From e4a25f41236face8ce3235fd242b731eb014ed94 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Tue, 17 Aug 2021 13:07:14 -0400 Subject: [PATCH] For #21035 - Refactor HistoryViewInteractor from HistoryView into HistoryInteractor --- .../fenix/library/history/HistoryFragment.kt | 2 +- .../library/history/HistoryInteractor.kt | 73 ++++++++++++++++++- .../fenix/library/history/HistoryView.kt | 67 ----------------- .../library/history/HistoryInteractorTest.kt | 2 +- 4 files changed, 72 insertions(+), 72 deletions(-) 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 7cbba31de..4d8db0768 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 @@ -101,7 +101,7 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl syncHistory = ::syncHistory, metrics = requireComponents.analytics.metrics ) - historyInteractor = HistoryInteractor( + historyInteractor = DefaultHistoryInteractor( historyController ) _historyView = HistoryView( diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt index e7792e827..e72acf29c 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt @@ -5,15 +5,82 @@ package org.mozilla.fenix.library.history import org.mozilla.fenix.browser.browsingmode.BrowsingMode +import org.mozilla.fenix.selection.SelectionInteractor + +/** + * Interface for the HistoryInteractor. This interface is implemented by objects that want + * to respond to user interaction on the HistoryView + */ +interface HistoryInteractor : SelectionInteractor { + + /** + * Called on backpressed to exit edit mode + */ + fun onBackPressed(): Boolean + + /** + * Called when the mode is switched so we can invalidate the menu + */ + fun onModeSwitched() + + /** + * Copies the URL of a history item to the copy-paste buffer. + * + * @param item the history item to copy the URL from + */ + fun onCopyPressed(item: HistoryItem) + + /** + * Opens the share sheet for a history item. + * + * @param item the history item to share + */ + fun onSharePressed(item: HistoryItem) + + /** + * Opens a history item in a new tab. + * + * @param item the history item to open in a new tab + */ + fun onOpenInNormalTab(item: HistoryItem) + + /** + * Opens a history item in a private tab. + * + * @param item the history item to open in a private tab + */ + fun onOpenInPrivateTab(item: HistoryItem) + + /** + * Called when delete all is tapped + */ + fun onDeleteAll() + + /** + * Called when multiple history items are deleted + * @param items the history items to delete + */ + fun onDeleteSome(items: Set) + + /** + * Called when the user requests a sync of the history + */ + fun onRequestSync() + + /** + * Called when the user clicks on recently closed tab button. + */ + fun onRecentlyClosedClicked() +} /** * Interactor for the history screen - * Provides implementations for the HistoryViewInteractor + * Provides implementations for the HistoryInteractor */ @SuppressWarnings("TooManyFunctions") -class HistoryInteractor( +class DefaultHistoryInteractor( private val historyController: HistoryController -) : HistoryViewInteractor { +) : HistoryInteractor { override fun open(item: HistoryItem) { historyController.handleOpen(item) } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryView.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryView.kt index ad4fdf839..24f818367 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryView.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryView.kt @@ -14,75 +14,8 @@ import org.mozilla.fenix.R import org.mozilla.fenix.databinding.ComponentHistoryBinding import org.mozilla.fenix.ext.components import org.mozilla.fenix.library.LibraryPageView -import org.mozilla.fenix.selection.SelectionInteractor import org.mozilla.fenix.theme.ThemeManager -/** - * Interface for the HistoryViewInteractor. This interface is implemented by objects that want - * to respond to user interaction on the HistoryView - */ -interface HistoryViewInteractor : SelectionInteractor { - - /** - * Called on backpressed to exit edit mode - */ - fun onBackPressed(): Boolean - - /** - * Called when the mode is switched so we can invalidate the menu - */ - fun onModeSwitched() - - /** - * Copies the URL of a history item to the copy-paste buffer. - * - * @param item the history item to copy the URL from - */ - fun onCopyPressed(item: HistoryItem) - - /** - * Opens the share sheet for a history item. - * - * @param item the history item to share - */ - fun onSharePressed(item: HistoryItem) - - /** - * Opens a history item in a new tab. - * - * @param item the history item to open in a new tab - */ - fun onOpenInNormalTab(item: HistoryItem) - - /** - * Opens a history item in a private tab. - * - * @param item the history item to open in a private tab - */ - fun onOpenInPrivateTab(item: HistoryItem) - - /** - * Called when delete all is tapped - */ - fun onDeleteAll() - - /** - * Called when multiple history items are deleted - * @param items the history items to delete - */ - fun onDeleteSome(items: Set) - - /** - * Called when the user requests a sync of the history - */ - fun onRequestSync() - - /** - * Called when the user clicks on recently closed tab button. - */ - fun onRecentlyClosedClicked() -} - /** * View that contains and configures the History List */ diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt index 4d5365657..557ce5f2f 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt @@ -14,7 +14,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode class HistoryInteractorTest { private val historyItem = HistoryItem(0, "title", "url", 0.toLong()) val controller: HistoryController = mockk(relaxed = true) - val interactor = HistoryInteractor(controller) + val interactor = DefaultHistoryInteractor(controller) @Test fun onOpen() {