Skip to content

Commit

Permalink
For mozilla-mobile#26489 - Add synced tab pickup onboarding message
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah541 committed Aug 17, 2022
1 parent 32b635d commit c95b1c0
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
50 changes: 50 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -205,6 +206,13 @@ class SessionControlView(
super.onLayoutCompleted(state)

JumpBackInCFRDialog(view).showIfNeeded()
val syncCFRPresenter = SyncCFRPresenter(
context = context,
settings = context.settings(),
recyclerView = view
)

syncCFRPresenter.start()
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.mozilla.fenix.onboarding

import android.content.Context
import android.view.View
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,
) {

private var syncCFR: CFRPopup? = null

/**
* Check if [settings] allow sync CFR which may trigger showing one.
*/
fun start() {
if (settings.showSyncCFR) {
showSyncCFR()
}
}

private 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())
}
}
}

private 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
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1800,4 +1800,5 @@
<!-- Snackbar button text to navigate to telemetry settings.-->
<string name="experiments_snackbar_button">Go to settings</string>
<string name="firefox_suggest_header">Firefox Suggest</string>
<string name="sync_cfr_message">Your tabs are syncing! Pick up where you left off on your other device.</string>
</resources>

0 comments on commit c95b1c0

Please sign in to comment.