Skip to content

Commit

Permalink
chore: adjust preference trees
Browse files Browse the repository at this point in the history
- Move `Schemas`, `Appearance`(`Themes` and `Colors`) to top tree
- Refactor some preference items' titles
- Hide the options menu in sub settings page
  • Loading branch information
WhiredPlanck committed Jun 24, 2021
1 parent aeaea94 commit eec38f7
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.preference.PreferenceManager
import com.osfans.trime.Function
import com.osfans.trime.R
import com.osfans.trime.databinding.PrefActivityBinding
import com.osfans.trime.settings.components.SchemaPickerDialog
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.system.exitProcess
Expand Down Expand Up @@ -216,6 +217,10 @@ class PrefMainActivity: AppCompatActivity(),
(activity as PrefMainActivity).imeManager.showInputMethodPicker()
true
}
"pref_schemas" -> {
SchemaPickerDialog(requireContext()).show()
true
}
else -> super.onPreferenceTreeClick(preference)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.osfans.trime.settings.fragments

import android.os.Bundle
import android.view.Menu
import androidx.core.view.forEach
import androidx.core.view.forEachIndexed
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.osfans.trime.R
import com.osfans.trime.settings.components.ColorPickerDialog
import com.osfans.trime.settings.components.ThemePickerDialog

class AppearanceFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.appearance_preference)

setHasOptionsMenu(true)
}

override fun onPrepareOptionsMenu(menu: Menu) {
menu.forEach { item -> item.isVisible = false}
super.onPrepareOptionsMenu(menu)
}

override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) {
"pref_themes" -> {
ThemePickerDialog(requireContext()).show()
true
}
"pref_colors" -> {
ColorPickerDialog(requireContext()).show()
true
}
else -> super.onPreferenceTreeClick(preference)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.ProgressDialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.Menu
import androidx.core.view.forEach
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
Expand All @@ -30,14 +32,17 @@ class InputFragment: PreferenceFragmentCompat(), CoroutineScope {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.input_preference)

setHasOptionsMenu(true)
}

override fun onPrepareOptionsMenu(menu: Menu) {
menu.forEach { item -> item.isVisible = false}
super.onPrepareOptionsMenu(menu)
}

override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) {
"pref_schemas" -> {
SchemaPickerDialog(requireContext()).show()
true
}
"pref_sync" -> {
@Suppress("DEPRECATION")
val progressDialog = ProgressDialog(context).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.osfans.trime.settings.fragments

import android.content.SharedPreferences
import android.os.Bundle
import android.view.Menu
import androidx.core.view.forEach
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.osfans.trime.R
Expand All @@ -14,20 +16,13 @@ class KeyboardFragment: PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.keyboard_preference)

setHasOptionsMenu(true)
}

override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) {
"pref_themes" -> {
ThemePickerDialog(requireContext()).show()
true
}
"pref_colors" -> {
ColorPickerDialog(requireContext()).show()
true
}
else -> super.onPreferenceTreeClick(preference)
}
override fun onPrepareOptionsMenu(menu: Menu) {
menu.forEach { item -> item.isVisible = false}
super.onPrepareOptionsMenu(menu)
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.osfans.trime.settings.fragments
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.Menu
import androidx.core.view.forEach
import androidx.preference.PreferenceFragmentCompat
import com.osfans.trime.Pref
import com.osfans.trime.R
Expand All @@ -13,6 +15,13 @@ class OtherFragment: PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.other_preference)

setHasOptionsMenu(true)
}

override fun onPrepareOptionsMenu(menu: Menu) {
menu.forEach { item -> item.isVisible = false}
super.onPrepareOptionsMenu(menu)
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<string name="pref_credits">鸣谢</string>
<string name="pref_pime">微软平台PRIME输入法</string>
<string name="pref_privacy">隐私策略</string>
<string name="pref_input">输入</string>
<string name="pref_input">输入配置</string>
<string name="pref_enable">启用</string>
<string name="pref_enable_summary">启用同文输入法</string>
<string name="pref_select">选取软键盘</string>
Expand All @@ -52,7 +52,7 @@
<string name="pref_colors_summary">选取键盘配色</string>
<string name="pref_reset">恢复默认设置</string>
<string name="pref_reset_summary">使用默认设置覆盖共享文件夹下同名文件</string>
<string name="pref_keyboard">键盘</string>
<string name="pref_keyboard">偏好设置</string>
<string name="key_sound">按键声音</string>
<string name="key_sound_volume">按键音量</string>
<string name="key_vibrate">按键时振动</string>
Expand Down Expand Up @@ -108,9 +108,9 @@
<string name="pref_help__general_channel">常规渠道</string>
<string name="pref_help__marketplace">应用市场</string>
<string name="pref_help__user_community">用户社区</string>
<string name="pref_keyboard__appearance">外观</string>
<string name="pref_keyboard__function">功能</string>
<string name="pref_keyboard__effect">效果</string>
<string name="pref_keyboard__effect">按键效果</string>
<string name="pref__draw_overlays_tip_title">显示在其他应用上方</string>
<string name="pref__draw_overlays_tip_message">要正确显示候选栏,或从键盘开启各项菜单,您需要授予同文输入法“显示在其他应用上方”的权限。点击“确定”前往设置页,或“取消”以稍后手动设置。</string>
<string name="pref_keyboard_appearance">键盘外观</string>
<string name="pref_keyboard__function">视图</string>
</resources>
10 changes: 5 additions & 5 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<string name="pref_credits">鳴謝</string>
<string name="pref_pime">Win10 PRIME輸入法平臺</string>
<string name="pref_privacy">隱私權政策</string>
<string name="pref_input">輸入</string>
<string name="pref_input">輸入配置</string>
<string name="pref_enable">啓用</string>
<string name="pref_enable_summary">啓用同文輸入法平臺</string>
<string name="pref_select">選取軟鍵盤</string>
Expand All @@ -53,7 +53,7 @@
<string name="pref_colors_summary">選取想要的鍵盤配色</string>
<string name="pref_reset">回廠</string>
<string name="pref_reset_summary">使用預設設定覆蓋共享資料夾下同名檔案</string>
<string name="pref_keyboard">鍵盤</string>
<string name="pref_keyboard">偏好設定</string>
<string name="key_sound">按鍵聲音</string>
<string name="key_sound_volume">按鍵音量</string>
<string name="key_vibrate">按鍵時振動</string>
Expand Down Expand Up @@ -109,9 +109,9 @@
<string name="pref_help__general_channel">常規渠道</string>
<string name="pref_help__marketplace">應用市場</string>
<string name="pref_help__user_community">使用者社群</string>
<string name="pref_keyboard__appearance">外觀</string>
<string name="pref_keyboard__function">功能</string>
<string name="pref_keyboard__effect">效果</string>
<string name="pref_keyboard__function">檢視</string>
<string name="pref_keyboard__effect">按键效果</string>
<string name="pref__draw_overlays_tip_title">顯示在其他應用上方</string>
<string name="pref__draw_overlays_tip_message">要正確顯示候選欄,或從鍵盤開啟各項選單,您需要授予同文輸入法“顯示在其他應用上方”的許可權。點選“確定”前往設定頁,或“取消”以稍後手動設定。</string>
<string name="pref_keyboard_appearance">鍵盤外觀</string>
</resources>
10 changes: 5 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<string name="pref_credits">Credits</string>
<string name="pref_pime">Win10 PRIME Platform</string>
<string name="pref_privacy">Privacy Policy</string>
<string name="pref_input">Input</string>
<string name="pref_input">Input Setup</string>
<string name="pref_enable">Enable</string>
<string name="pref_enable_summary">Enable TRIME</string>
<string name="pref_select">Change Keyboard</string>
Expand All @@ -55,7 +55,7 @@
<string name="pref_colors_summary">Select Desired Color for Keyboard</string>
<string name="pref_reset">Reset</string>
<string name="pref_reset_summary">Use Default Settings to Replace the contents in shared directory</string>
<string name="pref_keyboard">Keyboard</string>
<string name="pref_keyboard">Preferences</string>
<string name="key_sound">Sound on keypress</string>
<string name="key_sound_volume">Volume on keypress</string>
<string name="key_vibrate">Vibrate on keypress</string>
Expand Down Expand Up @@ -109,9 +109,9 @@
<string name="pref_help__general_channel">General Channel</string>
<string name="pref_help__marketplace">Marketplace</string>
<string name="pref_help__user_community">User Community</string>
<string name="pref_keyboard__appearance">Appearance</string>
<string name="pref_keyboard__function">Function</string>
<string name="pref_keyboard__effect">Effect</string>
<string name="pref_keyboard__function">View</string>
<string name="pref_keyboard__effect">Keypress Effect</string>
<string name="pref__draw_overlays_tip_title">Display Over Other Apps</string>
<string name="pref__draw_overlays_tip_message">To display the candidate bar properly, or to open menus from the keyboard, you need to grant Trime permission to \"Display over other apps\". Click OK to go to the settings page, or cancel to set it manually later.</string>
<string name="pref_keyboard_appearance">Appearance</string>
</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/xml/appearance_preference.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference android:key="pref_themes"
app:iconSpaceReserved="false"
android:title="@string/pref_themes"
android:summary="@string/pref_themes_summary" />
<Preference android:key="pref_colors"
app:iconSpaceReserved="false"
android:title="@string/pref_colors"
android:summary="@string/pref_colors_summary" />
</PreferenceScreen>
5 changes: 0 additions & 5 deletions app/src/main/res/xml/input_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
android:defaultValue="@string/default_user_data_dir"
app:useSimpleSummaryProvider="true"/>

<Preference android:key="pref_schemas"
app:iconSpaceReserved="false"
android:title="@string/pref_schemas"
android:summary="@string/pref_schemas_summary"/>

<Preference android:key="pref_sync"
app:iconSpaceReserved="false"
android:title="@string/pref_sync"
Expand Down
15 changes: 2 additions & 13 deletions app/src/main/res/xml/keyboard_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="pref_keyboard"
android:title="@string/pref_keyboard">
<PreferenceCategory app:iconSpaceReserved="false"
app:title="@string/pref_keyboard__appearance"
app:key="pref_keyboard__appearance" >
<Preference android:key="pref_themes"
app:iconSpaceReserved="false"
android:title="@string/pref_themes"
android:summary="@string/pref_themes_summary" />
<Preference android:key="pref_colors"
app:iconSpaceReserved="false"
android:title="@string/pref_colors"
android:summary="@string/pref_colors_summary" />
</PreferenceCategory>

<PreferenceCategory app:iconSpaceReserved="false"
app:title="@string/pref_keyboard__function"
Expand All @@ -24,7 +12,8 @@
android:title="@string/inline_preedit"
android:entries="@array/inline_entries"
android:entryValues="@array/inline_values"
android:defaultValue="preview"/>
android:defaultValue="preview"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference android:key="soft_cursor"
app:iconSpaceReserved="false"
android:title="@string/soft_cursor"
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/ime_name">

<!-- <SwitchPreference android:key="pref_ui"
Expand All @@ -38,11 +39,21 @@
android:title="@string/pref_select"
android:summary="@string/pref_select_summary"/>

<Preference android:key="pref_keyboard"
<Preference android:key="pref_schemas"
android:order="4"
android:title="@string/pref_schemas"
android:summary="@string/pref_schemas_summary"/>

<Preference android:key="pref_keyboard"
android:order="5"
android:title="@string/pref_keyboard"
android:fragment="com.osfans.trime.settings.fragments.KeyboardFragment"/>

<Preference android:key="pref_keyboard_appearance"
android:order="6"
android:title="@string/pref_keyboard_appearance"
android:fragment="com.osfans.trime.settings.fragments.AppearanceFragment"/>

<Preference android:key="pref_input"
android:order="8"
android:title="@string/pref_input"
Expand Down

0 comments on commit eec38f7

Please sign in to comment.