From 5fb214dc038526e68dc25381c74388a4a8318d80 Mon Sep 17 00:00:00 2001 From: mcarare Date: Wed, 25 Nov 2020 14:18:18 +0200 Subject: [PATCH] For #15366: Add recently closed tabs metrics from history fragment. --- .../org/mozilla/fenix/library/history/HistoryController.kt | 6 +++++- .../org/mozilla/fenix/library/history/HistoryFragment.kt | 5 +++-- .../mozilla/fenix/library/history/HistoryControllerTest.kt | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryController.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryController.kt index 069afb1df86e..96ef57698c82 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryController.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryController.kt @@ -15,6 +15,8 @@ import mozilla.components.concept.engine.prompt.ShareData import org.mozilla.fenix.R import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.components.FenixSnackbar +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController @Suppress("TooManyFunctions") interface HistoryController { @@ -43,7 +45,8 @@ class DefaultHistoryController( private val displayDeleteAll: () -> Unit, private val invalidateOptionsMenu: () -> Unit, private val deleteHistoryItems: (Set) -> Unit, - private val syncHistory: suspend () -> Unit + private val syncHistory: suspend () -> Unit, + private val metrics: MetricController ) : HistoryController { override fun handleOpen(item: HistoryItem, mode: BrowsingMode?) { openToBrowser(item, mode) @@ -111,5 +114,6 @@ class DefaultHistoryController( HistoryFragmentDirections.actionGlobalRecentlyClosed(), NavOptions.Builder().setPopUpTo(R.id.recentlyClosedFragment, true).build() ) + metrics.track(Event.RecentlyClosedTabsOpened) } } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt index 7f2d49db6ec7..26ebe09eb3ab 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt @@ -92,8 +92,9 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl ::displayDeleteAllDialog, ::invalidateOptionsMenu, ::deleteHistoryItems, - ::syncHistory - ) + ::syncHistory, + requireComponents.analytics.metrics + ) historyInteractor = HistoryInteractor( historyController ) diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt index ea6f427cf87f..601c8cc41f76 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt @@ -25,6 +25,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.components.FenixSnackbar +import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.ext.directionsEq import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @@ -45,6 +46,7 @@ class HistoryControllerTest { private val invalidateOptionsMenu: () -> Unit = mockk(relaxed = true) private val deleteHistoryItems: (Set) -> Unit = mockk(relaxed = true) private val syncHistory: suspend () -> Unit = mockk(relaxed = true) + private val metrics: MetricController = mockk(relaxed = true) private val controller = DefaultHistoryController( store, navController, @@ -56,7 +58,8 @@ class HistoryControllerTest { displayDeleteAll, invalidateOptionsMenu, deleteHistoryItems, - syncHistory + syncHistory, + metrics ) @Before