From aefa17692f978a56159d76289b6e1433f8e46c4b Mon Sep 17 00:00:00 2001 From: sarah541 Date: Wed, 17 Aug 2022 08:02:19 -0400 Subject: [PATCH] For #26489 - Add synced tab pickup onboarding message --- app/metrics.yaml | 50 ++++++++++++ .../home/sessioncontrol/SessionControlView.kt | 8 ++ .../fenix/onboarding/SyncCFRPresenter.kt | 78 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 137 insertions(+) create mode 100644 app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt diff --git a/app/metrics.yaml b/app/metrics.yaml index 6c2e9afbddd5..d703056253ba 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -447,6 +447,56 @@ events: expires: 113 onboarding: + syn_cfr_shown: + type: event + description: | + The Sync Onboarding CFR was shown to the user + bugs: + - https://github.com/mozilla-mobile/fenix/issues/26489 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/26507 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Onboarding + sync_cfr_implicit_dismissal: + type: event + description: | + The Sync Onboarding CFR was dismissed by the user by interacting + with the outside of the popup. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/26489 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/26507 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Onboarding + sync_cfr_explicit_dismissal: + type: event + description: | + The Sync Onboarding CFR was dismissed by the user by clicking on + the "X" button to close the popup. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/26489 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/26507 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Onboarding fxa_auto_signin: type: event description: diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt index baac4a035e6b..0ed9077ef3b4 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt @@ -23,6 +23,7 @@ import org.mozilla.fenix.home.OnboardingState import org.mozilla.fenix.home.recentbookmarks.RecentBookmark import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem import org.mozilla.fenix.onboarding.JumpBackInCFRDialog +import org.mozilla.fenix.onboarding.SyncCFRPresenter import org.mozilla.fenix.utils.Settings // This method got a little complex with the addition of the tab tray feature flag @@ -205,6 +206,13 @@ class SessionControlView( super.onLayoutCompleted(state) JumpBackInCFRDialog(view).showIfNeeded() + val syncCFRPresenter = SyncCFRPresenter( + context = context, + settings = context.settings(), + recyclerView = view + ) + + syncCFRPresenter.start() } } } diff --git a/app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt b/app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt new file mode 100644 index 000000000000..5dda3a16f1af --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt @@ -0,0 +1,78 @@ +package org.mozilla.fenix.onboarding + +import android.content.Context +import android.view.View +import androidx.annotation.VisibleForTesting +import androidx.recyclerview.widget.RecyclerView +import mozilla.components.service.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Onboarding +import org.mozilla.fenix.R +import org.mozilla.fenix.compose.cfr.CFRPopup +import org.mozilla.fenix.compose.cfr.CFRPopupProperties +import org.mozilla.fenix.home.recentsyncedtabs.view.RecentSyncedTabViewHolder +import org.mozilla.fenix.utils.Settings + +/** + * Delegate for handling sync onboarding CFR. + * + * @param context used for various Android interactions. + * @param settings used to read and write persistent user settings + * @param recyclerView will serve as anchor for the sync CFR + */ + +class SyncCFRPresenter( + private val context: Context, + private val settings: Settings, + private val recyclerView: RecyclerView, +) { + + @VisibleForTesting + internal var syncCFR: CFRPopup? = null + + /** + * Check if [settings] allow sync CFR which may trigger showing one. + */ + fun start() { + if (settings.showSyncCFR) { + showSyncCFR() + } + } + + @VisibleForTesting + internal fun showSyncCFR() { + findSyncTabsView()?.let { + CFRPopup( + text = context.getString(R.string.sync_cfr_message), + anchor = it, + properties = CFRPopupProperties( + indicatorDirection = CFRPopup.IndicatorDirection.DOWN + ), + onDismiss = { + when (it) { + true -> Onboarding.syncCfrExplicitDismissal.record(NoExtras()) + false -> Onboarding.syncCfrImplicitDismissal.record(NoExtras()) + } + } + ) { + }.apply { + settings.showSyncCFR = false + syncCFR = this + show() + Onboarding.synCfrShown.record(NoExtras()) + } + } + } + + @VisibleForTesting + internal fun findSyncTabsView(): View? { + val count = recyclerView.adapter?.itemCount ?: return null + + for (index in count downTo 0) { + val viewHolder = recyclerView.findViewHolderForAdapterPosition(index) + if (viewHolder is RecentSyncedTabViewHolder) { + return viewHolder.composeView + } + } + return null + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0bea8990ac5c..36d1745f07e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1800,4 +1800,5 @@ Go to settings Firefox Suggest + Your tabs are syncing! Pick up where you left off on your other device.