Commit 0761f391 authored by Sebastian Kaspari's avatar Sebastian Kaspari
Browse files

Update to latest feature-intent and feature-recentlyclosed APIs (and update Android Components).

parent 7983a7fc
......@@ -45,14 +45,14 @@ class IntentProcessors(
* Provides intent processing functionality for ACTION_VIEW and ACTION_SEND intents.
*/
val intentProcessor by lazyMonitored {
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = false)
TabIntentProcessor(tabsUseCases, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = false)
}
/**
* Provides intent processing functionality for ACTION_VIEW and ACTION_SEND intents in private tabs.
*/
val privateIntentProcessor by lazyMonitored {
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
TabIntentProcessor(tabsUseCases, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
}
val customTabIntentProcessor by lazyMonitored {
......
......@@ -8,11 +8,11 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
class RecentlyClosedAdapter(
private val interactor: RecentlyClosedFragmentInteractor
) : ListAdapter<ClosedTab, RecentlyClosedItemViewHolder>(DiffCallback) {
) : ListAdapter<RecoverableTab, RecentlyClosedItemViewHolder>(DiffCallback) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
......@@ -26,11 +26,11 @@ class RecentlyClosedAdapter(
holder.bind(getItem(position))
}
private object DiffCallback : DiffUtil.ItemCallback<ClosedTab>() {
override fun areItemsTheSame(oldItem: ClosedTab, newItem: ClosedTab) =
private object DiffCallback : DiffUtil.ItemCallback<RecoverableTab>() {
override fun areItemsTheSame(oldItem: RecoverableTab, newItem: RecoverableTab) =
oldItem.id == newItem.id
override fun areContentsTheSame(oldItem: ClosedTab, newItem: ClosedTab) =
override fun areContentsTheSame(oldItem: RecoverableTab, newItem: RecoverableTab) =
oldItem.id == newItem.id
}
}
......@@ -11,10 +11,10 @@ import androidx.navigation.NavController
import androidx.navigation.NavOptions
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.feature.recentlyclosed.ext.restoreTab
import mozilla.components.feature.tabs.TabsUseCases
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
......@@ -22,29 +22,30 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.FenixSnackbar
interface RecentlyClosedController {
fun handleOpen(item: ClosedTab, mode: BrowsingMode? = null)
fun handleDeleteOne(tab: ClosedTab)
fun handleCopyUrl(item: ClosedTab)
fun handleShare(item: ClosedTab)
fun handleOpen(item: RecoverableTab, mode: BrowsingMode? = null)
fun handleDeleteOne(tab: RecoverableTab)
fun handleCopyUrl(item: RecoverableTab)
fun handleShare(item: RecoverableTab)
fun handleNavigateToHistory()
fun handleRestore(item: ClosedTab)
fun handleRestore(item: RecoverableTab)
}
class DefaultRecentlyClosedController(
private val navController: NavController,
private val store: BrowserStore,
private val sessionManager: SessionManager,
private val tabsUseCases: TabsUseCases,
private val resources: Resources,
private val snackbar: FenixSnackbar,
private val clipboardManager: ClipboardManager,
private val activity: HomeActivity,
private val openToBrowser: (item: ClosedTab, mode: BrowsingMode?) -> Unit
private val openToBrowser: (item: RecoverableTab, mode: BrowsingMode?) -> Unit
) : RecentlyClosedController {
override fun handleOpen(item: ClosedTab, mode: BrowsingMode?) {
override fun handleOpen(item: RecoverableTab, mode: BrowsingMode?) {
openToBrowser(item, mode)
}
override fun handleDeleteOne(tab: ClosedTab) {
override fun handleDeleteOne(tab: RecoverableTab) {
store.dispatch(RecentlyClosedAction.RemoveClosedTabAction(tab))
}
......@@ -55,7 +56,7 @@ class DefaultRecentlyClosedController(
)
}
override fun handleCopyUrl(item: ClosedTab) {
override fun handleCopyUrl(item: RecoverableTab) {
val urlClipData = ClipData.newPlainText(item.url, item.url)
clipboardManager.setPrimaryClip(urlClipData)
with(snackbar) {
......@@ -64,7 +65,7 @@ class DefaultRecentlyClosedController(
}
}
override fun handleShare(item: ClosedTab) {
override fun handleShare(item: RecoverableTab) {
navController.navigate(
RecentlyClosedFragmentDirections.actionGlobalShareFragment(
data = arrayOf(ShareData(url = item.url, title = item.title))
......@@ -72,15 +73,15 @@ class DefaultRecentlyClosedController(
)
}
override fun handleRestore(item: ClosedTab) {
item.restoreTab(
store,
sessionManager,
onTabRestored = {
activity.openToBrowser(
from = BrowserDirection.FromRecentlyClosed
)
}
override fun handleRestore(item: RecoverableTab) {
tabsUseCases.restore(item)
store.dispatch(
RecentlyClosedAction.RemoveClosedTabAction(item)
)
activity.openToBrowser(
from = BrowserDirection.FromRecentlyClosed
)
}
}
......@@ -18,7 +18,7 @@ import kotlinx.android.synthetic.main.fragment_recently_closed_tabs.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
......@@ -34,7 +34,7 @@ import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.library.LibraryPageFragment
@Suppress("TooManyFunctions")
class RecentlyClosedFragment : LibraryPageFragment<ClosedTab>() {
class RecentlyClosedFragment : LibraryPageFragment<RecoverableTab>() {
private lateinit var recentlyClosedFragmentStore: RecentlyClosedFragmentStore
private var _recentlyClosedFragmentView: RecentlyClosedFragmentView? = null
protected val recentlyClosedFragmentView: RecentlyClosedFragmentView
......@@ -82,6 +82,7 @@ class RecentlyClosedFragment : LibraryPageFragment<ClosedTab>() {
navController = findNavController(),
store = requireComponents.core.store,
activity = activity as HomeActivity,
tabsUseCases = requireComponents.useCases.tabsUseCases,
sessionManager = requireComponents.core.sessionManager,
resources = requireContext().resources,
snackbar = FenixSnackbar.make(
......@@ -104,7 +105,7 @@ class RecentlyClosedFragment : LibraryPageFragment<ClosedTab>() {
_recentlyClosedFragmentView = null
}
private fun openItem(tab: ClosedTab, mode: BrowsingMode? = null) {
private fun openItem(tab: RecoverableTab, mode: BrowsingMode? = null) {
mode?.let { (activity as HomeActivity).browsingModeManager.mode = it }
(activity as HomeActivity).openToBrowserAndLoad(
......@@ -131,5 +132,5 @@ class RecentlyClosedFragment : LibraryPageFragment<ClosedTab>() {
}
}
override val selectedItems: Set<ClosedTab> = setOf()
override val selectedItems: Set<RecoverableTab> = setOf()
}
......@@ -4,7 +4,7 @@
package org.mozilla.fenix.library.recentlyclosed
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
/**
......@@ -14,27 +14,27 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
class RecentlyClosedFragmentInteractor(
private val recentlyClosedController: RecentlyClosedController
) : RecentlyClosedInteractor {
override fun restore(item: ClosedTab) {
override fun restore(item: RecoverableTab) {
recentlyClosedController.handleRestore(item)
}
override fun onCopyPressed(item: ClosedTab) {
override fun onCopyPressed(item: RecoverableTab) {
recentlyClosedController.handleCopyUrl(item)
}
override fun onSharePressed(item: ClosedTab) {
override fun onSharePressed(item: RecoverableTab) {
recentlyClosedController.handleShare(item)
}
override fun onOpenInNormalTab(item: ClosedTab) {
override fun onOpenInNormalTab(item: RecoverableTab) {
recentlyClosedController.handleOpen(item, BrowsingMode.Normal)
}
override fun onOpenInPrivateTab(item: ClosedTab) {
override fun onOpenInPrivateTab(item: RecoverableTab) {
recentlyClosedController.handleOpen(item, BrowsingMode.Private)
}
override fun onDeleteOne(tab: ClosedTab) {
override fun onDeleteOne(tab: RecoverableTab) {
recentlyClosedController.handleDeleteOne(tab)
}
......
......@@ -4,7 +4,7 @@
package org.mozilla.fenix.library.recentlyclosed
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
......@@ -23,14 +23,14 @@ class RecentlyClosedFragmentStore(initialState: RecentlyClosedFragmentState) :
* `RecentlyClosedFragmentState` through the reducer.
*/
sealed class RecentlyClosedFragmentAction : Action {
data class Change(val list: List<ClosedTab>) : RecentlyClosedFragmentAction()
data class Change(val list: List<RecoverableTab>) : RecentlyClosedFragmentAction()
}
/**
* The state for the Recently Closed Screen
* @property items List of recently closed tabs to display
*/
data class RecentlyClosedFragmentState(val items: List<ClosedTab> = emptyList()) : State
data class RecentlyClosedFragmentState(val items: List<RecoverableTab> = emptyList()) : State
/**
* The RecentlyClosedFragmentState Reducer.
......
......@@ -12,7 +12,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.component_recently_closed.*
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import org.mozilla.fenix.R
interface RecentlyClosedInteractor {
......@@ -21,7 +21,7 @@ interface RecentlyClosedInteractor {
*
* @param item the tapped item to restore.
*/
fun restore(item: ClosedTab)
fun restore(item: RecoverableTab)
/**
* Called when the view more history option is tapped.
......@@ -33,35 +33,35 @@ interface RecentlyClosedInteractor {
*
* @param item the recently closed tab item to copy the URL from
*/
fun onCopyPressed(item: ClosedTab)
fun onCopyPressed(item: RecoverableTab)
/**
* Opens the share sheet for a recently closed tab item.
*
* @param item the recently closed tab item to share
*/
fun onSharePressed(item: ClosedTab)
fun onSharePressed(item: RecoverableTab)
/**
* Opens a recently closed tab item in a new tab.
*
* @param item the recently closed tab item to open in a new tab
*/
fun onOpenInNormalTab(item: ClosedTab)
fun onOpenInNormalTab(item: RecoverableTab)
/**
* Opens a recently closed tab item in a private tab.
*
* @param item the recently closed tab item to open in a private tab
*/
fun onOpenInPrivateTab(item: ClosedTab)
fun onOpenInPrivateTab(item: RecoverableTab)
/**
* Deletes one recently closed tab item.
*
* @param item the recently closed tab item to delete.
* @param tab the recently closed tab item to delete.
*/
fun onDeleteOne(tab: ClosedTab)
fun onDeleteOne(tab: RecoverableTab)
}
/**
......@@ -102,7 +102,7 @@ class RecentlyClosedFragmentView(
}
}
fun update(items: List<ClosedTab>) {
fun update(items: List<RecoverableTab>) {
recently_closed_empty_view.isVisible = items.isEmpty()
recently_closed_list.isVisible = items.isNotEmpty()
recentlyClosedAdapter.submitList(items)
......
......@@ -7,7 +7,7 @@ package org.mozilla.fenix.library.recentlyclosed
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.history_list_item.view.*
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import org.mozilla.fenix.R
import org.mozilla.fenix.library.history.HistoryItemMenu
import org.mozilla.fenix.utils.Do
......@@ -17,14 +17,14 @@ class RecentlyClosedItemViewHolder(
private val recentlyClosedFragmentInteractor: RecentlyClosedFragmentInteractor
) : RecyclerView.ViewHolder(view) {
private var item: ClosedTab? = null
private var item: RecoverableTab? = null
init {
setupMenu()
}
fun bind(
item: ClosedTab
item: RecoverableTab
) {
itemView.history_layout.titleView.text =
if (item.title.isNotEmpty()) item.title else item.url
......
......@@ -13,18 +13,16 @@ import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.feature.recentlyclosed.ext.restoreTab
import mozilla.components.feature.tabs.TabsUseCases
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
......@@ -47,16 +45,18 @@ class DefaultRecentlyClosedControllerTest {
private val resources: Resources = mockk(relaxed = true)
private val snackbar: FenixSnackbar = mockk(relaxed = true)
private val clipboardManager: ClipboardManager = mockk(relaxed = true)
private val openToBrowser: (ClosedTab, BrowsingMode?) -> Unit = mockk(relaxed = true)
private val openToBrowser: (RecoverableTab, BrowsingMode?) -> Unit = mockk(relaxed = true)
private val sessionManager: SessionManager = mockk(relaxed = true)
private val activity: HomeActivity = mockk(relaxed = true)
private val store: BrowserStore = mockk(relaxed = true)
val mockedTab: ClosedTab = mockk(relaxed = true)
private val tabsUseCases: TabsUseCases = mockk(relaxed = true)
val mockedTab: RecoverableTab = mockk(relaxed = true)
private val controller = DefaultRecentlyClosedController(
navController,
store,
sessionManager,
tabsUseCases,
resources,
snackbar,
clipboardManager,
......@@ -66,19 +66,17 @@ class DefaultRecentlyClosedControllerTest {
@Before
fun setUp() {
mockkStatic("mozilla.components.feature.recentlyclosed.ext.ClosedTabKt")
every { mockedTab.restoreTab(any(), any(), any()) } just Runs
every { tabsUseCases.restore.invoke(any(), true) } just Runs
}
@After
fun tearDown() {
dispatcher.cleanupTestCoroutines()
unmockkStatic("mozilla.components.feature.recentlyclosed.ext.ClosedTabKt")
}
@Test
fun handleOpen() {
val item: ClosedTab = mockk(relaxed = true)
val item: RecoverableTab = mockk(relaxed = true)
controller.handleOpen(item, BrowsingMode.Private)
......@@ -95,7 +93,7 @@ class DefaultRecentlyClosedControllerTest {
@Test
fun handleDeleteOne() {
val item: ClosedTab = mockk(relaxed = true)
val item: RecoverableTab = mockk(relaxed = true)
controller.handleDeleteOne(item)
......@@ -120,7 +118,7 @@ class DefaultRecentlyClosedControllerTest {
@Test
fun handleCopyUrl() {
val item = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val item = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
val clipdata = slot<ClipData>()
......@@ -139,7 +137,7 @@ class DefaultRecentlyClosedControllerTest {
@Test
@Suppress("UNCHECKED_CAST")
fun handleShare() {
val item = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val item = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
controller.handleShare(item)
......@@ -160,12 +158,6 @@ class DefaultRecentlyClosedControllerTest {
dispatcher.advanceUntilIdle()
verify {
mockedTab.restoreTab(
store,
sessionManager,
onTabRestored = any()
)
}
verify { tabsUseCases.restore.invoke(mockedTab, true) }
}
}
......@@ -6,7 +6,7 @@ package org.mozilla.fenix.library.recentlyclosed
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.browser.state.state.ClosedTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
......@@ -27,7 +27,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun open() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.restore(tab)
verify {
......@@ -37,7 +37,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun onCopyPressed() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.onCopyPressed(tab)
verify {
......@@ -47,7 +47,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun onSharePressed() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.onSharePressed(tab)
verify {
......@@ -57,7 +57,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun onOpenInNormalTab() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.onOpenInNormalTab(tab)
verify {
......@@ -67,7 +67,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun onOpenInPrivateTab() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.onOpenInPrivateTab(tab)
verify {
......@@ -77,7 +77,7 @@ class RecentlyClosedFragmentInteractorTest {
@Test
fun onDeleteOne() {
val tab = ClosedTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", createdAt = 1L)
val tab = RecoverableTab(id = "tab-id", title = "Mozilla", url = "mozilla.org", lastAccess = 1L)
interactor.onDeleteOne(tab)
verify {
......
......@@ -3,5 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
object AndroidComponents {
const val VERSION = "71.0.20210110143120"
const val VERSION = "71.0.20210111162202"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment