Skip to content

Commit

Permalink
refactor(ui): rename classes to be consistent with new preference names
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Aug 6, 2022
1 parent be95e64 commit 44f5372
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/TrimeApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/core/Rime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 20 additions & 20 deletions app/src/main/java/com/osfans/trime/data/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class AppPrefs(
private val cacheInt: HashMap<String, Int> = hashMapOf()
private val cacheString: HashMap<String, String> = 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)

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
Expand All @@ -167,7 +167,7 @@ class AppPrefs(
}

/**
* Wrapper class of keyboard preferences.
* Wrapper class of keyboard settings.
*/
class Keyboard(private val prefs: AppPrefs) {
companion object {
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/data/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/osfans/trime/data/DataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}

Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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秒后,开始后台同步
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/keyboard/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Sound(String soundPackageName) {

Map<String, ?> 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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class PrefFragment : PreferenceFragmentCompat() {
true
}
get<Preference>("pref_user_data")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_confFragment)
findNavController().navigate(R.id.action_prefFragment_to_userDataFragment)
true
}
get<Preference>("pref_keyboard")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_keyboardFragment)
true
}
get<Preference>("pref_theme_and_color")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_looksFragment)
findNavController().navigate(R.id.action_prefFragment_to_themeColorFragment)
true
}
get<Preference>("pref_toolkit")?.setOnPreferenceClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Preference>("looks__selected_theme")?.setOnPreferenceClickListener {
get<Preference>("theme_selected_theme")?.setOnPreferenceClickListener {
ThemePickerDialog(context).show()
true
}
get<Preference>("looks__selected_color")?.setOnPreferenceClickListener {
get<Preference>("theme_selected_color")?.setOnPreferenceClickListener {
ColorPickerDialog(context).show()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Preference>("conf_synchronize")?.setOnPreferenceClickListener {
get<Preference>("data_synchronize")?.setOnPreferenceClickListener {
val progress = ProgressDialog(context)
progress.setMessage(getString(R.string.sync_progress))
progress.setCancelable(false)
Expand All @@ -44,11 +44,11 @@ class ConfFragment : PreferenceFragmentCompat(), CoroutineScope by MainScope() {
}
true
}
get<Preference>("conf__synchronize_background")?.setOnPreferenceClickListener {
get<Preference>("data_synchronize_background")?.setOnPreferenceClickListener {
setBackgroundSyncSummary(context)
true
}
get<Preference>("conf__reset")?.setOnPreferenceClickListener {
get<Preference>("data_reset")?.setOnPreferenceClickListener {
ResetAssetsDialog(context).show()
true
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/util/AppVersionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/res/navigation/pref_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
android:name="com.osfans.trime.ui.fragments.PrefFragment"
android:label="PrefFragment" >
<action
android:id="@+id/action_prefFragment_to_confFragment"
app:destination="@id/confFragment" />
android:id="@+id/action_prefFragment_to_userDataFragment"
app:destination="@id/userDataFragment" />
<action
android:id="@+id/action_prefFragment_to_keyboardFragment"
app:destination="@id/keyboardFragment" />
<action
android:id="@+id/action_prefFragment_to_looksFragment"
app:destination="@id/looksFragment" />
android:id="@+id/action_prefFragment_to_themeColorFragment"
app:destination="@id/themeColorFragment" />
<action
android:id="@+id/action_prefFragment_to_otherFragment"
app:destination="@id/otherFragment" />
Expand All @@ -28,17 +28,17 @@
app:destination="@id/aboutFragment" />
</fragment>
<fragment
android:id="@+id/confFragment"
android:name="com.osfans.trime.ui.fragments.ConfFragment"
android:label="ConfFragment" />
android:id="@+id/userDataFragment"
android:name="com.osfans.trime.ui.fragments.UserDataFragment"
android:label="UserDataFragment" />
<fragment
android:id="@+id/keyboardFragment"
android:name="com.osfans.trime.ui.fragments.KeyboardFragment"
android:label="KeyboardFragment" />
<fragment
android:id="@+id/looksFragment"
android:name="com.osfans.trime.ui.fragments.LooksFragment"
android:label="LooksFragment" />
android:id="@+id/themeColorFragment"
android:name="com.osfans.trime.ui.fragments.ThemeColorFragment"
android:label="ThemeColorFragment" />
<fragment
android:id="@+id/otherFragment"
android:name="com.osfans.trime.ui.fragments.OtherFragment"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?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="looks__selected_theme"
<Preference android:key="theme_selected_theme"
app:iconSpaceReserved="false"
android:title="@string/looks__selected_theme_title"
android:summary="@string/looks__selected_theme_summary" />
<Preference android:key="looks__selected_color"
<Preference android:key="theme_selected_color"
app:iconSpaceReserved="false"
android:title="@string/looks__selected_color_title"
android:summary="@string/looks__selected_color_summary" />
<SwitchPreferenceCompat android:key="looks__auto_dark"
<SwitchPreferenceCompat android:key="theme_auto_dark"
app:iconSpaceReserved="false"
android:title="@string/keyboard__auto_dark_title"
android:defaultValue="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

<PreferenceCategory android:title="@string/storage"
app:iconSpaceReserved="false" >
<EditTextPreference android:key="conf__shared_data_dir"
<EditTextPreference android:key="data_shared_data_dir"
app:iconSpaceReserved="false"
android:title="@string/conf__shared_data_dir_title"
app:useSimpleSummaryProvider="true"/>

<EditTextPreference android:key="conf__user_data_dir"
<EditTextPreference android:key="data_user_data_dir"
app:iconSpaceReserved="false"
android:title="@string/conf__user_data_dir_title"
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>

<PreferenceCategory android:title="@string/maintenance"
app:iconSpaceReserved="false" >
<Preference android:key="conf__synchronize"
<Preference android:key="data_synchronize"
app:iconSpaceReserved="false"
android:title="@string/conf__synchronize_title"
android:summary="@string/conf__synchronize_summary"/>

<SwitchPreferenceCompat android:key="conf__synchronize_background"
<SwitchPreferenceCompat android:key="data_synchronize_background"
app:iconSpaceReserved="false"
android:title="@string/conf__synchronize_background_title"
android:summary="@string/conf__synchronize_background_summary"
android:persistent="true" />

<Preference android:key="conf__reset"
<Preference android:key="data_reset"
app:iconSpaceReserved="false"
android:title="@string/conf__reset_title"
android:summary="@string/conf__reset_summary"/>
Expand Down

0 comments on commit 44f5372

Please sign in to comment.