Skip to content

Commit

Permalink
For mozilla-mobile#21035 - Refactor HistoryViewInteractor from Histor…
Browse files Browse the repository at this point in the history
…yView into HistoryInteractor
  • Loading branch information
gabrielluong authored and mergify[bot] committed Aug 26, 2021
1 parent 46e8714 commit e4a25f4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
syncHistory = ::syncHistory,
metrics = requireComponents.analytics.metrics
)
historyInteractor = HistoryInteractor(
historyInteractor = DefaultHistoryInteractor(
historyController
)
_historyView = HistoryView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryItem> {

/**
* 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<HistoryItem>)

/**
* 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)
}
Expand Down
67 changes: 0 additions & 67 deletions app/src/main/java/org/mozilla/fenix/library/history/HistoryView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryItem> {

/**
* 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<HistoryItem>)

/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e4a25f4

Please sign in to comment.