forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#26489 - Add synced tab pickup onboarding message
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/main/java/org/mozilla/fenix/onboarding/SyncCFRPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters