Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #2329 , For #2332: Invoke pending delete session job on navigate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager authored and colintheshots committed May 8, 2019
1 parent 1105f94 commit eb4e159
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class HomeFragment : Fragment(), CoroutineScope {
(toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
view.toolbar.compoundDrawablePadding = roundToInt
view.toolbar.setOnClickListener {
invokePendingDeleteSessionJob()
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
Navigation.findNavController(it).navigate(directions)

Expand Down Expand Up @@ -206,6 +207,7 @@ class HomeFragment : Fragment(), CoroutineScope {
showCollectionCreationFragment(action.selectedTabSessionId)
}
is TabAction.Select -> {
invokePendingDeleteSessionJob()
val session =
requireComponents.core.sessionManager.findSessionById(action.sessionId)
requireComponents.core.sessionManager.select(session!!)
Expand Down Expand Up @@ -241,6 +243,7 @@ class HomeFragment : Fragment(), CoroutineScope {
)
}
is TabAction.Add -> {
invokePendingDeleteSessionJob()
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
Navigation.findNavController(view!!).navigate(directions)
}
Expand All @@ -250,6 +253,16 @@ class HomeFragment : Fragment(), CoroutineScope {
}
}

private fun invokePendingDeleteSessionJob() {
deleteSessionJob?.let {
launch {
it.invoke()
}.invokeOnCompletion {
deleteSessionJob = null
}
}
}

@Suppress("ComplexMethod")
private fun handleCollectionAction(action: CollectionAction) {
when (action) {
Expand Down Expand Up @@ -298,13 +311,20 @@ class HomeFragment : Fragment(), CoroutineScope {
private fun setupHomeMenu() {
homeMenu = HomeMenu(requireContext()) {
when (it) {
HomeMenu.Item.Settings -> Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToSettingsFragment()
)
HomeMenu.Item.Library -> Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToLibraryFragment()
)
HomeMenu.Item.Settings -> {
invokePendingDeleteSessionJob()
Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToSettingsFragment()
)
}
HomeMenu.Item.Library -> {
invokePendingDeleteSessionJob()
Navigation.findNavController(homeLayout).navigate(
HomeFragmentDirections.actionHomeFragmentToLibraryFragment()
)
}
HomeMenu.Item.Help -> {
invokePendingDeleteSessionJob()
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic(
context!!,
Expand Down Expand Up @@ -367,7 +387,7 @@ class HomeFragment : Fragment(), CoroutineScope {
.map {
val selected =
it == sessionManager.selectedSession
org.mozilla.fenix.home.sessioncontrol.Tab(
Tab(
it.id,
it.url,
it.url.urlToTrimmedHost(),
Expand Down Expand Up @@ -408,7 +428,7 @@ class HomeFragment : Fragment(), CoroutineScope {
.filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private }
.map {
val selected = it == sessionManager.selectedSession
org.mozilla.fenix.home.sessioncontrol.Tab(
Tab(
it.id,
it.url,
it.url.urlToTrimmedHost(),
Expand Down

0 comments on commit eb4e159

Please sign in to comment.