Commit f653964e authored by David Walsh's avatar David Walsh Committed by Jeff Boek
Browse files

For #10864 - Display snack bar to undo closing tabs

parent a59917cd
......@@ -36,6 +36,7 @@ import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.tabstray.Tab
import mozilla.components.feature.accounts.FxaCapability
import mozilla.components.feature.accounts.FxaWebChannelFeature
import mozilla.components.feature.app.links.AppLinksFeature
......@@ -96,6 +97,7 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.SharedViewModel
import org.mozilla.fenix.tabtray.TabTrayDialogFragment
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
import java.lang.ref.WeakReference
......@@ -225,6 +227,33 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
tabTrayDialog.dismiss()
findNavController().navigate(BrowserFragmentDirections.actionGlobalHome())
}
override fun onTabClosed(tab: Tab) {
val snapshot = sessionManager
.findSessionById(tab.id)?.let {
sessionManager.createSessionSnapshot(it)
} ?: return
val state = snapshot.engineSession?.saveState()
val isSelected = tab.id == requireComponents.core.store.state.selectedTabId ?: false
val snackbarMessage = if (snapshot.session.private) {
getString(R.string.snackbar_private_tab_closed)
} else {
getString(R.string.snackbar_tab_closed)
}
viewLifecycleOwner.lifecycleScope.allowUndo(
requireView(),
snackbarMessage,
getString(R.string.snackbar_deleted_undo),
{
sessionManager.add(snapshot.session, isSelected, engineSessionState = state)
},
operation = { }//,
//anchorView = view?.tab_tray_controls
)
}
}
}
)
......
......@@ -371,6 +371,33 @@ class HomeFragment : Fragment() {
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.fromBoolean(private)
tabTrayDialog.dismiss()
}
override fun onTabClosed(tab: mozilla.components.concept.tabstray.Tab) {
val snapshot = sessionManager
.findSessionById(tab.id)?.let {
sessionManager.createSessionSnapshot(it)
} ?: return
val state = snapshot.engineSession?.saveState()
val isSelected = tab.id == requireComponents.core.store.state.selectedTabId ?: false
val snackbarMessage = if (snapshot.session.private) {
getString(R.string.snackbar_private_tab_closed)
} else {
getString(R.string.snackbar_tab_closed)
}
viewLifecycleOwner.lifecycleScope.allowUndo(
requireView(),
snackbarMessage,
getString(R.string.snackbar_deleted_undo),
{
sessionManager.add(snapshot.session, isSelected, engineSessionState = state)
},
operation = { }//,
//anchorView = view?.tab_tray_controls
)
}
}
}
......
......@@ -21,6 +21,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
interface Interactor {
fun onTabSelected(tab: Tab)
fun onNewTabTapped(private: Boolean)
fun onTabClosed(tab: Tab)
}
private lateinit var tabTrayView: TabTrayView
......@@ -62,6 +63,10 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
}
}
override fun onTabClosed(tab: Tab) {
interactor?.onTabClosed(tab)
}
override fun onTabSelected(tab: Tab) {
interactor?.onTabSelected(tab)
}
......
......@@ -22,6 +22,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
interface TabTrayInteractor {
fun onTabClosed(tab: Tab)
fun onTabSelected(tab: Tab)
fun onNewTabTapped(private: Boolean)
fun onTabTrayDismissed()
......@@ -110,7 +111,9 @@ class TabTrayView(
tabsFeature.filterTabs(filter)
}
override fun onTabClosed(tab: Tab) { /*noop*/ }
override fun onTabClosed(tab: Tab) {
interactor.onTabClosed(tab)
}
override fun onTabReselected(tab: TabLayout.Tab?) { /*noop*/ }
override fun onTabUnselected(tab: TabLayout.Tab?) { /*noop*/ }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment