Don't restart activity if inactive theme is changed

Change-Id: I1241b419cf588606af7e465bb1ac8285a026b944
This commit is contained in:
SpiritCroc 2020-09-06 15:50:44 +02:00
parent 9dca2d433e
commit 65716c0ee8
1 changed files with 9 additions and 9 deletions

View File

@ -56,9 +56,11 @@ class VectorSettingsPreferencesFragment @Inject constructor(
val darkThemePref = findPreference<VectorListPreference>(ThemeUtils.APPLICATION_DARK_THEME_KEY)!!
lightThemePref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
if (newValue is String) {
ThemeUtils.setApplicationLightTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.restart()
if (!ThemeUtils.shouldUseDarkTheme(requireContext())) {
ThemeUtils.setApplicationLightTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.restart()
}
true
} else {
false
@ -68,12 +70,10 @@ class VectorSettingsPreferencesFragment @Inject constructor(
lightThemePref.title = getString(R.string.settings_light_theme)
darkThemePref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
if (newValue is String) {
ThemeUtils.setApplicationDarkTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.let {
// Note: recreate does not apply the color correctly
it.startActivity(it.intent)
it.finish()
if (ThemeUtils.shouldUseDarkTheme(requireContext())) {
ThemeUtils.setApplicationDarkTheme(requireContext().applicationContext, newValue)
// Restart the Activity
activity?.restart()
}
true
} else {