For #627 - Set Engine Setting for PreferredColorScheme
parent
9cb252da40
commit
442ca9b79c
|
@ -14,5 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- #1049 - Add style for progress bar with gradient drawable
|
||||
- #1165 - Added doorhanger to the toolbar
|
||||
- #1195 - Adds telemetry for quick action sheet
|
||||
- #627 - Sets engine preferred color scheme based on light/dark theme
|
||||
### Changed
|
||||
### Removed
|
|
@ -53,6 +53,7 @@ open class HomeActivity : AppCompatActivity() {
|
|||
|
||||
setTheme(themeManager.currentTheme)
|
||||
DefaultThemeManager.applyStatusBarTheme(window, themeManager, this)
|
||||
components.core.setEnginePreferredColorScheme()
|
||||
|
||||
browsingModeManager = DefaultBrowsingModeManager(this)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.components
|
|||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -21,6 +22,7 @@ import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
|||
import mozilla.components.concept.engine.DefaultSettings
|
||||
import mozilla.components.concept.engine.Engine
|
||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
||||
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
|
||||
import mozilla.components.concept.fetch.Client
|
||||
import mozilla.components.feature.session.HistoryDelegate
|
||||
import mozilla.components.feature.session.bundling.SessionBundleStorage
|
||||
|
@ -152,6 +154,21 @@ class Core(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Preferred Color scheme based on Dark/Light Theme Settings or Current Configuration
|
||||
*/
|
||||
fun setEnginePreferredColorScheme() {
|
||||
val inDark =
|
||||
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
|
||||
Configuration.UI_MODE_NIGHT_YES
|
||||
engine.settings.preferredColorScheme = when {
|
||||
Settings.getInstance(context).shouldUseDarkTheme -> PreferredColorScheme.Dark
|
||||
Settings.getInstance(context).shouldUseLightTheme -> PreferredColorScheme.Light
|
||||
inDark -> PreferredColorScheme.Dark
|
||||
else -> PreferredColorScheme.Light
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val BUNDLE_LIFETIME_IN_MINUTES = 5L
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue