1
0
Fork 0

For #3005: Closes tabs when saving to collection (#3723)

master
Sawyer Blatz 2019-07-01 09:39:48 -07:00 committed by Colin Lee
parent 144335d1be
commit 7e46e71d00
4 changed files with 17 additions and 0 deletions

View File

@ -790,6 +790,7 @@ class BrowserFragment : Fragment(), BackHandler {
viewModel?.saveCollectionStep =
viewModel?.tabCollections?.getStepForCollectionsSize() ?: SaveCollectionStep.SelectCollection
viewModel?.snackbarAnchorView = nestedScrollQuickAction
viewModel?.previousFragmentId = R.id.browserFragment
view?.let {
val directions = BrowserFragmentDirections.actionBrowserFragmentToCreateCollectionFragment()
nav(R.id.browserFragment, directions)

View File

@ -19,6 +19,7 @@ import org.mozilla.fenix.FenixViewModelProvider
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.home.sessioncontrol.Tab
import org.mozilla.fenix.home.sessioncontrol.toSessionBundle
import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getAutoDisposeObservable
@ -121,6 +122,7 @@ class CreateCollectionFragment : DialogFragment() {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
context.components.core.tabCollectionStorage.createCollection(it.name, sessionBundle)
}
closeTabsIfNecessary(it.tabs)
}
}
is CollectionCreationAction.SelectCollection -> {
@ -131,6 +133,7 @@ class CreateCollectionFragment : DialogFragment() {
context.components.core.tabCollectionStorage
.addTabsToCollection(it.collection, sessionBundle)
}
closeTabsIfNecessary(it.tabs)
}
}
is CollectionCreationAction.RenameCollection -> {
@ -170,4 +173,15 @@ class CreateCollectionFragment : DialogFragment() {
}
}
}
private fun closeTabsIfNecessary(tabs: List<Tab>) {
// Only close the tabs if the user is not on the BrowserFragment
if (viewModel.previousFragmentId == R.id.browserFragment) { return }
tabs.forEach {
requireComponents.core.sessionManager.findSessionById(it.sessionId)?.let { session ->
requireComponents.useCases.tabsUseCases.removeTab.invoke(session)
}
}
}
}

View File

@ -16,6 +16,7 @@ class CreateCollectionViewModel : ViewModel() {
var tabCollections = listOf<TabCollection>()
var selectedTabCollection: TabCollection? = null
var snackbarAnchorView: View? = null
var previousFragmentId: Int? = null
fun getStepForTabsAndCollectionSize(): SaveCollectionStep =
if (tabs.size > 1) SaveCollectionStep.SelectTabs else tabCollections.getStepForCollectionsSize()

View File

@ -702,6 +702,7 @@ class HomeFragment : Fragment(), AccountObserver {
viewModel?.selectedTabCollection = selectedTabCollection
viewModel?.saveCollectionStep =
step ?: viewModel?.getStepForTabsAndCollectionSize() ?: SaveCollectionStep.SelectTabs
viewModel?.previousFragmentId = R.id.homeFragment
// Only register the observer right before moving to collection creation
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)