Skip to content

Commit cc81f57

Browse files
committed
Use cached feature flags to determine omnibar type
1 parent 1791f2e commit cc81f57

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import com.duckduckgo.app.browser.omnibar.Omnibar.LogoClickListener
149149
import com.duckduckgo.app.browser.omnibar.Omnibar.OmnibarTextState
150150
import com.duckduckgo.app.browser.omnibar.Omnibar.TextListener
151151
import com.duckduckgo.app.browser.omnibar.Omnibar.ViewMode
152+
import com.duckduckgo.app.browser.omnibar.OmnibarFeatureRepository
152153
import com.duckduckgo.app.browser.omnibar.OmnibarItemPressedListener
153154
import com.duckduckgo.app.browser.omnibar.QueryOrigin
154155
import com.duckduckgo.app.browser.print.PrintDocumentAdapterFactory
@@ -595,6 +596,9 @@ class BrowserTabFragment :
595596
@Inject
596597
lateinit var webViewCompatWrapper: WebViewCompatWrapper
597598

599+
@Inject
600+
lateinit var omnibarFeatureRepository: OmnibarFeatureRepository
601+
598602
/**
599603
* We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
600604
* This is needed because the activity stack will be cleared if an external link is opened in our browser
@@ -1018,7 +1022,7 @@ class BrowserTabFragment :
10181022
omnibar = Omnibar(
10191023
omnibarType = settingsDataStore.omnibarType,
10201024
binding = binding,
1021-
isUnifiedOmnibarEnabled = androidBrowserConfigFeature.useUnifiedOmnibarLayout().isEnabled(),
1025+
isUnifiedOmnibarEnabled = omnibarFeatureRepository.isUnifiedOmnibarEnabled,
10221026
)
10231027

10241028
webViewContainer = binding.webViewContainer
Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,57 @@
1717
package com.duckduckgo.app.browser.omnibar
1818

1919
import androidx.lifecycle.LifecycleOwner
20+
import com.duckduckgo.app.di.AppCoroutineScope
2021
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
2122
import com.duckduckgo.app.pixels.remoteconfig.AndroidBrowserConfigFeature
2223
import com.duckduckgo.app.settings.db.SettingsDataStore
2324
import com.duckduckgo.browser.ui.omnibar.OmnibarType
25+
import com.duckduckgo.common.utils.DispatcherProvider
2426
import com.duckduckgo.di.scopes.AppScope
2527
import com.squareup.anvil.annotations.ContributesMultibinding
28+
import dagger.SingleInstanceIn
29+
import kotlinx.coroutines.CoroutineScope
30+
import kotlinx.coroutines.launch
2631
import javax.inject.Inject
2732

28-
/**
29-
* Observes app lifecycle to ensure that if the Split Omnibar feature is disabled via remote config,
30-
* and the user had selected the Split Omnibar, we revert to Single Top Omnibar.
31-
* If the feature is re-enabled, we restore the user's choice.
32-
*/
3333
@ContributesMultibinding(
3434
scope = AppScope::class,
3535
boundType = MainProcessLifecycleObserver::class,
3636
)
37-
class SplitOmnibarFallbackObserver @Inject constructor(
37+
@SingleInstanceIn(AppScope::class)
38+
class OmnibarFeatureRepository @Inject constructor(
3839
private val settingsDataStore: SettingsDataStore,
3940
private val browserFeatures: AndroidBrowserConfigFeature,
41+
private val dispatcherProvider: DispatcherProvider,
42+
@AppCoroutineScope private val coroutineScope: CoroutineScope,
4043
) : MainProcessLifecycleObserver {
44+
var isUnifiedOmnibarEnabled: Boolean = false
45+
private set
46+
47+
var isSplitOmnibarEnabled: Boolean = false
48+
private set
49+
50+
val isSplitOmnibarAvailable: Boolean
51+
get() = isUnifiedOmnibarEnabled && isSplitOmnibarEnabled
52+
4153
override fun onStart(owner: LifecycleOwner) {
42-
super.onStart(owner)
54+
updateFeatureFlags()
55+
}
56+
57+
fun updateFeatureFlags() {
58+
coroutineScope.launch(dispatcherProvider.io()) {
59+
isUnifiedOmnibarEnabled = browserFeatures.useUnifiedOmnibarLayout().isEnabled()
60+
isSplitOmnibarEnabled = browserFeatures.splitOmnibar().isEnabled()
61+
62+
resetOmnibarTypeIfNecessary()
63+
}
64+
}
4365

44-
if (settingsDataStore.omnibarType == OmnibarType.SPLIT &&
45-
(!browserFeatures.useUnifiedOmnibarLayout().isEnabled() || !browserFeatures.splitOmnibar().isEnabled())
46-
) {
66+
private fun resetOmnibarTypeIfNecessary() {
67+
if (settingsDataStore.omnibarType == OmnibarType.SPLIT && !isSplitOmnibarAvailable) {
4768
settingsDataStore.isSplitOmnibarSelected = true
4869
settingsDataStore.omnibarType = OmnibarType.SINGLE_TOP
49-
} else if (settingsDataStore.isSplitOmnibarSelected &&
50-
browserFeatures.useUnifiedOmnibarLayout().isEnabled() &&
51-
browserFeatures.splitOmnibar().isEnabled()
52-
) {
70+
} else if (settingsDataStore.isSplitOmnibarSelected && isSplitOmnibarAvailable) {
5371
// Restore user's choice if the feature is re-enabled
5472
settingsDataStore.omnibarType = OmnibarType.SPLIT
5573
settingsDataStore.isSplitOmnibarSelected = false

0 commit comments

Comments
 (0)