mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-16 23:12:12 +00:00
fix: make app language key global, not profile-scoped
The language preference was stored with a profile-scoped key
(selected_app_language_{profileId}), causing it to reset to English
on app restart when the active profile was not profile 1.
During startup, initialize() reads the key with default
activeProfileId=1 before the correct profile is loaded, resulting
in a cache miss and fallback to English.
App language is a device-level preference, not per-profile, so
the key should not be scoped. This also fixes replaceFromSyncPayload
to correctly clear both profile-scoped and global keys.
This commit is contained in:
parent
7ef0083a71
commit
e15a398f3e
2 changed files with 14 additions and 8 deletions
|
|
@ -18,7 +18,8 @@ actual object ThemeSettingsStorage {
|
||||||
private const val selectedThemeKey = "selected_theme"
|
private const val selectedThemeKey = "selected_theme"
|
||||||
private const val amoledEnabledKey = "amoled_enabled"
|
private const val amoledEnabledKey = "amoled_enabled"
|
||||||
private const val selectedAppLanguageKey = "selected_app_language"
|
private const val selectedAppLanguageKey = "selected_app_language"
|
||||||
private val syncKeys = listOf(selectedThemeKey, amoledEnabledKey, selectedAppLanguageKey)
|
private val profileScopedSyncKeys = listOf(selectedThemeKey, amoledEnabledKey)
|
||||||
|
private val globalSyncKeys = listOf(selectedAppLanguageKey)
|
||||||
|
|
||||||
private var preferences: SharedPreferences? = null
|
private var preferences: SharedPreferences? = null
|
||||||
|
|
||||||
|
|
@ -51,12 +52,12 @@ actual object ThemeSettingsStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun loadSelectedAppLanguage(): String? =
|
actual fun loadSelectedAppLanguage(): String? =
|
||||||
preferences?.getString(ProfileScopedKey.of(selectedAppLanguageKey), null)
|
preferences?.getString(selectedAppLanguageKey, null)
|
||||||
|
|
||||||
actual fun saveSelectedAppLanguage(languageCode: String) {
|
actual fun saveSelectedAppLanguage(languageCode: String) {
|
||||||
preferences
|
preferences
|
||||||
?.edit()
|
?.edit()
|
||||||
?.putString(ProfileScopedKey.of(selectedAppLanguageKey), languageCode)
|
?.putString(selectedAppLanguageKey, languageCode)
|
||||||
?.apply()
|
?.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +75,8 @@ actual object ThemeSettingsStorage {
|
||||||
|
|
||||||
actual fun replaceFromSyncPayload(payload: JsonObject) {
|
actual fun replaceFromSyncPayload(payload: JsonObject) {
|
||||||
preferences?.edit()?.apply {
|
preferences?.edit()?.apply {
|
||||||
syncKeys.forEach { remove(ProfileScopedKey.of(it)) }
|
profileScopedSyncKeys.forEach { remove(ProfileScopedKey.of(it)) }
|
||||||
|
globalSyncKeys.forEach { remove(it) }
|
||||||
}?.apply()
|
}?.apply()
|
||||||
|
|
||||||
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)
|
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ actual object ThemeSettingsStorage {
|
||||||
private const val selectedThemeKey = "selected_theme"
|
private const val selectedThemeKey = "selected_theme"
|
||||||
private const val amoledEnabledKey = "amoled_enabled"
|
private const val amoledEnabledKey = "amoled_enabled"
|
||||||
private const val selectedAppLanguageKey = "selected_app_language"
|
private const val selectedAppLanguageKey = "selected_app_language"
|
||||||
private val syncKeys = listOf(selectedThemeKey, amoledEnabledKey, selectedAppLanguageKey)
|
private val profileScopedSyncKeys = listOf(selectedThemeKey, amoledEnabledKey)
|
||||||
|
private val globalSyncKeys = listOf(selectedAppLanguageKey)
|
||||||
|
|
||||||
actual fun loadSelectedTheme(): String? =
|
actual fun loadSelectedTheme(): String? =
|
||||||
NSUserDefaults.standardUserDefaults.stringForKey(ProfileScopedKey.of(selectedThemeKey))
|
NSUserDefaults.standardUserDefaults.stringForKey(ProfileScopedKey.of(selectedThemeKey))
|
||||||
|
|
@ -38,10 +39,10 @@ actual object ThemeSettingsStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun loadSelectedAppLanguage(): String? =
|
actual fun loadSelectedAppLanguage(): String? =
|
||||||
NSUserDefaults.standardUserDefaults.stringForKey(ProfileScopedKey.of(selectedAppLanguageKey))
|
NSUserDefaults.standardUserDefaults.stringForKey(selectedAppLanguageKey)
|
||||||
|
|
||||||
actual fun saveSelectedAppLanguage(languageCode: String) {
|
actual fun saveSelectedAppLanguage(languageCode: String) {
|
||||||
NSUserDefaults.standardUserDefaults.setObject(languageCode, forKey = ProfileScopedKey.of(selectedAppLanguageKey))
|
NSUserDefaults.standardUserDefaults.setObject(languageCode, forKey = selectedAppLanguageKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun applySelectedAppLanguage(languageCode: String) = Unit
|
actual fun applySelectedAppLanguage(languageCode: String) = Unit
|
||||||
|
|
@ -53,9 +54,12 @@ actual object ThemeSettingsStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun replaceFromSyncPayload(payload: JsonObject) {
|
actual fun replaceFromSyncPayload(payload: JsonObject) {
|
||||||
syncKeys.forEach { key ->
|
profileScopedSyncKeys.forEach { key ->
|
||||||
NSUserDefaults.standardUserDefaults.removeObjectForKey(ProfileScopedKey.of(key))
|
NSUserDefaults.standardUserDefaults.removeObjectForKey(ProfileScopedKey.of(key))
|
||||||
}
|
}
|
||||||
|
globalSyncKeys.forEach { key ->
|
||||||
|
NSUserDefaults.standardUserDefaults.removeObjectForKey(key)
|
||||||
|
}
|
||||||
|
|
||||||
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)
|
payload.decodeSyncString(selectedThemeKey)?.let(::saveSelectedTheme)
|
||||||
payload.decodeSyncBoolean(amoledEnabledKey)?.let(::saveAmoledEnabled)
|
payload.decodeSyncBoolean(amoledEnabledKey)?.let(::saveAmoledEnabled)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue