mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
For #10502 - Show snackbar after adding tabs to collection from tab tray
This commit is contained in:
parent
eebc1f936a
commit
5373a75f57
@ -26,15 +26,18 @@ import mozilla.components.browser.state.state.BrowserState
|
|||||||
import mozilla.components.concept.engine.prompt.ShareData
|
import mozilla.components.concept.engine.prompt.ShareData
|
||||||
import mozilla.components.concept.tabstray.Tab
|
import mozilla.components.concept.tabstray.Tab
|
||||||
import mozilla.components.feature.tabs.tabstray.TabsFeature
|
import mozilla.components.feature.tabs.tabstray.TabsFeature
|
||||||
|
import mozilla.components.feature.tab.collections.TabCollection
|
||||||
import mozilla.components.lib.state.ext.consumeFrom
|
import mozilla.components.lib.state.ext.consumeFrom
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||||
import org.mozilla.fenix.collections.SaveCollectionStep
|
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||||
|
import org.mozilla.fenix.components.FenixSnackbar
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import org.mozilla.fenix.utils.allowUndo
|
import org.mozilla.fenix.utils.allowUndo
|
||||||
|
import org.mozilla.fenix.components.TabCollectionStorage
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions")
|
@SuppressWarnings("TooManyFunctions")
|
||||||
class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
|
class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
|
||||||
@ -43,6 +46,16 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
|
|||||||
private val tabTrayView: TabTrayView
|
private val tabTrayView: TabTrayView
|
||||||
get() = _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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setStyle(STYLE_NO_TITLE, R.style.TabTrayDialogStyle)
|
setStyle(STYLE_NO_TITLE, R.style.TabTrayDialogStyle)
|
||||||
@ -192,6 +205,9 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
|
|||||||
|
|
||||||
if (navController.currentDestination?.id == R.id.collectionCreationFragment) return
|
if (navController.currentDestination?.id == R.id.collectionCreationFragment) return
|
||||||
|
|
||||||
|
// Only register the observer right before moving to collection creation
|
||||||
|
registerCollectionStorageObserver()
|
||||||
|
|
||||||
val directions = TabTrayDialogFragmentDirections.actionGlobalCollectionCreationFragment(
|
val directions = TabTrayDialogFragmentDirections.actionGlobalCollectionCreationFragment(
|
||||||
tabIds = tabIds,
|
tabIds = tabIds,
|
||||||
saveCollectionStep = step,
|
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 {
|
companion object {
|
||||||
private const val ELEVATION = 80f
|
private const val ELEVATION = 80f
|
||||||
private const val FRAGMENT_TAG = "tabTrayDialogFragment"
|
private const val FRAGMENT_TAG = "tabTrayDialogFragment"
|
||||||
|
@ -706,6 +706,8 @@
|
|||||||
<string name="create_collection_close">Close</string>
|
<string name="create_collection_close">Close</string>
|
||||||
<!-- Button to save currently selected tabs in the "select tabs" step of the collection creator-->
|
<!-- Button to save currently selected tabs in the "select tabs" step of the collection creator-->
|
||||||
<string name="create_collection_save">Save</string>
|
<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-->
|
<!-- 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>
|
<string name="create_collection_default_name">Collection %d</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user