From 5373a75f57016b755370f831367220c22b77fc8d Mon Sep 17 00:00:00 2001 From: Mozilla L10n Automation Bot Date: Mon, 8 Jun 2020 00:03:06 +0000 Subject: [PATCH] For #10502 - Show snackbar after adding tabs to collection from tab tray --- .../fenix/tabtray/TabTrayDialogFragment.kt | 39 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 2 files changed, 41 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt index edb895fa3b..2e463f7384 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt @@ -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) { + showCollectionSnackbar() + } + + override fun onTabsAdded(tabCollection: TabCollection, sessions: List) { + 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" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8591aae6bc..5a7f3e53ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -706,6 +706,8 @@ Close Save + + View Collection %d