diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 5daf2bb381..10ec307d11 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -251,11 +251,6 @@ open class HomeActivity : AppCompatActivity() { it.register(singleSessionObserver) } } - - override fun onSessionSelected(session: Session) { - super.onSessionSelected(session) - updateThemeForSession(session) - } }.also { components.core.sessionManager.register(it) } } 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 ad8d984b0d..99d5224b31 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.launch import mozilla.appservices.places.BookmarkRoot import mozilla.components.browser.session.Session +import mozilla.components.browser.session.SessionManager import mozilla.components.feature.contextmenu.ContextMenuCandidate import mozilla.components.feature.contextmenu.ContextMenuFeature import mozilla.components.feature.downloads.DownloadsFeature @@ -85,6 +86,8 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, private lateinit var toolbarComponent: ToolbarComponent private var sessionObserver: Session.Observer? = null + private var sessionManagerObserver: SessionManager.Observer? = null + private val sessionFeature = ViewBoundFeatureWrapper() private val contextMenuFeature = ViewBoundFeatureWrapper() private val downloadsFeature = ViewBoundFeatureWrapper() @@ -299,9 +302,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, override fun onResume() { super.onResume() - getSessionById()?.let { - (activity as HomeActivity).updateThemeForSession(it) - } context?.components?.core?.let { val preferredColorScheme = it.getPreferredColorScheme() if (it.engine.settings.preferredColorScheme != preferredColorScheme) { @@ -316,6 +316,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, override fun onStart() { super.onStart() sessionObserver = subscribeToSession() + sessionManagerObserver = subscribeToSessions() updateToolbar() getAutoDisposeObservable() .subscribe { @@ -420,6 +421,9 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, sessionObserver?.let { getSessionById()?.unregister(it) } + sessionManagerObserver?.let { + requireComponents.core.sessionManager.unregister(it) + } } override fun onBackPressed(): Boolean { @@ -606,6 +610,15 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, return observer } + private fun subscribeToSessions(): SessionManager.Observer { + return object : SessionManager.Observer { + override fun onSessionSelected(session: Session) { + super.onSessionSelected(session) + (activity as HomeActivity).updateThemeForSession(session) + } + }.also { requireComponents.core.sessionManager.register(it) } + } + override fun onTouchExplorationStateChanged(enabled: Boolean) { updateToolbar() }