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

Move snackbar to TabTrayDialogFragment

parent f653964e
......@@ -97,7 +97,6 @@ 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
......@@ -222,38 +221,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
tabTrayDialog.dismiss()
}
override fun onTabClosed(tab: Tab) {
TODO("Not yet implemented")
}
override fun onNewTabTapped(private: Boolean) {
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.fromBoolean(private)
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
)
}
}
}
)
......
......@@ -373,30 +373,7 @@ class HomeFragment : Fragment() {
}
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
)
TODO("Not yet implemented")
}
}
}
......
......@@ -10,12 +10,16 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.component_tabstray.view.*
import kotlinx.android.synthetic.main.fragment_tab_tray_dialog.*
import kotlinx.android.synthetic.main.fragment_tab_tray_dialog.view.*
import mozilla.components.concept.tabstray.Tab
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.utils.allowUndo
class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
interface Interactor {
......@@ -64,7 +68,32 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
}
override fun onTabClosed(tab: Tab) {
interactor?.onTabClosed(tab)
// interactor?.onTabClosed(tab)
val sessionManager = view?.context?.components?.core?.sessionManager
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?.handle
)
}
override fun onTabSelected(tab: Tab) {
......
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