2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

For #1658 - Reload current session (if exists) when theme changes

This commit is contained in:
Emily Kager 2019-04-16 10:08:05 -07:00 committed by Emily Kager
parent bc07da91a2
commit 8e5958580e

View File

@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.requireComponents
class ThemeFragment : PreferenceFragmentCompat() { class ThemeFragment : PreferenceFragmentCompat() {
private lateinit var radioLightTheme: RadioButtonPreference private lateinit var radioLightTheme: RadioButtonPreference
@ -64,8 +65,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyLightTheme = getString(R.string.pref_key_light_theme) val keyLightTheme = getString(R.string.pref_key_light_theme)
radioLightTheme = requireNotNull(findPreference(keyLightTheme)) radioLightTheme = requireNotNull(findPreference(keyLightTheme))
radioLightTheme.onClickListener { radioLightTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) setNewTheme(AppCompatDelegate.MODE_NIGHT_NO)
activity?.recreate()
} }
} }
@ -75,8 +75,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyBatteryTheme = getString(R.string.pref_key_auto_battery_theme) val keyBatteryTheme = getString(R.string.pref_key_auto_battery_theme)
radioAutoBatteryTheme = requireNotNull(findPreference(keyBatteryTheme)) radioAutoBatteryTheme = requireNotNull(findPreference(keyBatteryTheme))
radioAutoBatteryTheme.onClickListener { radioAutoBatteryTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY) setNewTheme(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
activity?.recreate()
} }
} }
@ -84,8 +83,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyDarkTheme = getString(R.string.pref_key_dark_theme) val keyDarkTheme = getString(R.string.pref_key_dark_theme)
radioDarkTheme = requireNotNull(findPreference(keyDarkTheme)) radioDarkTheme = requireNotNull(findPreference(keyDarkTheme))
radioDarkTheme.onClickListener { radioDarkTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) setNewTheme(AppCompatDelegate.MODE_NIGHT_YES)
activity?.recreate()
} }
} }
@ -94,9 +92,14 @@ class ThemeFragment : PreferenceFragmentCompat() {
radioFollowDeviceTheme = requireNotNull(findPreference(keyDeviceTheme)) radioFollowDeviceTheme = requireNotNull(findPreference(keyDeviceTheme))
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
radioFollowDeviceTheme.onClickListener { radioFollowDeviceTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
activity?.recreate()
} }
} }
} }
private fun setNewTheme(mode: Int) {
AppCompatDelegate.setDefaultNightMode(mode)
activity?.recreate()
requireComponents.useCases.sessionUseCases.reload.invoke()
}
} }