For #14243: Pre-land visuals for Close Tabs CFR (#15171)

pull/159/head^2
Sawyer Blatz 4 years ago committed by GitHub
parent 57755fe165
commit 0fa2509bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,6 +13,7 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import kotlinx.android.synthetic.main.info_banner.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
/**
* Displays an Info Banner in the specified container with a message and an optional action.
@ -25,12 +26,15 @@ import org.mozilla.fenix.R
* @param actionText - The text on the action to perform button
* @param actionToPerform - The action to be performed on action button press
*/
@SuppressWarnings("LongParameterList")
class InfoBanner(
private val context: Context,
private val container: ViewGroup,
private val message: String,
private val dismissText: String,
private val actionText: String? = null,
private val dismissByHiding: Boolean = false,
private val dismissAction: (() -> Unit)? = null,
private val actionToPerform: (() -> Unit)? = null
) {
@SuppressLint("InflateParams")
@ -54,12 +58,15 @@ class InfoBanner(
params.width = MATCH_PARENT
bannerLayout.dismiss.setOnClickListener {
dismiss()
dismissAction?.invoke()
if (dismissByHiding) { bannerLayout.visibility = GONE } else { dismiss() }
}
bannerLayout.action.setOnClickListener {
actionToPerform?.invoke()
}
context.settings().lastCfrShownTimeInMillis = System.currentTimeMillis()
}
internal fun dismiss() {

@ -60,7 +60,6 @@ class OpenInAppOnboardingObserver(
infoBanner?.showBanner()
sessionDomainForDisplayedBanner = session.url.tryGetHostFromUrl()
settings.lastCfrShownTimeInMillis = System.currentTimeMillis()
settings.shouldShowOpenInAppBanner = false
}
}

@ -43,6 +43,7 @@ interface TabTrayController {
fun handleOpenTab(tab: Tab)
fun handleEnterMultiselect()
fun handleRecentlyClosedClicked()
fun handleSetUpAutoCloseTabsClicked()
}
/**
@ -184,4 +185,9 @@ class DefaultTabTrayController(
val directions = TabTrayDialogFragmentDirections.actionGlobalRecentlyClosed()
navController.navigate(directions)
}
override fun handleSetUpAutoCloseTabsClicked() {
val directions = TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment()
navController.navigate(directions)
}
}

@ -54,6 +54,11 @@ interface TabTrayInteractor {
*/
fun onModeRequested(): TabTrayDialogFragmentState.Mode
/**
* Called when user clicks on the "set it up" prompt for automatically closing tabs
*/
fun onSetUpAutoCloseTabsClicked()
/**
* Called when a tab should be opened in the browser.
*/
@ -140,4 +145,8 @@ class TabTrayFragmentInteractor(private val controller: TabTrayController) : Tab
override fun onEnterMultiselect() {
controller.handleEnterMultiselect()
}
override fun onSetUpAutoCloseTabsClicked() {
controller.handleSetUpAutoCloseTabsClicked()
}
}

@ -43,6 +43,7 @@ import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.feature.syncedtabs.SyncedTabsFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.InfoBanner
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.toolbar.TabCounter.Companion.INFINITE_CHAR_PADDING_BOTTOM
import org.mozilla.fenix.components.toolbar.TabCounter.Companion.MAX_VISIBLE_TABS
@ -239,6 +240,28 @@ class TabTrayView(
}
adjustNewTabButtonsForNormalMode()
if (
view.context.settings().shouldShowAutoCloseTabsBanner &&
view.context.settings().canShowCfr &&
tabs.size >= TAB_COUNT_SHOW_CFR
) {
InfoBanner(
context = view.context,
message = view.context.getString(R.string.tab_tray_close_tabs_banner_message),
dismissText = view.context.getString(R.string.tab_tray_close_tabs_banner_negative_button_text),
actionText = view.context.getString(R.string.tab_tray_close_tabs_banner_positive_button_text),
container = view.infoBanner,
dismissByHiding = true,
dismissAction = { view.context.settings().shouldShowAutoCloseTabsBanner = false }
) {
interactor.onSetUpAutoCloseTabsClicked()
view.context.settings().shouldShowAutoCloseTabsBanner = false
}.apply {
view.infoBanner.visibility = View.VISIBLE
showBanner()
}
}
}
private fun handleTabClicked(tab: SyncTab) {
@ -578,6 +601,7 @@ class TabTrayView(
}
companion object {
private const val TAB_COUNT_SHOW_CFR = 6
private const val DEFAULT_TAB_ID = 0
private const val PRIVATE_TAB_ID = 1
private const val EXPAND_AT_SIZE = 3

@ -689,6 +689,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
val shouldShowOpenInAppCfr: Boolean
get() = canShowCfr && shouldShowOpenInAppBanner
var shouldShowAutoCloseTabsBanner by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_should_show_auto_close_tabs_banner),
default = true
)
@VisibleForTesting(otherwise = PRIVATE)
internal val trackingProtectionOnboardingCount = counterPreference(
appContext.getPreferenceKey(R.string.pref_key_tracking_protection_onboarding),

@ -24,6 +24,15 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/infoBanner"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/foundation_normal_theme"
app:layout_constraintTop_toBottomOf="@+id/topBar"/>
<TextView
android:id="@+id/tab_tray_empty_view"
android:layout_width="0dp"
@ -38,7 +47,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topBar" />
app:layout_constraintTop_toBottomOf="@id/infoBanner" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/topBar"
@ -164,7 +173,7 @@
android:background="@color/tab_tray_item_divider_normal_theme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/topBar" />
app:layout_constraintTop_toBottomOf="@+id/infoBanner" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tabsTray"

@ -194,6 +194,9 @@
<!-- A value of `true` means the Open In App Banner has not been shown yet -->
<string name="pref_key_should_show_open_in_app_banner" translatable="false">pref_key_should_show_open_in_app_banner</string>
<!-- A value of `true` means the Auto Close Tabs Banner has not been shown yet -->
<string name="pref_key_should_show_auto_close_tabs_banner" translatable="false">pref_key_should_show_auto_close_tabs_banner</string>
<string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string>
<string name="pref_key_migrating_from_firefox_nightly_tip" translatable="false">pref_key_migrating_from_firefox_nightly_tip</string>
<string name="pref_key_migrating_from_fenix_tip" translatable="false">pref_key_migrating_from_fenix_tip</string>

@ -248,4 +248,14 @@ class DefaultTabTrayControllerTest {
showChooseCollectionDialog(listOf(session))
}
}
@Test
fun handleSetUpAutoCloseTabsClicked() {
controller.handleSetUpAutoCloseTabsClicked()
val directions = TabTrayDialogFragmentDirections.actionGlobalCloseTabSettingsFragment()
verify {
navController.navigate(directions)
}
}
}

@ -106,4 +106,10 @@ class TabTrayFragmentInteractorTest {
interactor.onEnterMultiselect()
verify { controller.handleEnterMultiselect() }
}
@Test
fun onSetUpAutoCloseTabsClicked() {
interactor.onSetUpAutoCloseTabsClicked()
verify { controller.handleSetUpAutoCloseTabsClicked() }
}
}

@ -15,7 +15,7 @@ object Versions {
const val androidx_appcompat = "1.2.0-rc01"
const val androidx_biometric = "1.1.0-alpha01"
const val androidx_coordinator_layout = "1.1.0-rc01"
const val androidx_constraint_layout = "2.0.0-beta6"
const val androidx_constraint_layout = "2.0.0"
const val androidx_preference = "1.1.0"
const val androidx_legacy = "1.0.0"
const val androidx_annotation = "1.1.0"

Loading…
Cancel
Save