Skip to content

Commit 1965900

Browse files
committed
Use a flag to implement a fallback when the feature is disabled
1 parent 574df86 commit 1965900

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,6 @@ open class BrowserActivity : DuckDuckGoActivity() {
346346

347347
super.onCreate(savedInstanceState = newInstanceState, daggerInject = false)
348348

349-
// safety check: if the omnibar type is SPLIT but the feature is disabled, reset to SINGLE_TOP
350-
if (settingsDataStore.omnibarType == OmnibarType.SPLIT &&
351-
(!browserFeatures.useUnifiedOmnibarLayout().isEnabled() || !browserFeatures.splitOmnibar().isEnabled())
352-
) {
353-
settingsDataStore.omnibarType = OmnibarType.SINGLE_TOP
354-
}
355-
356349
bindMockupToolbars()
357350

358351
setContentView(binding.root)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2025 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.browser.omnibar
18+
19+
import androidx.lifecycle.LifecycleOwner
20+
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
21+
import com.duckduckgo.app.pixels.remoteconfig.AndroidBrowserConfigFeature
22+
import com.duckduckgo.app.settings.db.SettingsDataStore
23+
import com.duckduckgo.browser.ui.omnibar.OmnibarType
24+
import com.duckduckgo.di.scopes.AppScope
25+
import com.squareup.anvil.annotations.ContributesMultibinding
26+
import javax.inject.Inject
27+
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+
*/
33+
@ContributesMultibinding(
34+
scope = AppScope::class,
35+
boundType = MainProcessLifecycleObserver::class,
36+
)
37+
class SplitOmnibarFallbackObserver @Inject constructor(
38+
private val settingsDataStore: SettingsDataStore,
39+
private val browserFeatures: AndroidBrowserConfigFeature,
40+
) : MainProcessLifecycleObserver {
41+
override fun onStart(owner: LifecycleOwner) {
42+
super.onStart(owner)
43+
44+
if (settingsDataStore.omnibarType == OmnibarType.SPLIT &&
45+
(!browserFeatures.useUnifiedOmnibarLayout().isEnabled() || !browserFeatures.splitOmnibar().isEnabled())
46+
) {
47+
settingsDataStore.isSplitOmnibarSelected = true
48+
settingsDataStore.omnibarType = OmnibarType.SINGLE_TOP
49+
} else if (settingsDataStore.isSplitOmnibarSelected &&
50+
browserFeatures.useUnifiedOmnibarLayout().isEnabled() &&
51+
browserFeatures.splitOmnibar().isEnabled()
52+
) {
53+
// Restore user's choice if the feature is re-enabled
54+
settingsDataStore.omnibarType = OmnibarType.SPLIT
55+
settingsDataStore.isSplitOmnibarSelected = false
56+
}
57+
}
58+
}

app/src/main/java/com/duckduckgo/app/settings/db/SettingsDataStore.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ interface SettingsDataStore {
6868
var showAutomaticFireproofDialog: Boolean
6969
var omnibarType: OmnibarType
7070

71+
// Temporary cache value for split omnibar feature, in case the flag is temporarily disabled
72+
var isSplitOmnibarSelected: Boolean
73+
7174
/**
7275
* This will be checked upon app startup and used to decide whether it should perform a clear or not.
7376
* If the app is cleared and the process restarted as a result, then we don't want to clear and restart again when the app launches.
@@ -219,6 +222,10 @@ class SettingsSharedPreferences @Inject constructor(
219222
)
220223
set(value) = preferences.edit { putString(KEY_OMNIBAR_TYPE, value.typeName) }
221224

225+
override var isSplitOmnibarSelected: Boolean
226+
get() = preferences.getBoolean(KEY_SPLIT_OMNIBAR, false)
227+
set(value) = preferences.edit { putBoolean(KEY_SPLIT_OMNIBAR, value) }
228+
222229
override var isFullUrlEnabled: Boolean
223230
get() = preferences.getBoolean(KEY_IS_FULL_URL_ENABLED, true)
224231
set(enabled) = preferences.edit { putBoolean(KEY_IS_FULL_URL_ENABLED, enabled) }
@@ -300,6 +307,7 @@ class SettingsSharedPreferences @Inject constructor(
300307
const val KEY_NOTIFY_ME_IN_DOWNLOADS_DISMISSED = "KEY_NOTIFY_ME_IN_DOWNLOADS_DISMISSED"
301308
const val KEY_EXPERIMENTAL_SITE_DARK_MODE = "KEY_EXPERIMENTAL_SITE_DARK_MODE"
302309
const val KEY_OMNIBAR_TYPE = "KEY_OMNIBAR_POSITION"
310+
const val KEY_SPLIT_OMNIBAR = "KEY_SPLIT_OMNIBAR"
303311
const val KEY_IS_FULL_URL_ENABLED = "KEY_IS_FULL_URL_ENABLED"
304312
const val KEY_CLEAR_DUCK_AI_DATA = "KEY_CLEAR_DUCK_AI_DATA"
305313
}

0 commit comments

Comments
 (0)