From b2f4e4327b28d4666850a5979d9e36b983268119 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Thu, 30 May 2019 16:13:06 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/2723 - Creates callbacks to wire up the mode and theme manager together --- .../org/mozilla/fenix/BrowsingModeManager.kt | 16 ++++++++++++---- .../main/java/org/mozilla/fenix/HomeActivity.kt | 12 ++++++++++-- .../main/java/org/mozilla/fenix/ThemeManager.kt | 6 +++++- .../org/mozilla/fenix/browser/BrowserFragment.kt | 1 + .../QuickSettingsSheetDialogFragment.kt | 1 + 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt b/app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt index 2d5ff3afe4..953e956bb0 100644 --- a/app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt +++ b/app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt @@ -8,7 +8,9 @@ import org.mozilla.fenix.utils.Settings interface BrowsingModeManager { enum class Mode { - Normal, Private + Normal, Private; + + fun isPrivate(): Boolean = this == Private } val isPrivate: Boolean @@ -36,13 +38,19 @@ fun Settings.createBrowserModeStorage(): BrowserModeStorage = object : BrowserMo } -class DefaultBrowsingModeManager(private val storage: BrowserModeStorage) : BrowsingModeManager { +class DefaultBrowsingModeManager( + private val storage: BrowserModeStorage, + private val modeDidChange: (BrowsingModeManager.Mode) -> Unit +) : BrowsingModeManager { override val isPrivate: Boolean get() = mode == BrowsingModeManager.Mode.Private override var mode: BrowsingModeManager.Mode get() = storage.currentMode() - set(value) = storage.setMode(value) + set(value) { + storage.setMode(value) + modeDidChange(mode) + } } class CustomTabBrowsingModeManager : BrowsingModeManager { @@ -50,4 +58,4 @@ class CustomTabBrowsingModeManager : BrowsingModeManager { override var mode: BrowsingModeManager.Mode get() = BrowsingModeManager.Mode.Normal set(_) { return } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index bd5438d614..c820839366 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -259,12 +259,20 @@ open class HomeActivity : AppCompatActivity() { private fun createBrowsingModeManager(): BrowsingModeManager { return if (isCustomTab) CustomTabBrowsingModeManager() - else DefaultBrowsingModeManager(Settings.getInstance(this).createBrowserModeStorage()) + else DefaultBrowsingModeManager(Settings.getInstance(this).createBrowserModeStorage()) { + themeManager.setTheme(when (it.isPrivate()) { + true -> ThemeManager.Theme.Private + false -> ThemeManager.Theme.Normal + }) + } } private fun createThemeManager(currentTheme: ThemeManager.Theme): ThemeManager { return if (isCustomTab) CustomTabThemeManager() - else DefaultThemeManager(currentTheme) + else DefaultThemeManager(currentTheme) { + setTheme(it) + recreate() + } } private fun subscribeToSessions(): SessionManager.Observer { diff --git a/app/src/main/java/org/mozilla/fenix/ThemeManager.kt b/app/src/main/java/org/mozilla/fenix/ThemeManager.kt index 58d7be0553..fdb6ac05ac 100644 --- a/app/src/main/java/org/mozilla/fenix/ThemeManager.kt +++ b/app/src/main/java/org/mozilla/fenix/ThemeManager.kt @@ -119,13 +119,17 @@ fun Activity.setTheme(theme: ThemeManager.Theme) { setTheme(themeCode) } -class DefaultThemeManager(private var _currentTheme: ThemeManager.Theme) : ThemeManager { +class DefaultThemeManager( + private var _currentTheme: ThemeManager.Theme, + private val onThemeChanged: (ThemeManager.Theme) -> Unit +) : ThemeManager { override val currentTheme: ThemeManager.Theme get() = _currentTheme override fun setTheme(theme: ThemeManager.Theme) { if (theme == _currentTheme) return _currentTheme = theme + onThemeChanged(theme) } } diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 712c1dcca7..78baaa0f86 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -44,6 +44,7 @@ import mozilla.components.feature.readerview.ReaderViewFeature import mozilla.components.feature.session.FullScreenFeature import mozilla.components.feature.session.SessionFeature import mozilla.components.feature.session.SessionUseCases +import mozilla.components.feature.session.SwipeRefreshFeature import mozilla.components.feature.session.ThumbnailsFeature import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissionsFeature diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt index ddb5dacc17..f946f61771 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsSheetDialogFragment.kt @@ -33,6 +33,7 @@ import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.R import org.mozilla.fenix.browser.BrowserFragment +import org.mozilla.fenix.currentThemeResource import org.mozilla.fenix.exceptions.ExceptionDomains import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.requireComponents