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

Commit

Permalink
Closes #3493 - Show tab saved to collection snackbar in BrowserFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Jun 14, 2019
1 parent 7ebdfcc commit ac5c4a0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import org.mozilla.fenix.collections.SaveCollectionStep
import org.mozilla.fenix.collections.getStepForCollectionsSize
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.Event.BrowserMenuItemTapped.Item
import org.mozilla.fenix.components.toolbar.SearchAction
Expand Down Expand Up @@ -458,6 +459,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
sessionObserver = subscribeToSession()
sessionManagerObserver = subscribeToSessions()
tabCollectionObserver = subscribeToTabCollections()
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)

getSessionById()?.let { updateBookmarkState(it) }

Expand Down Expand Up @@ -923,6 +925,32 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
}
}

private val collectionStorageObserver = object : TabCollectionStorage.Observer {
override fun onCollectionCreated(title: String, sessions: List<Session>) {
super.onCollectionCreated(title, sessions)
showTabSavedToCollectionSnackbar()
}

override fun onTabsAdded(
tabCollection: mozilla.components.feature.tab.collections.TabCollection,
sessions: List<Session>
) {
super.onTabsAdded(tabCollection, sessions)
showTabSavedToCollectionSnackbar()
}
}

private fun showTabSavedToCollectionSnackbar() {
context?.let { context: Context ->
view?.let { view: View ->
val string = context.getString(R.string.create_collection_tab_saved)
FenixSnackbar.make(view, Snackbar.LENGTH_SHORT).setText(string)
.setAnchorView(toolbarComponent.uiView.view)
.show()
}
}
}

private fun shareUrl(url: String) {
val directions = BrowserFragmentDirections.actionBrowserFragmentToShareFragment(url)
nav(R.id.browserFragment, directions)
Expand Down

0 comments on commit ac5c4a0

Please sign in to comment.