2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

For #2329 , For #2332: Invoke pending delete session job on navigate (#2333)

This commit is contained in:
Emily Kager 2019-05-08 10:27:38 -07:00 committed by Colin Lee
parent 1105f947f0
commit eb4e159101

View File

@ -141,6 +141,7 @@ class HomeFragment : Fragment(), CoroutineScope {
(toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt() (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
view.toolbar.compoundDrawablePadding = roundToInt view.toolbar.compoundDrawablePadding = roundToInt
view.toolbar.setOnClickListener { view.toolbar.setOnClickListener {
invokePendingDeleteSessionJob()
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null) val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
Navigation.findNavController(it).navigate(directions) Navigation.findNavController(it).navigate(directions)
@ -206,6 +207,7 @@ class HomeFragment : Fragment(), CoroutineScope {
showCollectionCreationFragment(action.selectedTabSessionId) showCollectionCreationFragment(action.selectedTabSessionId)
} }
is TabAction.Select -> { is TabAction.Select -> {
invokePendingDeleteSessionJob()
val session = val session =
requireComponents.core.sessionManager.findSessionById(action.sessionId) requireComponents.core.sessionManager.findSessionById(action.sessionId)
requireComponents.core.sessionManager.select(session!!) requireComponents.core.sessionManager.select(session!!)
@ -241,6 +243,7 @@ class HomeFragment : Fragment(), CoroutineScope {
) )
} }
is TabAction.Add -> { is TabAction.Add -> {
invokePendingDeleteSessionJob()
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null) val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
@ -250,6 +253,16 @@ class HomeFragment : Fragment(), CoroutineScope {
} }
} }
private fun invokePendingDeleteSessionJob() {
deleteSessionJob?.let {
launch {
it.invoke()
}.invokeOnCompletion {
deleteSessionJob = null
}
}
}
@Suppress("ComplexMethod") @Suppress("ComplexMethod")
private fun handleCollectionAction(action: CollectionAction) { private fun handleCollectionAction(action: CollectionAction) {
when (action) { when (action) {
@ -298,13 +311,20 @@ class HomeFragment : Fragment(), CoroutineScope {
private fun setupHomeMenu() { private fun setupHomeMenu() {
homeMenu = HomeMenu(requireContext()) { homeMenu = HomeMenu(requireContext()) {
when (it) { when (it) {
HomeMenu.Item.Settings -> Navigation.findNavController(homeLayout).navigate( HomeMenu.Item.Settings -> {
invokePendingDeleteSessionJob()
Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToSettingsFragment() HomeFragmentDirections.actionHomeFragmentToSettingsFragment()
) )
HomeMenu.Item.Library -> Navigation.findNavController(homeLayout).navigate( }
HomeMenu.Item.Library -> {
invokePendingDeleteSessionJob()
Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToLibraryFragment() HomeFragmentDirections.actionHomeFragmentToLibraryFragment()
) )
}
HomeMenu.Item.Help -> { HomeMenu.Item.Help -> {
invokePendingDeleteSessionJob()
(activity as HomeActivity).openToBrowserAndLoad( (activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic( searchTermOrURL = SupportUtils.getSumoURLForTopic(
context!!, context!!,
@ -367,7 +387,7 @@ class HomeFragment : Fragment(), CoroutineScope {
.map { .map {
val selected = val selected =
it == sessionManager.selectedSession it == sessionManager.selectedSession
org.mozilla.fenix.home.sessioncontrol.Tab( Tab(
it.id, it.id,
it.url, it.url,
it.url.urlToTrimmedHost(), it.url.urlToTrimmedHost(),
@ -408,7 +428,7 @@ class HomeFragment : Fragment(), CoroutineScope {
.filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private } .filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private }
.map { .map {
val selected = it == sessionManager.selectedSession val selected = it == sessionManager.selectedSession
org.mozilla.fenix.home.sessioncontrol.Tab( Tab(
it.id, it.id,
it.url, it.url,
it.url.urlToTrimmedHost(), it.url.urlToTrimmedHost(),