@@ -43,20 +43,28 @@ import com.duckduckgo.common.ui.DuckDuckGoTheme.DARK
4343import com.duckduckgo.common.ui.DuckDuckGoTheme.LIGHT
4444import com.duckduckgo.common.ui.DuckDuckGoTheme.SYSTEM_DEFAULT
4545import com.duckduckgo.common.ui.sendThemeChangedBroadcast
46+ import com.duckduckgo.common.ui.store.AppTheme
4647import com.duckduckgo.common.ui.view.dialog.RadioListAlertDialogBuilder
4748import com.duckduckgo.common.ui.view.dialog.TextAlertDialogBuilder
4849import com.duckduckgo.common.ui.view.getColorFromAttr
50+ import com.duckduckgo.common.ui.view.gone
51+ import com.duckduckgo.common.ui.view.show
4952import com.duckduckgo.common.ui.viewbinding.viewBinding
5053import com.duckduckgo.di.scopes.ActivityScope
5154import com.duckduckgo.navigation.api.getActivityParams
5255import kotlinx.coroutines.flow.launchIn
5356import kotlinx.coroutines.flow.onEach
5457import logcat.logcat
58+ import javax.inject.Inject
59+ import com.duckduckgo.mobile.android.R as CommonR
5560
5661@InjectWith(ActivityScope ::class )
5762@ContributeToActivityStarter(Default ::class , screenName = " appearance" )
5863@ContributeToActivityStarter(HighlightedItem ::class , screenName = " appearance" )
5964class AppearanceActivity : DuckDuckGoActivity () {
65+ @Inject
66+ lateinit var appTheme: AppTheme
67+
6068 private val viewModel: AppearanceViewModel by bindViewModel()
6169 private val binding: ActivityAppearanceBinding by viewBinding()
6270
@@ -110,10 +118,43 @@ class AppearanceActivity : DuckDuckGoActivity() {
110118 scrollToHighlightedItem()
111119 }
112120
121+ private fun configureOmnibarSettings (viewState : AppearanceViewModel .ViewState ) {
122+ if (viewState.shouldShowSplitOmnibarSettings) {
123+ configureOmnibarTypeToggle(
124+ top = InputScreenToggleButton .Top (
125+ isActive = viewState.omnibarType == OmnibarType .SINGLE_TOP ,
126+ isLightMode = appTheme.isLightModeEnabled(),
127+ ),
128+ bottom = InputScreenToggleButton .Bottom (
129+ isActive = viewState.omnibarType == OmnibarType .SINGLE_BOTTOM ,
130+ isLightMode = appTheme.isLightModeEnabled(),
131+ ),
132+ split = InputScreenToggleButton .Split (
133+ isActive = viewState.omnibarType == OmnibarType .SPLIT ,
134+ isLightMode = appTheme.isLightModeEnabled(),
135+ ),
136+ )
137+
138+ binding.omnibarTypeSettingsTitle.show()
139+ binding.omnibarTypeToggleContainer.show()
140+ binding.showFullUrlSettingDivider.show()
141+ binding.addressBarPositionSetting.gone()
142+ } else {
143+ updateSelectedOmnibarPosition(viewState.omnibarType)
144+ binding.omnibarTypeSettingsTitle.gone()
145+ binding.omnibarTypeToggleContainer.gone()
146+ binding.showFullUrlSettingDivider.gone()
147+ binding.addressBarPositionSetting.show()
148+ }
149+ }
150+
113151 private fun configureUiEventHandlers () {
114152 binding.selectedThemeSetting.setClickListener { viewModel.userRequestedToChangeTheme() }
115153 binding.changeAppIconSetting.setOnClickListener { viewModel.userRequestedToChangeIcon() }
116154 binding.addressBarPositionSetting.setOnClickListener { viewModel.userRequestedToChangeAddressBarPosition() }
155+ binding.topOmnibarContainer.setOnClickListener { viewModel.onOmnibarTypeSelected(OmnibarType .SINGLE_TOP ) }
156+ binding.bottomOmnibarContainer.setOnClickListener { viewModel.onOmnibarTypeSelected(OmnibarType .SINGLE_BOTTOM ) }
157+ binding.splitOmnibarContainer.setOnClickListener { viewModel.onOmnibarTypeSelected(OmnibarType .SPLIT ) }
117158 }
118159
119160 private fun observeViewModel () {
@@ -127,12 +168,12 @@ class AppearanceActivity : DuckDuckGoActivity() {
127168 binding.experimentalNightMode.quietlySetIsChecked(viewState.forceDarkModeEnabled, forceDarkModeToggleListener)
128169 binding.experimentalNightMode.isEnabled = viewState.canForceDarkMode
129170 binding.experimentalNightMode.isVisible = viewState.supportsForceDarkMode
130- updateSelectedOmnibarPosition(it.omnibarType)
131171 binding.showFullUrlSetting.quietlySetIsChecked(viewState.isFullUrlEnabled, showFullUrlToggleListener)
132172 binding.showTrackersCountInTabSwitcher.quietlySetIsChecked(
133173 viewState.isTrackersCountInTabSwitcherEnabled,
134174 showTrackersCountInTabSwitcher,
135175 )
176+ configureOmnibarSettings(it)
136177 }
137178 }.launchIn(lifecycleScope)
138179
@@ -161,7 +202,7 @@ class AppearanceActivity : DuckDuckGoActivity() {
161202 when (omnibarType) {
162203 OmnibarType .SINGLE_TOP -> R .string.settingsAddressBarPositionTop
163204 OmnibarType .SINGLE_BOTTOM -> R .string.settingsAddressBarPositionBottom
164- OmnibarType .SPLIT -> TODO ( )
205+ OmnibarType .SPLIT -> throw IllegalStateException ( " Split omnibar type should not be shown in address bar position setting " )
165206 },
166207 )
167208 binding.addressBarPositionSetting.setSecondaryText(subtitle)
@@ -224,7 +265,7 @@ class AppearanceActivity : DuckDuckGoActivity() {
224265 object : RadioListAlertDialogBuilder .EventListener () {
225266 override fun onPositiveButtonClicked (selectedItem : Int ) {
226267 val newType = OmnibarType .entries[selectedItem - 1 ]
227- viewModel.setOmnibarType (newType)
268+ viewModel.onOmnibarTypeSelected (newType)
228269 }
229270 },
230271 ).show()
@@ -260,6 +301,74 @@ class AppearanceActivity : DuckDuckGoActivity() {
260301 colorAnimator.start()
261302 }
262303
304+ private fun configureOmnibarTypeToggle (
305+ top : InputScreenToggleButton ,
306+ bottom : InputScreenToggleButton ,
307+ split : InputScreenToggleButton ,
308+ ) = with (binding) {
309+ val context = this @AppearanceActivity
310+ topOmnibarToggleImage.setImageDrawable(ContextCompat .getDrawable(context, top.imageRes))
311+ topOmnibarToggleCheck.setImageDrawable(ContextCompat .getDrawable(context, top.checkRes))
312+
313+ bottomOmnibarToggleImage.setImageDrawable(ContextCompat .getDrawable(context, bottom.imageRes))
314+ bottomOmnibarToggleCheck.setImageDrawable(ContextCompat .getDrawable(context, bottom.checkRes))
315+
316+ splitOmnibarToggleImage.setImageDrawable(ContextCompat .getDrawable(context, split.imageRes))
317+ splitOmnibarToggleCheck.setImageDrawable(ContextCompat .getDrawable(context, split.checkRes))
318+ }
319+
320+ private sealed class InputScreenToggleButton (
321+ isActive : Boolean ,
322+ ) {
323+ abstract val imageRes: Int
324+
325+ val checkRes: Int =
326+ if (isActive) {
327+ CommonR .drawable.ic_check_accent_24
328+ } else {
329+ CommonR .drawable.ic_shape_circle_disabled_24
330+ }
331+
332+ class Top (
333+ isActive : Boolean ,
334+ isLightMode : Boolean ,
335+ ) : InputScreenToggleButton(isActive) {
336+ override val imageRes: Int =
337+ when {
338+ isActive && isLightMode -> R .drawable.mobile_toolbar_top_selected_light
339+ isActive && ! isLightMode -> R .drawable.mobile_toolbar_top_selected_dark
340+ ! isActive && isLightMode -> R .drawable.mobile_toolbar_top_unselected_light
341+ else -> R .drawable.mobile_toolbar_top_unselected_dark
342+ }
343+ }
344+
345+ class Bottom (
346+ isActive : Boolean ,
347+ isLightMode : Boolean ,
348+ ) : InputScreenToggleButton(isActive) {
349+ override val imageRes: Int =
350+ when {
351+ isActive && isLightMode -> R .drawable.mobile_toolbar_bottom_selected_light
352+ isActive && ! isLightMode -> R .drawable.mobile_toolbar_bottom_selected_dark
353+ ! isActive && isLightMode -> R .drawable.mobile_toolbar_bottom_unselected_light
354+ else -> R .drawable.mobile_toolbar_bottom_unselected_dark
355+ }
356+ }
357+
358+ class Split (
359+ isActive : Boolean ,
360+ isLightMode : Boolean ,
361+ ) : InputScreenToggleButton(isActive) {
362+ override val imageRes: Int =
363+ when {
364+ isActive && isLightMode -> R .drawable.mobile_toolbar_split_selected_light
365+ isActive && ! isLightMode -> R .drawable.mobile_toolbar_split_selected_dark
366+ ! isActive && isLightMode -> R .drawable.mobile_toolbar_split_unselected_light
367+ else -> R .drawable.mobile_toolbar_split_unselected_dark
368+ }
369+ }
370+ }
371+
263372 companion object {
264373 private const val ADDRESS_BAR = " addressBar"
265374 private const val FADE_DURATION = 300L
0 commit comments