1
0
Fork 0

Only set the engine's theme when it is instantiated

master
ekager 2019-04-18 21:40:07 -07:00 committed by Jeff Boek
parent 9e2164720e
commit af613962e5
3 changed files with 7 additions and 4 deletions

View File

@ -65,7 +65,6 @@ open class HomeActivity : AppCompatActivity() {
DefaultThemeManager.applyStatusBarTheme(window, themeManager, this)
browsingModeManager = DefaultBrowsingModeManager(this)
components.core.setEnginePreferredColorScheme()
setContentView(R.layout.activity_home)
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.libraryFragment)).build()

View File

@ -62,7 +62,8 @@ class Core(private val context: Context) {
remoteDebuggingEnabled = Settings.getInstance(context).isRemoteDebuggingEnabled,
testingModeEnabled = false,
trackingProtectionPolicy = createTrackingProtectionPolicy(),
historyTrackingDelegate = HistoryDelegate(historyStorage)
historyTrackingDelegate = HistoryDelegate(historyStorage),
preferredColorScheme = getPreferredColorScheme()
)
GeckoEngine(context, defaultSettings, runtime)
@ -153,11 +154,11 @@ class Core(private val context: Context) {
/**
* Sets Preferred Color scheme based on Dark/Light Theme Settings or Current Configuration
*/
fun setEnginePreferredColorScheme() {
fun getPreferredColorScheme(): PreferredColorScheme {
val inDark =
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES
engine.settings.preferredColorScheme = when {
return when {
Settings.getInstance(context).shouldUseDarkTheme -> PreferredColorScheme.Dark
Settings.getInstance(context).shouldUseLightTheme -> PreferredColorScheme.Light
inDark -> PreferredColorScheme.Dark

View File

@ -100,6 +100,9 @@ class ThemeFragment : PreferenceFragmentCompat() {
private fun setNewTheme(mode: Int) {
AppCompatDelegate.setDefaultNightMode(mode)
activity?.recreate()
with(requireComponents.core) {
engine.settings.preferredColorScheme = getPreferredColorScheme()
}
requireComponents.useCases.sessionUseCases.reload.invoke()
}
}