From 44f537289dd9d8dfd41200eefac7a52e58f85674 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Mon, 4 Jul 2022 02:06:29 +0800 Subject: [PATCH] refactor(ui): rename classes to be consistent with new preference names --- .../java/com/osfans/trime/TrimeApplication.kt | 4 +- .../main/java/com/osfans/trime/core/Rime.java | 4 +- .../java/com/osfans/trime/data/AppPrefs.kt | 40 +++++++++---------- .../java/com/osfans/trime/data/Config.java | 4 +- .../java/com/osfans/trime/data/DataManager.kt | 10 ++--- .../java/com/osfans/trime/ime/core/Trime.java | 2 +- .../com/osfans/trime/ime/keyboard/Sound.java | 2 +- .../osfans/trime/ui/fragments/PrefFragment.kt | 4 +- ...LooksFragment.kt => ThemeColorFragment.kt} | 8 ++-- .../{ConfFragment.kt => UserDataFragment.kt} | 14 +++---- .../com/osfans/trime/util/AppVersionUtils.kt | 4 +- .../com/osfans/trime/util/ShortcutUtils.kt | 4 +- app/src/main/res/navigation/pref_nav.xml | 20 +++++----- ...ference.xml => theme_color_preference.xml} | 6 +-- ...reference.xml => user_data_preference.xml} | 10 ++--- 15 files changed, 68 insertions(+), 68 deletions(-) rename app/src/main/java/com/osfans/trime/ui/fragments/{LooksFragment.kt => ThemeColorFragment.kt} (77%) rename app/src/main/java/com/osfans/trime/ui/fragments/{ConfFragment.kt => UserDataFragment.kt} (86%) rename app/src/main/res/xml/{looks_preference.xml => theme_color_preference.xml} (84%) rename app/src/main/res/xml/{conf_preference.xml => user_data_preference.xml} (81%) diff --git a/app/src/main/java/com/osfans/trime/TrimeApplication.kt b/app/src/main/java/com/osfans/trime/TrimeApplication.kt index 07b5f4d49f..92fd271e38 100644 --- a/app/src/main/java/com/osfans/trime/TrimeApplication.kt +++ b/app/src/main/java/com/osfans/trime/TrimeApplication.kt @@ -41,11 +41,11 @@ class TrimeApplication : Application() { // record last pid for crash logs val appPrefs = AppPrefs.defaultInstance() val currentPid = Process.myPid() - appPrefs.general.pid.apply { + appPrefs.internal.pid.apply { lastPid = this Timber.d("Last pid is $lastPid. Set it to current pid: $currentPid") } - appPrefs.general.pid = currentPid + appPrefs.internal.pid = currentPid } catch (e: Exception) { e.fillInStackTrace() return diff --git a/app/src/main/java/com/osfans/trime/core/Rime.java b/app/src/main/java/com/osfans/trime/core/Rime.java index a6ea4511c9..96c185e2fa 100644 --- a/app/src/main/java/com/osfans/trime/core/Rime.java +++ b/app/src/main/java/com/osfans/trime/core/Rime.java @@ -342,8 +342,8 @@ private static void init(boolean full_check) { Timber.d(methodName); mOnMessage = false; final AppPrefs appPrefs = AppPrefs.defaultInstance(); - final String sharedDataDir = appPrefs.getConf().getSharedDataDir(); - final String userDataDir = appPrefs.getConf().getUserDataDir(); + final String sharedDataDir = appPrefs.getUserData().getSharedDataDir(); + final String userDataDir = appPrefs.getUserData().getUserDataDir(); Timber.d(methodName + "setup"); // Initialize librime APIs diff --git a/app/src/main/java/com/osfans/trime/data/AppPrefs.kt b/app/src/main/java/com/osfans/trime/data/AppPrefs.kt index 76ff3a2504..aa4933829c 100644 --- a/app/src/main/java/com/osfans/trime/data/AppPrefs.kt +++ b/app/src/main/java/com/osfans/trime/data/AppPrefs.kt @@ -28,10 +28,10 @@ class AppPrefs( private val cacheInt: HashMap = hashMapOf() private val cacheString: HashMap = hashMapOf() - val general = General(this) + val internal = Internal(this) val keyboard = Keyboard(this) - val looks = Looks(this) - val conf = Configuration(this) + val looks = ThemeColor(this) + val userData = UserData(this) val other = Other(this) /** @@ -131,8 +131,8 @@ class AppPrefs( try { applicationContext.get()?.let { context -> PreferenceManager.setDefaultValues(context, R.xml.keyboard_preference, true) - PreferenceManager.setDefaultValues(context, R.xml.looks_preference, true) - PreferenceManager.setDefaultValues(context, R.xml.conf_preference, true) + PreferenceManager.setDefaultValues(context, R.xml.theme_color_preference, true) + PreferenceManager.setDefaultValues(context, R.xml.user_data_preference, true) PreferenceManager.setDefaultValues(context, R.xml.other_preference, true) } } catch (e: Exception) { @@ -149,7 +149,7 @@ class AppPrefs( cacheString.clear() } - class General(private val prefs: AppPrefs) { + class Internal(private val prefs: AppPrefs) { companion object { const val LAST_VERSION_NAME = "general__last_version_name" const val PID = "general__pid" @@ -167,7 +167,7 @@ class AppPrefs( } /** - * Wrapper class of keyboard preferences. + * Wrapper class of keyboard settings. */ class Keyboard(private val prefs: AppPrefs) { companion object { @@ -326,14 +326,14 @@ class AppPrefs( } /** - * Wrapper class of keyboard appearance preferences. + * Wrapper class of theme and color settings. */ - class Looks(private val prefs: AppPrefs) { + class ThemeColor(private val prefs: AppPrefs) { companion object { - const val SELECTED_THEME = "looks__selected_theme" - const val SELECTED_COLOR = "looks__selected_color_scheme" - const val AUTO_DARK = "looks__auto_dark" - const val USE_MINI_KEYBOARD = "looks__use_mini_keyboard" + const val SELECTED_THEME = "theme_selected_theme" + const val SELECTED_COLOR = "theme_selected_color" + const val AUTO_DARK = "theme_auto_dark" + const val USE_MINI_KEYBOARD = "theme_use_mini_keyboard" } var selectedTheme: String get() = prefs.getPref(SELECTED_THEME, "trime") @@ -350,15 +350,15 @@ class AppPrefs( } /** - * Wrapper class of configuration settings. + * Wrapper class of user data settings. */ - class Configuration(private val prefs: AppPrefs) { + class UserData(private val prefs: AppPrefs) { companion object { - const val SHARED_DATA_DIR = "conf__shared_data_dir" - const val USER_DATA_DIR = "conf__user_data_dir" - const val SYNC_BACKGROUND_ENABLED = "conf__sync_background" - const val LAST_SYNC_STATUS = "conf__last_sync_status" - const val LAST_BACKGROUND_SYNC = "conf__last_background_sync" + const val SHARED_DATA_DIR = "data_shared_data_dir" + const val USER_DATA_DIR = "data_user_data_dir" + const val SYNC_BACKGROUND_ENABLED = "data_synchronize_background" + const val LAST_SYNC_STATUS = "data_last_sync_status" + const val LAST_BACKGROUND_SYNC = "data_last_background_sync" val EXTERNAL_PATH_PREFIX: String = appContext.getExternalFilesDir(null)!!.absolutePath } var sharedDataDir: String diff --git a/app/src/main/java/com/osfans/trime/data/Config.java b/app/src/main/java/com/osfans/trime/data/Config.java index d7bd112ec0..9a11b3b6a0 100644 --- a/app/src/main/java/com/osfans/trime/data/Config.java +++ b/app/src/main/java/com/osfans/trime/data/Config.java @@ -68,8 +68,8 @@ public class Config { private static final AppPrefs appPrefs = AppPrefs.defaultInstance(); - private static final String sharedDataDir = appPrefs.getConf().getSharedDataDir(); - private static final String userDataDir = appPrefs.getConf().getUserDataDir(); + private static final String sharedDataDir = appPrefs.getUserData().getSharedDataDir(); + private static final String userDataDir = appPrefs.getUserData().getUserDataDir(); public static synchronized Config get(Context context) { if (self == null) self = new Config(context); diff --git a/app/src/main/java/com/osfans/trime/data/DataManager.kt b/app/src/main/java/com/osfans/trime/data/DataManager.kt index dd43c26b86..8d7fa3d691 100644 --- a/app/src/main/java/com/osfans/trime/data/DataManager.kt +++ b/app/src/main/java/com/osfans/trime/data/DataManager.kt @@ -8,7 +8,7 @@ import java.io.File object DataManager { private val prefs get() = AppPrefs.defaultInstance() - val sharedDataDir = File(prefs.conf.sharedDataDir) + val sharedDataDir = File(prefs.userData.sharedDataDir) val customDefault = File(sharedDataDir, "default.custom.yaml") sealed class Diff { @@ -19,10 +19,10 @@ object DataManager { @JvmStatic fun getDataDir(child: String = ""): String { - return if (File(prefs.conf.sharedDataDir, child).exists()) { - File(prefs.conf.sharedDataDir, child).absolutePath + return if (File(prefs.userData.sharedDataDir, child).exists()) { + File(prefs.userData.sharedDataDir, child).absolutePath } else { - File(prefs.conf.userDataDir, child).absolutePath + File(prefs.userData.userDataDir, child).absolutePath } } @@ -37,7 +37,7 @@ object DataManager { @JvmStatic fun sync() { val newHash = Const.buildGitHash - val oldHash = prefs.general.lastBuildGitHash + val oldHash = prefs.internal.lastBuildGitHash diff(oldHash, newHash).run { Timber.d("Diff: $this") diff --git a/app/src/main/java/com/osfans/trime/ime/core/Trime.java b/app/src/main/java/com/osfans/trime/ime/core/Trime.java index a5ac0c3558..88c5ff9a73 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/Trime.java +++ b/app/src/main/java/com/osfans/trime/ime/core/Trime.java @@ -301,7 +301,7 @@ public void onWindowHidden() { } isWindowShown = false; - if (getPrefs().getConf().getSyncBackgroundEnabled()) { + if (getPrefs().getUserData().getSyncBackgroundEnabled()) { final Message msg = new Message(); msg.obj = this; syncBackgroundHandler.sendMessageDelayed(msg, 5000); // 输入面板隐藏5秒后,开始后台同步 diff --git a/app/src/main/java/com/osfans/trime/ime/keyboard/Sound.java b/app/src/main/java/com/osfans/trime/ime/keyboard/Sound.java index 50bc666d71..1438eeaa0d 100644 --- a/app/src/main/java/com/osfans/trime/ime/keyboard/Sound.java +++ b/app/src/main/java/com/osfans/trime/ime/keyboard/Sound.java @@ -57,7 +57,7 @@ public Sound(String soundPackageName) { Map m = ConfigGetter.loadMap(soundPackageName + ".sound", ""); if (m != null) { - String path = appPrefs.getConf().getUserDataDir() + File.separator + "sound" + File.separator; + String path = appPrefs.getUserData().getUserDataDir() + File.separator + "sound" + File.separator; if (m.containsKey("folder")) path = path + m.get("folder") + File.separator; if (m.containsKey("sound")) { diff --git a/app/src/main/java/com/osfans/trime/ui/fragments/PrefFragment.kt b/app/src/main/java/com/osfans/trime/ui/fragments/PrefFragment.kt index 4ff8e17e9b..473e1e7d92 100644 --- a/app/src/main/java/com/osfans/trime/ui/fragments/PrefFragment.kt +++ b/app/src/main/java/com/osfans/trime/ui/fragments/PrefFragment.kt @@ -33,7 +33,7 @@ class PrefFragment : PreferenceFragmentCompat() { true } get("pref_user_data")?.setOnPreferenceClickListener { - findNavController().navigate(R.id.action_prefFragment_to_confFragment) + findNavController().navigate(R.id.action_prefFragment_to_userDataFragment) true } get("pref_keyboard")?.setOnPreferenceClickListener { @@ -41,7 +41,7 @@ class PrefFragment : PreferenceFragmentCompat() { true } get("pref_theme_and_color")?.setOnPreferenceClickListener { - findNavController().navigate(R.id.action_prefFragment_to_looksFragment) + findNavController().navigate(R.id.action_prefFragment_to_themeColorFragment) true } get("pref_toolkit")?.setOnPreferenceClickListener { diff --git a/app/src/main/java/com/osfans/trime/ui/fragments/LooksFragment.kt b/app/src/main/java/com/osfans/trime/ui/fragments/ThemeColorFragment.kt similarity index 77% rename from app/src/main/java/com/osfans/trime/ui/fragments/LooksFragment.kt rename to app/src/main/java/com/osfans/trime/ui/fragments/ThemeColorFragment.kt index 07310930d5..4f1b2fc5fc 100644 --- a/app/src/main/java/com/osfans/trime/ui/fragments/LooksFragment.kt +++ b/app/src/main/java/com/osfans/trime/ui/fragments/ThemeColorFragment.kt @@ -10,17 +10,17 @@ import com.osfans.trime.ui.components.ColorPickerDialog import com.osfans.trime.ui.components.ThemePickerDialog import com.osfans.trime.ui.main.MainViewModel -class LooksFragment : PreferenceFragmentCompat() { +class ThemeColorFragment : PreferenceFragmentCompat() { private val viewModel: MainViewModel by activityViewModels() override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.looks_preference) + addPreferencesFromResource(R.xml.theme_color_preference) with(preferenceScreen) { - get("looks__selected_theme")?.setOnPreferenceClickListener { + get("theme_selected_theme")?.setOnPreferenceClickListener { ThemePickerDialog(context).show() true } - get("looks__selected_color")?.setOnPreferenceClickListener { + get("theme_selected_color")?.setOnPreferenceClickListener { ColorPickerDialog(context).show() true } diff --git a/app/src/main/java/com/osfans/trime/ui/fragments/ConfFragment.kt b/app/src/main/java/com/osfans/trime/ui/fragments/UserDataFragment.kt similarity index 86% rename from app/src/main/java/com/osfans/trime/ui/fragments/ConfFragment.kt rename to app/src/main/java/com/osfans/trime/ui/fragments/UserDataFragment.kt index 6581d36c49..151c64c91b 100644 --- a/app/src/main/java/com/osfans/trime/ui/fragments/ConfFragment.kt +++ b/app/src/main/java/com/osfans/trime/ui/fragments/UserDataFragment.kt @@ -21,15 +21,15 @@ import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch import timber.log.Timber -class ConfFragment : PreferenceFragmentCompat(), CoroutineScope by MainScope() { +class UserDataFragment : PreferenceFragmentCompat(), CoroutineScope by MainScope() { private val viewModel: MainViewModel by activityViewModels() private val prefs get() = AppPrefs.defaultInstance() override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.conf_preference) + addPreferencesFromResource(R.xml.user_data_preference) with(preferenceScreen) { - get("conf_synchronize")?.setOnPreferenceClickListener { + get("data_synchronize")?.setOnPreferenceClickListener { val progress = ProgressDialog(context) progress.setMessage(getString(R.string.sync_progress)) progress.setCancelable(false) @@ -44,11 +44,11 @@ class ConfFragment : PreferenceFragmentCompat(), CoroutineScope by MainScope() { } true } - get("conf__synchronize_background")?.setOnPreferenceClickListener { + get("data_synchronize_background")?.setOnPreferenceClickListener { setBackgroundSyncSummary(context) true } - get("conf__reset")?.setOnPreferenceClickListener { + get("data_reset")?.setOnPreferenceClickListener { ResetAssetsDialog(context).show() true } @@ -73,8 +73,8 @@ class ConfFragment : PreferenceFragmentCompat(), CoroutineScope by MainScope() { } else { var summary: String if (syncBgPref?.isChecked == true) { - val lastResult = prefs.conf.lastSyncStatus - val lastTime = prefs.conf.lastBackgroundSync + val lastResult = prefs.userData.lastSyncStatus + val lastTime = prefs.userData.lastBackgroundSync summary = if (lastResult) { context.getString(R.string.pref_sync_bg_success) } else { diff --git a/app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt b/app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt index 43b9086fe0..0202704ab3 100644 --- a/app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt +++ b/app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt @@ -14,9 +14,9 @@ object AppVersionUtils { */ fun isDifferentVersion(prefs: AppPrefs): Boolean { val currentVersionName = BuildConfig.VERSION_NAME - val lastVersionName = prefs.general.lastVersionName + val lastVersionName = prefs.internal.lastVersionName return !currentVersionName.contentEquals(lastVersionName).also { - prefs.general.lastVersionName = currentVersionName + prefs.internal.lastVersionName = currentVersionName } } diff --git a/app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt b/app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt index 156888bf5a..7849a69991 100644 --- a/app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt +++ b/app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt @@ -124,8 +124,8 @@ object ShortcutUtils { fun syncInBackground(context: Context) { val prefs = AppPrefs.defaultInstance() - prefs.conf.lastBackgroundSync = Date().time - prefs.conf.lastSyncStatus = Rime.syncUserData(context) + prefs.userData.lastBackgroundSync = Date().time + prefs.userData.lastSyncStatus = Rime.syncUserData(context) } fun openCategory(keyCode: Int): Boolean { diff --git a/app/src/main/res/navigation/pref_nav.xml b/app/src/main/res/navigation/pref_nav.xml index 6b4f88c77d..cdd06d334a 100644 --- a/app/src/main/res/navigation/pref_nav.xml +++ b/app/src/main/res/navigation/pref_nav.xml @@ -9,14 +9,14 @@ android:name="com.osfans.trime.ui.fragments.PrefFragment" android:label="PrefFragment" > + android:id="@+id/action_prefFragment_to_userDataFragment" + app:destination="@id/userDataFragment" /> + android:id="@+id/action_prefFragment_to_themeColorFragment" + app:destination="@id/themeColorFragment" /> @@ -28,17 +28,17 @@ app:destination="@id/aboutFragment" /> + android:id="@+id/userDataFragment" + android:name="com.osfans.trime.ui.fragments.UserDataFragment" + android:label="UserDataFragment" /> + android:id="@+id/themeColorFragment" + android:name="com.osfans.trime.ui.fragments.ThemeColorFragment" + android:label="ThemeColorFragment" /> - - - diff --git a/app/src/main/res/xml/conf_preference.xml b/app/src/main/res/xml/user_data_preference.xml similarity index 81% rename from app/src/main/res/xml/conf_preference.xml rename to app/src/main/res/xml/user_data_preference.xml index 4c3b734579..b7212243ba 100644 --- a/app/src/main/res/xml/conf_preference.xml +++ b/app/src/main/res/xml/user_data_preference.xml @@ -4,12 +4,12 @@ - - @@ -17,18 +17,18 @@ - - -