For 10734 - Open tab tray when collection is opened from Home (#10751)
* For 10734 - Open tab tray when collection is opened from Home * Update to work with tab tray drawermaster
parent
ea4c342797
commit
4fdac4d608
|
@ -235,7 +235,8 @@ class HomeFragment : Fragment() {
|
|||
openSettingsScreen = ::openSettingsScreen,
|
||||
openSearchScreen = ::navigateToSearch,
|
||||
openWhatsNewLink = { openCustomTab(SupportUtils.getWhatsNewUrl(activity)) },
|
||||
openPrivacyNotice = { openCustomTab(SupportUtils.getMozillaPageUrl(PRIVATE_NOTICE)) }
|
||||
openPrivacyNotice = { openCustomTab(SupportUtils.getMozillaPageUrl(PRIVATE_NOTICE)) },
|
||||
showTabTray = ::openTabTray
|
||||
)
|
||||
)
|
||||
updateLayout(view)
|
||||
|
@ -360,87 +361,7 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
|
||||
view.tab_button.setOnClickListener {
|
||||
invokePendingDeleteJobs()
|
||||
hideOnboardingIfNeeded()
|
||||
val tabTrayDialog = TabTrayDialogFragment()
|
||||
tabTrayDialog.show(parentFragmentManager, null)
|
||||
tabTrayDialog.interactor = object : TabTrayDialogFragment.Interactor {
|
||||
override fun onTabSelected(tab: mozilla.components.concept.tabstray.Tab) {
|
||||
tabTrayDialog.dismiss()
|
||||
(activity as HomeActivity).openToBrowser(BrowserDirection.FromHome)
|
||||
}
|
||||
|
||||
override fun onNewTabTapped(private: Boolean) {
|
||||
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.fromBoolean(private)
|
||||
tabTrayDialog.dismiss()
|
||||
}
|
||||
|
||||
override fun onShareTabsClicked(private: Boolean) {
|
||||
share(getListOfSessions(private))
|
||||
}
|
||||
|
||||
override fun onCloseAllTabsClicked(private: Boolean) {
|
||||
val tabs = getListOfSessions(private)
|
||||
|
||||
val selectedIndex = sessionManager
|
||||
.selectedSession?.let { sessionManager.sessions.indexOf(it) } ?: 0
|
||||
|
||||
val snapshot = tabs
|
||||
.map(sessionManager::createSessionSnapshot)
|
||||
.map { it.copy(engineSession = null, engineSessionState = it.engineSession?.saveState()) }
|
||||
.let { SessionManager.Snapshot(it, selectedIndex) }
|
||||
|
||||
tabs.forEach {
|
||||
sessionManager.remove(it)
|
||||
}
|
||||
|
||||
val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate
|
||||
val snackbarMessage = if (isPrivate) {
|
||||
getString(R.string.snackbar_private_tabs_closed)
|
||||
} else {
|
||||
getString(R.string.snackbar_tabs_closed)
|
||||
}
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.allowUndo(
|
||||
requireView(),
|
||||
snackbarMessage,
|
||||
getString(R.string.snackbar_deleted_undo),
|
||||
{
|
||||
sessionManager.restore(snapshot)
|
||||
},
|
||||
operation = { },
|
||||
anchorView = view.tabs_header
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSaveToCollectionClicked() {
|
||||
val tabs = getListOfSessions(false)
|
||||
val tabIds = tabs.map { it.id }.toList().toTypedArray()
|
||||
val tabCollectionStorage = (activity as HomeActivity).components.core.tabCollectionStorage
|
||||
val navController = findNavController()
|
||||
|
||||
val step = when {
|
||||
// Show the SelectTabs fragment if there are multiple opened tabs to select which tabs
|
||||
// you want to save to a collection.
|
||||
tabs.size > 1 -> SaveCollectionStep.SelectTabs
|
||||
// If there is an existing tab collection, show the SelectCollection fragment to save
|
||||
// the selected tab to a collection of your choice.
|
||||
tabCollectionStorage.cachedTabCollections.isNotEmpty() -> SaveCollectionStep.SelectCollection
|
||||
// Show the NameCollection fragment to create a new collection for the selected tab.
|
||||
else -> SaveCollectionStep.NameCollection
|
||||
}
|
||||
|
||||
if (navController.currentDestination?.id == R.id.collectionCreationFragment) return
|
||||
|
||||
val directions = HomeFragmentDirections.actionHomeFragmentToCreateCollectionFragment(
|
||||
tabIds = tabIds,
|
||||
previousFragmentId = R.id.tabTrayFragment,
|
||||
saveCollectionStep = step,
|
||||
selectedTabIds = tabIds
|
||||
)
|
||||
navController.nav(R.id.homeFragment, directions)
|
||||
}
|
||||
}
|
||||
openTabTray()
|
||||
}
|
||||
|
||||
PrivateBrowsingButtonView(
|
||||
|
@ -1101,6 +1022,90 @@ class HomeFragment : Fragment() {
|
|||
nav(R.id.homeFragment, directions)
|
||||
}
|
||||
|
||||
private fun openTabTray() {
|
||||
invokePendingDeleteJobs()
|
||||
hideOnboardingIfNeeded()
|
||||
val tabTrayDialog = TabTrayDialogFragment()
|
||||
tabTrayDialog.show(parentFragmentManager, null)
|
||||
tabTrayDialog.interactor = object : TabTrayDialogFragment.Interactor {
|
||||
override fun onTabSelected(tab: mozilla.components.concept.tabstray.Tab) {
|
||||
tabTrayDialog.dismiss()
|
||||
(activity as HomeActivity).openToBrowser(BrowserDirection.FromHome)
|
||||
}
|
||||
|
||||
override fun onNewTabTapped(private: Boolean) {
|
||||
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.fromBoolean(private)
|
||||
tabTrayDialog.dismiss()
|
||||
}
|
||||
|
||||
override fun onShareTabsClicked(private: Boolean) {
|
||||
share(getListOfSessions(private))
|
||||
}
|
||||
|
||||
override fun onCloseAllTabsClicked(private: Boolean) {
|
||||
val tabs = getListOfSessions(private)
|
||||
|
||||
val selectedIndex = sessionManager
|
||||
.selectedSession?.let { sessionManager.sessions.indexOf(it) } ?: 0
|
||||
|
||||
val snapshot = tabs
|
||||
.map(sessionManager::createSessionSnapshot)
|
||||
.map { it.copy(engineSession = null, engineSessionState = it.engineSession?.saveState()) }
|
||||
.let { SessionManager.Snapshot(it, selectedIndex) }
|
||||
|
||||
tabs.forEach {
|
||||
sessionManager.remove(it)
|
||||
}
|
||||
|
||||
val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate
|
||||
val snackbarMessage = if (isPrivate) {
|
||||
getString(R.string.snackbar_private_tabs_closed)
|
||||
} else {
|
||||
getString(R.string.snackbar_tabs_closed)
|
||||
}
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.allowUndo(
|
||||
requireView(),
|
||||
snackbarMessage,
|
||||
getString(R.string.snackbar_deleted_undo),
|
||||
{
|
||||
sessionManager.restore(snapshot)
|
||||
},
|
||||
operation = { },
|
||||
anchorView = view?.tabs_header
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSaveToCollectionClicked() {
|
||||
val tabs = getListOfSessions(false)
|
||||
val tabIds = tabs.map { it.id }.toList().toTypedArray()
|
||||
val tabCollectionStorage = (activity as HomeActivity).components.core.tabCollectionStorage
|
||||
val navController = findNavController()
|
||||
|
||||
val step = when {
|
||||
// Show the SelectTabs fragment if there are multiple opened tabs to select which tabs
|
||||
// you want to save to a collection.
|
||||
tabs.size > 1 -> SaveCollectionStep.SelectTabs
|
||||
// If there is an existing tab collection, show the SelectCollection fragment to save
|
||||
// the selected tab to a collection of your choice.
|
||||
tabCollectionStorage.cachedTabCollections.isNotEmpty() -> SaveCollectionStep.SelectCollection
|
||||
// Show the NameCollection fragment to create a new collection for the selected tab.
|
||||
else -> SaveCollectionStep.NameCollection
|
||||
}
|
||||
|
||||
if (navController.currentDestination?.id == R.id.collectionCreationFragment) return
|
||||
|
||||
val directions = HomeFragmentDirections.actionHomeFragmentToCreateCollectionFragment(
|
||||
tabIds = tabIds,
|
||||
previousFragmentId = R.id.tabTrayFragment,
|
||||
saveCollectionStep = step,
|
||||
selectedTabIds = tabIds
|
||||
)
|
||||
navController.nav(R.id.homeFragment, directions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ANIMATION_DELAY = 100L
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.mozilla.fenix.home.HomeFragmentAction
|
|||
import org.mozilla.fenix.home.HomeFragmentDirections
|
||||
import org.mozilla.fenix.home.HomeFragmentStore
|
||||
import org.mozilla.fenix.home.Tab
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
import mozilla.components.feature.tab.collections.Tab as ComponentTab
|
||||
|
||||
|
@ -187,7 +188,8 @@ class DefaultSessionControlController(
|
|||
private val openSettingsScreen: () -> Unit,
|
||||
private val openSearchScreen: () -> Unit,
|
||||
private val openWhatsNewLink: () -> Unit,
|
||||
private val openPrivacyNotice: () -> Unit
|
||||
private val openPrivacyNotice: () -> Unit,
|
||||
private val showTabTray: () -> Unit
|
||||
) : SessionControlController {
|
||||
private val metrics: MetricController
|
||||
get() = activity.components.analytics.metrics
|
||||
|
@ -248,7 +250,12 @@ class DefaultSessionControlController(
|
|||
}
|
||||
)
|
||||
|
||||
scrollToTheTop()
|
||||
if (activity.settings().useNewTabTray) {
|
||||
showTabTray()
|
||||
} else {
|
||||
scrollToTheTop()
|
||||
}
|
||||
|
||||
metrics.track(Event.CollectionAllTabsRestored)
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ class DefaultSessionControlControllerTest {
|
|||
private val invokePendingDeleteJobs: () -> Unit = mockk(relaxed = true)
|
||||
private val registerCollectionStorageObserver: () -> Unit = mockk(relaxed = true)
|
||||
private val scrollToTheTop: () -> Unit = mockk(relaxed = true)
|
||||
private val showTabTray: () -> Unit = mockk(relaxed = true)
|
||||
private val showDeleteCollectionPrompt: (tabCollection: TabCollection) -> Unit =
|
||||
mockk(relaxed = true)
|
||||
private val metrics: MetricController = mockk(relaxed = true)
|
||||
|
@ -100,7 +101,8 @@ class DefaultSessionControlControllerTest {
|
|||
openSettingsScreen = openSettingsScreen,
|
||||
openSearchScreen = openSearchScreen,
|
||||
openWhatsNewLink = openWhatsNewLink,
|
||||
openPrivacyNotice = openPrivacyNotice
|
||||
openPrivacyNotice = openPrivacyNotice,
|
||||
showTabTray = showTabTray
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue