For #17177 - Do not show PBM CFR if entering search on home, make sure fragment attached before showing
This commit is contained in:
parent
f95547c271
commit
d5f625c945
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue