1
0
Fork 0

For #10502 - Show snackbar after adding tabs to collection from tab tray

master
Mozilla L10n Automation Bot 2020-06-08 00:03:06 +00:00 committed by Jeff Boek
parent eebc1f936a
commit 5373a75f57
2 changed files with 41 additions and 0 deletions

View File

@ -26,15 +26,18 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.tabstray.Tab
import mozilla.components.feature.tabs.tabstray.TabsFeature
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.collections.SaveCollectionStep
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.components.TabCollectionStorage
@SuppressWarnings("TooManyFunctions")
class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
@ -43,6 +46,16 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
private val tabTrayView: TabTrayView
get() = _tabTrayView!!
private val collectionStorageObserver = object : TabCollectionStorage.Observer {
override fun onCollectionCreated(title: String, sessions: List<Session>) {
showCollectionSnackbar()
}
override fun onTabsAdded(tabCollection: TabCollection, sessions: List<Session>) {
showCollectionSnackbar()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.TabTrayDialogStyle)
@ -192,6 +205,9 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
if (navController.currentDestination?.id == R.id.collectionCreationFragment) return
// Only register the observer right before moving to collection creation
registerCollectionStorageObserver()
val directions = TabTrayDialogFragmentDirections.actionGlobalCollectionCreationFragment(
tabIds = tabIds,
saveCollectionStep = step,
@ -262,6 +278,29 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
}
}
private fun registerCollectionStorageObserver() {
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
}
private fun showCollectionSnackbar() {
view.let {
val snackbar = FenixSnackbar
.make(
duration = FenixSnackbar.LENGTH_LONG,
isDisplayedWithBrowserToolbar = true,
view = (view as View)
)
.setText(requireContext().getString(R.string.create_collection_tabs_saved))
.setAction(requireContext().getString(R.string.create_collection_view)) {
dismissAllowingStateLoss()
findNavController().navigate(TabTrayDialogFragmentDirections.actionGlobalHome())
}
snackbar.view.elevation = ELEVATION
snackbar.show()
}
}
companion object {
private const val ELEVATION = 80f
private const val FRAGMENT_TAG = "tabTrayDialogFragment"

View File

@ -706,6 +706,8 @@
<string name="create_collection_close">Close</string>
<!-- Button to save currently selected tabs in the "select tabs" step of the collection creator-->
<string name="create_collection_save">Save</string>
<!-- Snackbar action to view the collection the user just created or updated -->
<string name="create_collection_view">View</string>
<!-- Default name for a new collection in "name new collection" step of the collection creator. %d is a placeholder for the number of collections-->
<string name="create_collection_default_name">Collection %d</string>