Skip to content

Commit 1201c8a

Browse files
committed
Check serpEasterEggLogosToggles from io
1 parent e4e4e16 commit 1201c8a

File tree

4 files changed

+112
-104
lines changed

4 files changed

+112
-104
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,15 +1950,14 @@ class BrowserTabViewModel @Inject constructor(
19501950

19511951
viewModelScope.launch {
19521952
onboardingDesignExperimentManager.onWebPageFinishedLoading(url)
1953+
evaluateDuckAIPage(url)
1954+
evaluateSerpLogoState(url)
19531955
}
1954-
1955-
evaluateDuckAIPage(url)
1956-
evaluateSerpLogoState(url)
19571956
}
19581957
}
19591958

1960-
private fun evaluateSerpLogoState(url: String?) {
1961-
if (serpEasterEggLogosToggles.feature().isEnabled()) {
1959+
private suspend fun evaluateSerpLogoState(url: String?) {
1960+
if (withContext(dispatchers.io()) { serpEasterEggLogosToggles.feature().isEnabled() }) {
19621961
if (url != null && duckDuckGoUrlDetector.isDuckDuckGoQueryUrl(url)) {
19631962
command.value = ExtractSerpLogo(url)
19641963
} else {

app/src/main/java/com/duckduckgo/app/browser/omnibar/LegacyOmnibarLayout.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import com.google.android.material.appbar.AppBarLayout
110110
import kotlinx.coroutines.flow.collectLatest
111111
import kotlinx.coroutines.flow.map
112112
import kotlinx.coroutines.launch
113+
import kotlinx.coroutines.withContext
113114
import logcat.logcat
114115
import javax.inject.Inject
115116
import kotlin.collections.isNotEmpty
@@ -572,24 +573,26 @@ open class LegacyOmnibarLayout @JvmOverloads constructor(
572573
}
573574

574575
OmnibarLayoutViewModel.LeadingIconState.Dax -> {
575-
if (serpEasterEggLogosToggles.feature().isEnabled()) {
576-
with(daxIcon) {
577-
setOnClickListener(null)
578-
show()
579-
Glide
580-
.with(this)
581-
.load(CommonR.drawable.ic_ddg_logo)
582-
.transition(withCrossFade())
583-
.placeholder(daxIcon.drawable)
584-
.into(this)
576+
lifecycleOwner.lifecycleScope.launch {
577+
if (withContext(dispatchers.io()) { serpEasterEggLogosToggles.feature().isEnabled() }) {
578+
with(daxIcon) {
579+
setOnClickListener(null)
580+
show()
581+
Glide
582+
.with(this)
583+
.load(CommonR.drawable.ic_ddg_logo)
584+
.transition(withCrossFade())
585+
.placeholder(daxIcon.drawable)
586+
.into(this)
587+
}
588+
} else {
589+
daxIcon.show()
585590
}
586-
} else {
587-
daxIcon.show()
591+
shieldIcon.gone()
592+
searchIcon.gone()
593+
globeIcon.gone()
594+
duckPlayerIcon.gone()
588595
}
589-
shieldIcon.gone()
590-
searchIcon.gone()
591-
globeIcon.gone()
592-
duckPlayerIcon.gone()
593596
}
594597

595598
OmnibarLayoutViewModel.LeadingIconState.Globe -> {

app/src/main/java/com/duckduckgo/app/browser/omnibar/OmnibarLayout.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ import dagger.android.support.AndroidSupportInjection
121121
import kotlinx.coroutines.flow.collectLatest
122122
import kotlinx.coroutines.flow.map
123123
import kotlinx.coroutines.launch
124+
import kotlinx.coroutines.withContext
124125
import logcat.logcat
125126
import javax.inject.Inject
126127
import kotlin.collections.isNotEmpty
@@ -723,24 +724,26 @@ class OmnibarLayout @JvmOverloads constructor(
723724
}
724725

725726
OmnibarLayoutViewModel.LeadingIconState.Dax -> {
726-
if (serpEasterEggLogosToggles.feature().isEnabled()) {
727-
with(daxIcon) {
728-
setOnClickListener(null)
729-
show()
730-
Glide
731-
.with(this)
732-
.load(CommonR.drawable.ic_ddg_logo)
733-
.transition(withCrossFade())
734-
.placeholder(daxIcon.drawable)
735-
.into(this)
727+
lifecycleOwner.lifecycleScope.launch {
728+
if (withContext(dispatchers.io()) { serpEasterEggLogosToggles.feature().isEnabled() }) {
729+
with(daxIcon) {
730+
setOnClickListener(null)
731+
show()
732+
Glide
733+
.with(this)
734+
.load(CommonR.drawable.ic_ddg_logo)
735+
.transition(withCrossFade())
736+
.placeholder(daxIcon.drawable)
737+
.into(this)
738+
}
739+
} else {
740+
daxIcon.show()
736741
}
737-
} else {
738-
daxIcon.show()
742+
shieldIcon.gone()
743+
searchIcon.gone()
744+
globeIcon.gone()
745+
duckPlayerIcon.gone()
739746
}
740-
shieldIcon.gone()
741-
searchIcon.gone()
742-
globeIcon.gone()
743-
duckPlayerIcon.gone()
744747
}
745748

746749
OmnibarLayoutViewModel.LeadingIconState.Globe -> {

app/src/main/java/com/duckduckgo/app/browser/omnibar/OmnibarLayoutViewModel.kt

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import kotlinx.coroutines.flow.receiveAsFlow
8181
import kotlinx.coroutines.flow.stateIn
8282
import kotlinx.coroutines.flow.update
8383
import kotlinx.coroutines.launch
84+
import kotlinx.coroutines.withContext
8485
import logcat.logcat
8586
import javax.inject.Inject
8687
import com.duckduckgo.app.global.model.PrivacyShield as PrivacyShieldState
@@ -636,99 +637,101 @@ class OmnibarLayoutViewModel @Inject constructor(
636637
omnibarViewState: OmnibarViewState,
637638
forceRender: Boolean,
638639
) {
639-
if (serpEasterEggLogosToggles.feature().isEnabled()) {
640-
val state = if (shouldUpdateOmnibarTextInput(omnibarViewState, _viewState.value.omnibarText) || forceRender) {
641-
if (forceRender && !duckDuckGoUrlDetector.isDuckDuckGoQueryUrl(omnibarViewState.queryOrFullUrl)) {
642-
val url = if (settingsDataStore.isFullUrlEnabled) {
643-
omnibarViewState.queryOrFullUrl
644-
} else {
645-
addressDisplayFormatter.getShortUrl(omnibarViewState.queryOrFullUrl)
646-
}
647-
_viewState.value.copy(
648-
omnibarText = url,
649-
updateOmnibarText = true,
650-
)
651-
} else {
652-
_viewState.value.copy(
653-
omnibarText = omnibarViewState.omnibarText,
654-
)
655-
}
656-
} else {
657-
_viewState.value
658-
}
659-
660-
if (omnibarViewState.navigationChange) {
661-
_viewState.update {
662-
state.copy(
663-
expanded = true,
664-
expandedAnimated = true,
665-
updateOmnibarText = true,
666-
)
667-
}
668-
} else {
669-
_viewState.update {
670-
state.copy(
671-
expanded = omnibarViewState.forceExpand,
672-
expandedAnimated = omnibarViewState.forceExpand,
673-
updateOmnibarText = true,
674-
showVoiceSearch = shouldShowVoiceSearch(
675-
hasFocus = omnibarViewState.isEditing,
676-
query = omnibarViewState.omnibarText,
677-
hasQueryChanged = true,
678-
urlLoaded = _viewState.value.url,
679-
),
680-
leadingIconState = when (omnibarViewState.serpLogo) {
681-
is SerpLogo.EasterEgg -> getLeadingIconState(
682-
hasFocus = omnibarViewState.isEditing,
683-
url = _viewState.value.url,
684-
logoUrl = omnibarViewState.serpLogo.logoUrl,
685-
)
686-
SerpLogo.Normal, null -> getLeadingIconState(
687-
hasFocus = omnibarViewState.isEditing,
688-
url = _viewState.value.url,
689-
logoUrl = null,
690-
)
691-
},
692-
)
693-
}
694-
}
695-
} else {
696-
if (shouldUpdateOmnibarTextInput(omnibarViewState, _viewState.value.omnibarText) || forceRender) {
697-
val omnibarText = if (forceRender && !duckDuckGoUrlDetector.isDuckDuckGoQueryUrl(omnibarViewState.queryOrFullUrl)) {
698-
if (settingsDataStore.isFullUrlEnabled) {
699-
omnibarViewState.queryOrFullUrl
640+
viewModelScope.launch {
641+
if (withContext(dispatcherProvider.io()) { serpEasterEggLogosToggles.feature().isEnabled() }) {
642+
val state = if (shouldUpdateOmnibarTextInput(omnibarViewState, _viewState.value.omnibarText) || forceRender) {
643+
if (forceRender && !duckDuckGoUrlDetector.isDuckDuckGoQueryUrl(omnibarViewState.queryOrFullUrl)) {
644+
val url = if (settingsDataStore.isFullUrlEnabled) {
645+
omnibarViewState.queryOrFullUrl
646+
} else {
647+
addressDisplayFormatter.getShortUrl(omnibarViewState.queryOrFullUrl)
648+
}
649+
_viewState.value.copy(
650+
omnibarText = url,
651+
updateOmnibarText = true,
652+
)
700653
} else {
701-
addressDisplayFormatter.getShortUrl(omnibarViewState.queryOrFullUrl)
654+
_viewState.value.copy(
655+
omnibarText = omnibarViewState.omnibarText,
656+
)
702657
}
703658
} else {
704-
omnibarViewState.omnibarText
659+
_viewState.value
705660
}
706661

707662
if (omnibarViewState.navigationChange) {
708663
_viewState.update {
709-
it.copy(
664+
state.copy(
710665
expanded = true,
711666
expandedAnimated = true,
712-
omnibarText = omnibarText,
713667
updateOmnibarText = true,
714668
)
715669
}
716670
} else {
717671
_viewState.update {
718-
it.copy(
672+
state.copy(
719673
expanded = omnibarViewState.forceExpand,
720674
expandedAnimated = omnibarViewState.forceExpand,
721-
omnibarText = omnibarText,
722675
updateOmnibarText = true,
723676
showVoiceSearch = shouldShowVoiceSearch(
724677
hasFocus = omnibarViewState.isEditing,
725678
query = omnibarViewState.omnibarText,
726679
hasQueryChanged = true,
727680
urlLoaded = _viewState.value.url,
728681
),
682+
leadingIconState = when (omnibarViewState.serpLogo) {
683+
is SerpLogo.EasterEgg -> getLeadingIconState(
684+
hasFocus = omnibarViewState.isEditing,
685+
url = _viewState.value.url,
686+
logoUrl = omnibarViewState.serpLogo.logoUrl,
687+
)
688+
SerpLogo.Normal, null -> getLeadingIconState(
689+
hasFocus = omnibarViewState.isEditing,
690+
url = _viewState.value.url,
691+
logoUrl = null,
692+
)
693+
},
729694
)
730695
}
731696
}
697+
} else {
698+
if (shouldUpdateOmnibarTextInput(omnibarViewState, _viewState.value.omnibarText) || forceRender) {
699+
val omnibarText = if (forceRender && !duckDuckGoUrlDetector.isDuckDuckGoQueryUrl(omnibarViewState.queryOrFullUrl)) {
700+
if (settingsDataStore.isFullUrlEnabled) {
701+
omnibarViewState.queryOrFullUrl
702+
} else {
703+
addressDisplayFormatter.getShortUrl(omnibarViewState.queryOrFullUrl)
704+
}
705+
} else {
706+
omnibarViewState.omnibarText
707+
}
708+
709+
if (omnibarViewState.navigationChange) {
710+
_viewState.update {
711+
it.copy(
712+
expanded = true,
713+
expandedAnimated = true,
714+
omnibarText = omnibarText,
715+
updateOmnibarText = true,
716+
)
717+
}
718+
} else {
719+
_viewState.update {
720+
it.copy(
721+
expanded = omnibarViewState.forceExpand,
722+
expandedAnimated = omnibarViewState.forceExpand,
723+
omnibarText = omnibarText,
724+
updateOmnibarText = true,
725+
showVoiceSearch = shouldShowVoiceSearch(
726+
hasFocus = omnibarViewState.isEditing,
727+
query = omnibarViewState.omnibarText,
728+
hasQueryChanged = true,
729+
urlLoaded = _viewState.value.url,
730+
),
731+
)
732+
}
733+
}
734+
}
732735
}
733736
}
734737
}

0 commit comments

Comments
 (0)