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