From d5f625c9451f3b430896d4993152459f8e6bb78c Mon Sep 17 00:00:00 2001 From: ekager Date: Mon, 21 Dec 2020 14:52:48 -0800 Subject: [PATCH] For #17177 - Do not show PBM CFR if entering search on home, make sure fragment attached before showing --- .../org/mozilla/fenix/home/HomeFragment.kt | 21 ++++++++++--------- .../java/org/mozilla/fenix/utils/Settings.kt | 9 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 9de1ca29a5..31beb58ed5 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -85,6 +85,7 @@ import mozilla.components.ui.tabcounter.TabCounterMenu import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R +import org.mozilla.fenix.addons.runIfFragmentIsAttached import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.components.FenixSnackbar @@ -345,10 +346,6 @@ class HomeFragment : Fragment() { sessionControlView!!.view.layoutManager?.onRestoreInstanceState(parcelable) } homeViewModel.layoutManagerState = null - - // We have to delay so that the keyboard collapses and the view is resized before the - // animation from SearchFragment happens - delay(ANIMATION_DELAY) } observeSearchEngineChanges() @@ -602,7 +599,9 @@ class HomeFragment : Fragment() { } if (browsingModeManager.mode.isPrivate && - context.settings().showPrivateModeCfr + // We will be showing the search dialog and don't want to show the CFR while the dialog shows + !bundleArgs.getBoolean(FOCUS_ON_ADDRESS_BAR) && + context.settings().shouldShowPrivateModeCfr ) { recommendPrivateBrowsingShortcut() } @@ -714,10 +713,13 @@ class HomeFragment : Fragment() { // We want to show the popup only after privateBrowsingButton is available. // Otherwise, we will encounter an activity token error. privateBrowsingButton.post { - context.settings().lastCfrShownTimeInMillis = System.currentTimeMillis() - privateBrowsingRecommend.showAsDropDown( - privateBrowsingButton, 0, CFR_Y_OFFSET, Gravity.TOP or Gravity.END - ) + runIfFragmentIsAttached { + context.settings().showedPrivateModeContextualFeatureRecommender = true + context.settings().lastCfrShownTimeInMillis = System.currentTimeMillis() + privateBrowsingRecommend.showAsDropDown( + privateBrowsingButton, 0, CFR_Y_OFFSET, Gravity.TOP or Gravity.END + ) + } } } } @@ -1043,7 +1045,6 @@ class HomeFragment : Fragment() { private const val FOCUS_ON_ADDRESS_BAR = "focusOnAddressBar" private const val FOCUS_ON_COLLECTION = "focusOnCollection" - private const val ANIMATION_DELAY = 100L /** * Represents the number of items in [sessionControlView] that are NOT part of diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 6ba49e7504..98b726a8b6 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -837,7 +837,7 @@ class Settings(private val appContext: Context) : PreferencesHolder { fun incrementNumTimesPrivateModeOpened() = numTimesPrivateModeOpened.increment() - private var showedPrivateModeContextualFeatureRecommender by booleanPreference( + var showedPrivateModeContextualFeatureRecommender by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_showed_private_mode_cfr), default = false ) @@ -846,7 +846,7 @@ class Settings(private val appContext: Context) : PreferencesHolder { appContext.getPreferenceKey(R.string.pref_key_private_mode_opened) ) - val showPrivateModeCfr: Boolean + val shouldShowPrivateModeCfr: Boolean get() { if (!canShowCfr) return false val focusInstalled = MozillaProductDetector @@ -854,13 +854,12 @@ class Settings(private val appContext: Context) : PreferencesHolder { .contains(MozillaProductDetector.MozillaProducts.FOCUS.productName) val showCondition = if (focusInstalled) { - numTimesPrivateModeOpened.value == CFR_COUNT_CONDITION_FOCUS_INSTALLED + numTimesPrivateModeOpened.value >= CFR_COUNT_CONDITION_FOCUS_INSTALLED } else { - numTimesPrivateModeOpened.value == CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED + numTimesPrivateModeOpened.value >= CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED } if (showCondition && !showedPrivateModeContextualFeatureRecommender) { - showedPrivateModeContextualFeatureRecommender = true return true }