avoid issues with prefChanged not changing

This commit is contained in:
Helium314 2025-03-31 16:27:16 +02:00
parent 3dbd9c6ed9
commit 8247366bdd
4 changed files with 5 additions and 4 deletions

View file

@ -53,6 +53,7 @@ import java.util.zip.ZipOutputStream
class SettingsActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
private val prefs by lazy { this.prefs() }
val prefChanged = MutableStateFlow(0) // simple counter, as the only relevant information is that something changed
fun prefChanged() = prefChanged.value++
private val dictUriFlow = MutableStateFlow<Uri?>(null)
private val cachedDictionaryFile by lazy { File(this.cacheDir.path + File.separator + "temp_dict") }
private val crashReportFiles = MutableStateFlow<List<File>>(emptyList())
@ -236,6 +237,6 @@ class SettingsActivity : ComponentActivity(), SharedPreferences.OnSharedPreferen
}
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {
prefChanged.value++
prefChanged()
}
}

View file

@ -77,7 +77,7 @@ fun LayoutEditDialog(
LayoutUtilsCustom.getLayoutFile(newLayoutName, layoutType, ctx).writeText(it)
LayoutUtilsCustom.onLayoutFileChanged()
onEdited(newLayoutName)
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 555
(ctx.getActivity() as? SettingsActivity)?.prefChanged()
KeyboardSwitcher.getInstance().setThemeNeedsReload()
},
confirmButtonText = stringResource(R.string.save),

View file

@ -168,7 +168,7 @@ fun BackupRestorePreference(setting: Setting) {
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
ctx.getActivity()?.sendBroadcast(newDictBroadcast)
LayoutUtilsCustom.onLayoutFileChanged()
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 210 // for settings reload
(ctx.getActivity() as? SettingsActivity)?.prefChanged()
KeyboardSwitcher.getInstance().setThemeNeedsReload()
}
Preference(name = setting.title, onClick = { showDialog = true })

View file

@ -391,7 +391,7 @@ private fun MainLayoutRow(
if (it == currentSubtype.mainLayoutName())
setCurrentSubtype(currentSubtype.withoutLayout(LayoutType.MAIN))
LayoutUtilsCustom.deleteLayout(it, LayoutType.MAIN, ctx)
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 1234
(ctx.getActivity() as? SettingsActivity)?.prefChanged()
}
)
}