@@ -81,6 +81,7 @@ import kotlinx.coroutines.flow.receiveAsFlow
8181import kotlinx.coroutines.flow.stateIn
8282import kotlinx.coroutines.flow.update
8383import kotlinx.coroutines.launch
84+ import kotlinx.coroutines.withContext
8485import logcat.logcat
8586import javax.inject.Inject
8687import 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