Skip to content

Commit

Permalink
refactor: improve user experience of settings pages
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Dec 13, 2024
1 parent 3e3abdd commit 176608b
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class AboutFragment : PaddingPreferenceFragment() {
}
}

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_about))
}

companion object {
private val DASH_G_PATTERN = Regex("^(.*-g)([0-9a-f]+)(.*)$")
private val COMMON_PATTERN = Regex("^([^-]*)(-.*)$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ClipboardFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.clipboard))
viewModel.disableTopOptionsMenu()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class KeyboardFragment :

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_keyboard))
viewModel.disableTopOptionsMenu()
preferenceScreen.sharedPreferences?.registerOnSharedPreferenceChangeListener(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class LicenseFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.about__license))
viewModel.disableTopOptionsMenu()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class OtherFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_other))
viewModel.disableTopOptionsMenu()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class PrefFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.trime_app_name))
viewModel.enableTopOptionsMenu()
}

Expand Down Expand Up @@ -70,7 +69,7 @@ class PrefFragment : PaddingPreferenceFragment() {
true
}
get<Preference>("pref_theme_and_color")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_themeColorFragment)
findNavController().navigate(R.id.action_prefFragment_to_themeFragment)
true
}
get<Preference>("pref_clipboard")?.setOnPreferenceClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class ProfileFragment :

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_profile))
viewModel.disableTopOptionsMenu()
preferenceScreen.sharedPreferences?.registerOnSharedPreferenceChangeListener(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.osfans.trime.ui.main.settings.ColorPickerDialog
import com.osfans.trime.ui.main.settings.ThemePickerDialog
import kotlinx.coroutines.launch

class ThemeColorFragment : PaddingPreferenceFragment() {
class ThemeFragment : PaddingPreferenceFragment() {
private val viewModel: MainViewModel by activityViewModels()

override fun onCreatePreferences(
Expand All @@ -38,7 +38,6 @@ class ThemeColorFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_theme_and_color))
viewModel.disableTopOptionsMenu()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ToolkitFragment : PaddingPreferenceFragment() {

override fun onResume() {
super.onResume()
viewModel.setToolbarTitle(getString(R.string.pref_toolkit))
viewModel.disableTopOptionsMenu()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class PrefMainActivity : AppCompatActivity() {
}
navHostFragment.navController.addOnDestinationChangedListener { _, dest, _ ->
dest.label?.let { viewModel.setToolbarTitle(it.toString()) }
binding.prefToolbar.toolbar.subtitle =
if (dest.id == R.id.prefFragment) {
getString(R.string.trime_app_slogan)
} else {
""
}
}

supportActionBar?.setDisplayHomeAsUpEnabled(true)
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/res/navigation/pref_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<fragment
android:id="@+id/prefFragment"
android:name="com.osfans.trime.ui.fragments.PrefFragment"
android:label="PrefFragment" >
android:label="@string/trime_app_name" >
<action
android:id="@+id/action_prefFragment_to_profileFragment"
app:destination="@id/profileFragment"
Expand All @@ -30,8 +30,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_prefFragment_to_themeColorFragment"
app:destination="@id/themeColorFragment"
android:id="@+id/action_prefFragment_to_themeFragment"
app:destination="@id/themeFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
Expand Down Expand Up @@ -70,27 +70,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
<fragment
android:id="@+id/profileFragment"
android:name="com.osfans.trime.ui.fragments.ProfileFragment"
android:label="ProfileFragment" />
android:label="@string/profile" />
<fragment
android:id="@+id/keyboardFragment"
android:name="com.osfans.trime.ui.fragments.KeyboardFragment"
android:label="KeyboardFragment" />
android:label="@string/keyboard" />
<fragment
android:id="@+id/themeColorFragment"
android:name="com.osfans.trime.ui.fragments.ThemeColorFragment"
android:label="ThemeColorFragment" />
android:id="@+id/themeFragment"
android:name="com.osfans.trime.ui.fragments.ThemeFragment"
android:label="@string/theme" />
<fragment
android:id="@+id/otherFragment"
android:name="com.osfans.trime.ui.fragments.OtherFragment"
android:label="OtherFragment" />
android:label="@string/others" />
<fragment
android:id="@+id/toolkitFragment"
android:name="com.osfans.trime.ui.fragments.ToolkitFragment"
android:label="ToolkitFragment" />
android:label="@string/toolkit" />
<fragment
android:id="@+id/aboutFragment"
android:name="com.osfans.trime.ui.fragments.AboutFragment"
android:label="AboutFragment" >
android:label="@string/about" >
<action
android:id="@+id/action_aboutFragment_to_licenseFragment"
app:destination="@id/licenseFragment"
Expand All @@ -102,11 +102,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
<fragment
android:id="@+id/licenseFragment"
android:name="com.osfans.trime.ui.fragments.LicenseFragment"
android:label="LicenseFragment" />
android:label="@string/license" />
<fragment
android:id="@+id/clipboardFragment"
android:name="com.osfans.trime.ui.fragments.ClipboardFragment"
android:label="ClipboardFragment" />
android:label="@string/clipboard" />
<fragment
android:id="@+id/candidatesSettingsFragment"
android:name="com.osfans.trime.ui.main.settings.CandidatesSettingsFragment"
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="about__librime_version">RIME版本</string>
<string name="about__opencc_version">OpenCC版本</string>
<string name="about__changelog">更新日志</string>
<string name="about__license">许可证</string>
<string name="license">许可证</string>
<string name="pref_credits">贡献代码</string>
<string name="about__product_prime">微软平台PRIME输入法</string>
<string name="about__privacy_policy">隐私策略</string>
Expand Down Expand Up @@ -64,7 +64,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="set_ime">设置</string>
<string name="other_ime">其他输入法</string>
<string name="other__ui_mode_title">夜间模式</string>
<string name="pref_other">其他设置</string>
<string name="others">其他</string>
<string name="other__show_status_bar_icon_title">显示通知栏图标</string>
<string name="other__destroy_on_quit_title">退出时清除缓存</string>
<string name="profile_user_data_dir">用户文件夹</string>
Expand Down Expand Up @@ -146,7 +146,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="keyboard__hook_shift_space">点击空格时,忽略Shift的锁定状态</string>
<string name="keyboard__hook_shift_num">点击0-9时,忽略Shift的锁定状态</string>
<string name="keyboard__hook_shift_symbol">点击符号键时,忽略Shift的锁定状态</string>
<string name="pref_toolkit">工具箱</string>
<string name="toolkit">工具箱</string>
<string name="export">导出</string>
<string name="scroll_to_bottom">跳到最后</string>
<string name="clear">清除画面</string>
Expand All @@ -157,17 +157,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="app_crash">应用程序崩溃了</string>
<string name="exception_logcat_created">Logcat 进程已创建</string>
<string name="app_crash_message">抱歉,但我们提供了日志以供调查。</string>
<string name="pref_keyboard">键盘设置</string>
<string name="pref_about">关于</string>
<string name="pref_theme_and_color">主题与配色</string>
<string name="pref_profile">配置管理</string>
<string name="keyboard">键盘</string>
<string name="about">关于</string>
<string name="theme">主题</string>
<string name="profile">配置</string>
<string name="storage">存储</string>
<string name="maintenance">维护</string>
<string name="loading">正在加载</string>
<string name="profile_reset">恢复默认设置</string>
<string name="success">成功</string>
<string name="failure">失败</string>
<string name="pref_profile_summary">设定存储位置和修改同步设置等</string>
<string name="profile_summary">设定存储位置和修改同步设置等</string>
<string name="profile_reset_summary">用默认的内置配置覆盖共享目录中的相同文件</string>
<string name="profile_sync_user_data_summary">备份配置文件和同步用户词典</string>
<string name="delete">删除</string>
Expand Down Expand Up @@ -226,7 +226,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="forget_this_word">忘记该词</string>
<string name="synchronization">同步</string>
<string name="profile_timing_background_sync_set_time">设置后台同步时间</string>
<string name="candidates_window">候选词窗口</string>
<string name="candidates_window">候选窗口</string>
<string name="candidates_mode">候选词显示模式</string>
<string name="general">常规</string>
<string name="preedit">预编辑码</string>
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="about__librime_version">RIME版本</string>
<string name="about__opencc_version">OpenCC版本</string>
<string name="about__changelog">更新日誌</string>
<string name="about__license">許可證</string>
<string name="license">許可證</string>
<string name="pref_credits">貢獻代碼</string>
<string name="about__product_prime">Win10 PRIME輸入法平臺</string>
<string name="about__privacy_policy">隱私權政策</string>
Expand Down Expand Up @@ -68,7 +68,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="set_ime">設定</string>
<string name="other_ime">其他輸入法</string>
<string name="other__ui_mode_title">夜間模式</string>
<string name="pref_other">其他設置</string>
<string name="others">其他</string>
<string name="other__show_status_bar_icon_title">顯示通知欄圖標</string>
<string name="other__destroy_on_quit_title">離開時清理記憶體</string>
<string name="profile_user_data_dir">使用者資料夾</string>
Expand Down Expand Up @@ -158,13 +158,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="real_time_logs_clear">清除所有紀錄檔</string>
<string name="real_time_logs_confirm">要清除有紀錄檔嗎?(此動作不能復原)</string>
<string name="clear">清除畫面</string>
<string name="pref_toolkit">工具箱</string>
<string name="toolkit">工具箱</string>
<string name="exception_logcat_created">Logcat 行程已建立</string>
<string name="pref_about">關於</string>
<string name="pref_theme_and_color">主題與配色</string>
<string name="pref_profile">配置管理</string>
<string name="pref_profile_summary">設定儲存位置和修改同步設定等</string>
<string name="pref_keyboard">鍵盤設定</string>
<string name="about">關於</string>
<string name="theme">主題</string>
<string name="profile">配置</string>
<string name="profile_summary">設定儲存位置和修改同步設定等</string>
<string name="keyboard">鍵盤</string>
<string name="storage">儲存</string>
<string name="maintenance">維護</string>
<string name="loading">正在載入</string>
Expand Down Expand Up @@ -226,7 +226,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="forget_this_word">忘記該詞</string>
<string name="synchronization">同步</string>
<string name="profile_timing_background_sync_set_time">設定後台同步時間</string>
<string name="candidates_window">候选词窗口</string>
<string name="candidates_window">候选窗口</string>
<string name="candidates_mode">候選詞顯示模式</string>
<string name="general">常規</string>
<string name="preedit">預編輯碼</string>
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="about__librime_version">Rime Version</string>
<string name="about__opencc_version">OpenCC Version</string>
<string name="about__changelog">Change Log</string>
<string name="about__license">License</string>
<string name="license">License</string>
<string name="pref_credits">Contribute</string>
<string name="about__product_prime">Win10 PRIME Platform</string>
<string name="about__privacy_policy">Privacy Policy</string>
Expand Down Expand Up @@ -68,7 +68,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="set_ime">Preferences</string>
<string name="other_ime">Other IMEs</string>
<string name="other__ui_mode_title">Night Mode</string>
<string name="pref_other">Others</string>
<string name="others">Others</string>
<string name="other__show_status_bar_icon_title">Show icon in notification bar</string>
<string name="other__destroy_on_quit_title">Free memory on quit</string>
<string name="profile_user_data_dir">User directory</string>
Expand Down Expand Up @@ -111,7 +111,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="system_default">System default</string>
<string name="keyboard__key_swipe_travel_title">Min travel for gesture</string>
<string name="keyboard__hook_candidate">Click candidate</string>c
<string name="trime_app_slogan">Trimes with Your Keystrokes</string>
<string name="trime_app_slogan">Rimes with Your Keystrokes on Android</string>
<string name="external_storage_permission_not_available">External storage permission is not available</string>
<string name="external_storage_permission_granted">External storage permission is granted</string>
<string name="external_storage_permission_denied">External storage permission was denied, deployment or reading schemas and config may not be available</string>
Expand Down Expand Up @@ -161,17 +161,17 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="clear">Clear Screen</string>
<string name="export">Export</string>
<string name="scroll_to_bottom">Jump to Bottom</string>
<string name="pref_toolkit">Toolkit</string>
<string name="pref_profile">Profile</string>
<string name="pref_keyboard">Keyboard settings</string>
<string name="pref_theme_and_color"><![CDATA[Theme & Color]]></string>
<string name="pref_about">About</string>
<string name="toolkit">Toolkit</string>
<string name="profile">Profile</string>
<string name="keyboard">Keyboard</string>
<string name="theme">Theme</string>
<string name="about">About</string>
<string name="storage">Storage</string>
<string name="maintenance">Maintenance</string>
<string name="loading">Loading</string>
<string name="success">success</string>
<string name="failure">failure</string>
<string name="pref_profile_summary">Define storage locations and change sync settings, etc.</string>
<string name="profile_summary">Define storage locations and change sync settings, etc.</string>
<string name="delete">Delete</string>
<string name="edit">Edit</string>
<string name="collect">Collect</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/about_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:iconSpaceReserved="false">

<Preference app:key="about__license"
app:title="@string/about__license"
app:title="@string/license"
app:summary="GPL-3.0-or-later"
app:iconSpaceReserved="false">
<intent android:action="android.intent.action.VIEW"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/keyboard_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="pref_keyboard"
android:title="@string/pref_keyboard">
android:title="@string/keyboard">

<PreferenceCategory
app:iconSpaceReserved="false"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ SPDX-License-Identifier: GPL-3.0-or-later
android:summary="@string/schemata_hint"/>

<Preference android:key="pref_user_data"
android:title="@string/pref_profile"
android:title="@string/profile"
app:icon="@drawable/ic_baseline_snippet_folder_24"
android:summary="@string/pref_profile_summary"/>
android:summary="@string/profile_summary"/>

<Preference android:key="pref_general"
android:title="@string/general"
app:icon="@drawable/ic_baseline_tune_24" />

<Preference android:key="pref_keyboard"
android:title="@string/pref_keyboard"
android:title="@string/keyboard"
app:icon="@drawable/ic_baseline_keyboard_24" />

<Preference android:key="pref_candidates"
android:title="@string/candidates_window"
app:icon="@drawable/ic_baseline_list_alt_24" />

<Preference android:key="pref_theme_and_color"
android:title="@string/pref_theme_and_color"
android:title="@string/theme"
app:icon="@drawable/ic_pref_theme_color" />

<Preference android:key="pref_clipboard"
Expand All @@ -42,11 +42,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:icon="@drawable/ic_baseline_assignment_24"/>

<Preference android:key="pref_toolkit"
android:title="@string/pref_toolkit"
android:title="@string/toolkit"
app:icon="@drawable/ic_iconpark_toolkit_24" />

<Preference android:key="pref_others"
android:title="@string/pref_other"
android:title="@string/others"
app:icon="@drawable/ic_pref_other" />

</PreferenceScreen>

0 comments on commit 176608b

Please sign in to comment.