mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/3967 - Invokes pending deletion with more bookmark actions (https://github.com/mozilla-mobile/fenix/pull/4522)
This commit is contained in:
parent
e7ca5257b4
commit
409cea2128
@ -44,7 +44,8 @@ class DefaultBookmarkController(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val navController: NavController,
|
private val navController: NavController,
|
||||||
private val snackbarPresenter: FenixSnackbarPresenter,
|
private val snackbarPresenter: FenixSnackbarPresenter,
|
||||||
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit
|
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit,
|
||||||
|
private val invokePendingDeletion: () -> Unit
|
||||||
) : BookmarkController {
|
) : BookmarkController {
|
||||||
|
|
||||||
private val activity: HomeActivity = context as HomeActivity
|
private val activity: HomeActivity = context as HomeActivity
|
||||||
@ -77,7 +78,8 @@ class DefaultBookmarkController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun handleBookmarkSharing(item: BookmarkNode) {
|
override fun handleBookmarkSharing(item: BookmarkNode) {
|
||||||
navigate(BookmarkFragmentDirections.actionBookmarkFragmentToShareFragment(
|
navigate(
|
||||||
|
BookmarkFragmentDirections.actionBookmarkFragmentToShareFragment(
|
||||||
url = item.url!!,
|
url = item.url!!,
|
||||||
title = item.title
|
title = item.title
|
||||||
)
|
)
|
||||||
@ -93,10 +95,12 @@ class DefaultBookmarkController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun handleBackPressed() {
|
override fun handleBackPressed() {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleSigningIn() {
|
override fun handleSigningIn() {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
services.launchPairingSignIn(context, navController)
|
services.launchPairingSignIn(context, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +110,7 @@ class DefaultBookmarkController(
|
|||||||
from: BrowserDirection,
|
from: BrowserDirection,
|
||||||
mode: BrowsingMode
|
mode: BrowsingMode
|
||||||
) {
|
) {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
with(activity) {
|
with(activity) {
|
||||||
browsingModeManager.mode = mode
|
browsingModeManager.mode = mode
|
||||||
openToBrowserAndLoad(searchTermOrURL, newTab, from)
|
openToBrowserAndLoad(searchTermOrURL, newTab, from)
|
||||||
@ -113,6 +118,7 @@ class DefaultBookmarkController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun navigate(directions: NavDirections) {
|
private fun navigate(directions: NavDirections) {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.nav(R.id.bookmarkFragment, directions)
|
navController.nav(R.id.bookmarkFragment, directions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavDirections
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import kotlinx.android.synthetic.main.fragment_bookmark.view.*
|
import kotlinx.android.synthetic.main.fragment_bookmark.view.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
@ -91,7 +92,8 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
|
|||||||
context = context!!,
|
context = context!!,
|
||||||
navController = findNavController(),
|
navController = findNavController(),
|
||||||
snackbarPresenter = FenixSnackbarPresenter(view),
|
snackbarPresenter = FenixSnackbarPresenter(view),
|
||||||
deleteBookmarkNodes = ::deleteMulti
|
deleteBookmarkNodes = ::deleteMulti,
|
||||||
|
invokePendingDeletion = ::invokePendingDeletion
|
||||||
),
|
),
|
||||||
metrics = metrics!!
|
metrics = metrics!!
|
||||||
)
|
)
|
||||||
@ -185,12 +187,12 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.libraryClose -> {
|
R.id.libraryClose -> {
|
||||||
|
invokePendingDeletion()
|
||||||
close()
|
close()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.add_bookmark_folder -> {
|
R.id.add_bookmark_folder -> {
|
||||||
nav(
|
navigate(
|
||||||
R.id.bookmarkFragment,
|
|
||||||
BookmarkFragmentDirections
|
BookmarkFragmentDirections
|
||||||
.actionBookmarkFragmentToBookmarkAddFolderFragment()
|
.actionBookmarkFragmentToBookmarkAddFolderFragment()
|
||||||
)
|
)
|
||||||
@ -199,23 +201,23 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
|
|||||||
R.id.open_bookmarks_in_new_tabs_multi_select -> {
|
R.id.open_bookmarks_in_new_tabs_multi_select -> {
|
||||||
openItemsInNewTab { node -> node.url }
|
openItemsInNewTab { node -> node.url }
|
||||||
|
|
||||||
nav(R.id.bookmarkFragment, BookmarkFragmentDirections.actionBookmarkFragmentToHomeFragment())
|
navigate(BookmarkFragmentDirections.actionBookmarkFragmentToHomeFragment())
|
||||||
metrics?.track(Event.OpenedBookmarksInNewTabs)
|
metrics?.track(Event.OpenedBookmarksInNewTabs)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.open_bookmarks_in_private_tabs_multi_select -> {
|
R.id.open_bookmarks_in_private_tabs_multi_select -> {
|
||||||
openItemsInNewTab(private = true) { node -> node.url }
|
openItemsInNewTab(private = true) { node -> node.url }
|
||||||
|
|
||||||
nav(R.id.bookmarkFragment, BookmarkFragmentDirections.actionBookmarkFragmentToHomeFragment())
|
navigate(BookmarkFragmentDirections.actionBookmarkFragmentToHomeFragment())
|
||||||
metrics?.track(Event.OpenedBookmarksInPrivateTabs)
|
metrics?.track(Event.OpenedBookmarksInPrivateTabs)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.edit_bookmark_multi_select -> {
|
R.id.edit_bookmark_multi_select -> {
|
||||||
val bookmark = bookmarkStore.state.mode.selectedItems.first()
|
val bookmark = bookmarkStore.state.mode.selectedItems.first()
|
||||||
nav(
|
navigate(
|
||||||
R.id.bookmarkFragment,
|
BookmarkFragmentDirections.actionBookmarkFragmentToBookmarkEditFragment(
|
||||||
BookmarkFragmentDirections
|
bookmark.guid
|
||||||
.actionBookmarkFragmentToBookmarkEditFragment(bookmark.guid)
|
)
|
||||||
)
|
)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -227,6 +229,11 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun navigate(directions: NavDirections) {
|
||||||
|
invokePendingDeletion()
|
||||||
|
nav(R.id.bookmarkFragment, directions)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean = bookmarkView.onBackPressed()
|
override fun onBackPressed(): Boolean = bookmarkView.onBackPressed()
|
||||||
|
|
||||||
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
|
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
|
||||||
|
@ -38,6 +38,7 @@ class BookmarkControllerTest {
|
|||||||
private val navController: NavController = mockk(relaxed = true)
|
private val navController: NavController = mockk(relaxed = true)
|
||||||
private val snackbarPresenter: FenixSnackbarPresenter = mockk(relaxed = true)
|
private val snackbarPresenter: FenixSnackbarPresenter = mockk(relaxed = true)
|
||||||
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit = mockk(relaxed = true)
|
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit = mockk(relaxed = true)
|
||||||
|
private val invokePendingDeletion: () -> Unit = mockk(relaxed = true)
|
||||||
|
|
||||||
private val homeActivity: HomeActivity = mockk(relaxed = true)
|
private val homeActivity: HomeActivity = mockk(relaxed = true)
|
||||||
private val services: Services = mockk(relaxed = true)
|
private val services: Services = mockk(relaxed = true)
|
||||||
@ -63,13 +64,16 @@ class BookmarkControllerTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
every { homeActivity.components.services } returns services
|
every { homeActivity.components.services } returns services
|
||||||
every { navController.currentDestination } returns NavDestination("").apply { id = R.id.bookmarkFragment }
|
every { navController.currentDestination } returns NavDestination("").apply {
|
||||||
|
id = R.id.bookmarkFragment
|
||||||
|
}
|
||||||
|
|
||||||
controller = DefaultBookmarkController(
|
controller = DefaultBookmarkController(
|
||||||
context = homeActivity,
|
context = homeActivity,
|
||||||
navController = navController,
|
navController = navController,
|
||||||
snackbarPresenter = snackbarPresenter,
|
snackbarPresenter = snackbarPresenter,
|
||||||
deleteBookmarkNodes = deleteBookmarkNodes
|
deleteBookmarkNodes = deleteBookmarkNodes,
|
||||||
|
invokePendingDeletion = invokePendingDeletion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +82,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleBookmarkTapped(item)
|
controller.handleBookmarkTapped(item)
|
||||||
|
|
||||||
verifyOrder {
|
verifyOrder {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
homeActivity.browsingModeManager.mode = BrowsingMode.Normal
|
homeActivity.browsingModeManager.mode = BrowsingMode.Normal
|
||||||
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
||||||
}
|
}
|
||||||
@ -88,6 +93,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleBookmarkExpand(tree)
|
controller.handleBookmarkExpand(tree)
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.navigate(BookmarkFragmentDirections.actionBookmarkFragmentSelf(tree.guid))
|
navController.navigate(BookmarkFragmentDirections.actionBookmarkFragmentSelf(tree.guid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,6 +112,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleBookmarkEdit(item)
|
controller.handleBookmarkEdit(item)
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.navigate(BookmarkFragmentDirections.actionBookmarkFragmentToBookmarkEditFragment(item.guid))
|
navController.navigate(BookmarkFragmentDirections.actionBookmarkFragmentToBookmarkEditFragment(item.guid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,6 +148,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleBookmarkSharing(item)
|
controller.handleBookmarkSharing(item)
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
BookmarkFragmentDirections.actionBookmarkFragmentToShareFragment(
|
BookmarkFragmentDirections.actionBookmarkFragmentToShareFragment(
|
||||||
item.url,
|
item.url,
|
||||||
@ -155,6 +163,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleOpeningBookmark(item, BrowsingMode.Normal)
|
controller.handleOpeningBookmark(item, BrowsingMode.Normal)
|
||||||
|
|
||||||
verifyOrder {
|
verifyOrder {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
homeActivity.browsingModeManager.mode = BrowsingMode.Normal
|
homeActivity.browsingModeManager.mode = BrowsingMode.Normal
|
||||||
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
||||||
}
|
}
|
||||||
@ -165,6 +174,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleOpeningBookmark(item, BrowsingMode.Private)
|
controller.handleOpeningBookmark(item, BrowsingMode.Private)
|
||||||
|
|
||||||
verifyOrder {
|
verifyOrder {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
homeActivity.browsingModeManager.mode = BrowsingMode.Private
|
homeActivity.browsingModeManager.mode = BrowsingMode.Private
|
||||||
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
||||||
}
|
}
|
||||||
@ -202,6 +212,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleBackPressed()
|
controller.handleBackPressed()
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,6 +222,7 @@ class BookmarkControllerTest {
|
|||||||
controller.handleSigningIn()
|
controller.handleSigningIn()
|
||||||
|
|
||||||
verify {
|
verify {
|
||||||
|
invokePendingDeletion.invoke()
|
||||||
services.launchPairingSignIn(homeActivity, navController)
|
services.launchPairingSignIn(homeActivity, navController)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user