|
|
|
@ -8,6 +8,7 @@ import android.content.Context
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.Gravity
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
@ -26,6 +27,7 @@ import mozilla.appservices.places.BookmarkRoot
|
|
|
|
|
import mozilla.components.browser.state.selector.normalTabs
|
|
|
|
|
import mozilla.components.browser.state.selector.privateTabs
|
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
|
import mozilla.components.feature.downloads.ui.DownloadCancelDialogFragment
|
|
|
|
|
import mozilla.components.feature.tabs.tabstray.TabsFeature
|
|
|
|
|
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
|
|
|
@ -58,6 +60,7 @@ import org.mozilla.fenix.tabstray.ext.collectionMessage
|
|
|
|
|
import org.mozilla.fenix.tabstray.ext.make
|
|
|
|
|
import org.mozilla.fenix.tabstray.ext.orDefault
|
|
|
|
|
import org.mozilla.fenix.tabstray.ext.showWithTheme
|
|
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
|
|
|
|
import org.mozilla.fenix.utils.allowUndo
|
|
|
|
|
import kotlin.math.max
|
|
|
|
|
|
|
|
|
@ -67,6 +70,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
private lateinit var browserTrayInteractor: BrowserTrayInteractor
|
|
|
|
|
private lateinit var tabsTrayInteractor: TabsTrayInteractor
|
|
|
|
|
private lateinit var tabsTrayController: DefaultTabsTrayController
|
|
|
|
|
private lateinit var navigationInteractor: DefaultNavigationInteractor
|
|
|
|
|
@VisibleForTesting internal lateinit var trayBehaviorManager: TabSheetBehaviorManager
|
|
|
|
|
|
|
|
|
|
private val tabLayoutMediator = ViewBoundFeatureWrapper<TabLayoutMediator>()
|
|
|
|
@ -142,6 +146,13 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
return tabsTrayDialogBinding.root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStart() {
|
|
|
|
|
super.onStart()
|
|
|
|
|
findPreviousDialogFragment()?.let { dialog ->
|
|
|
|
|
dialog.onAcceptClicked = ::onCancelDownloadWarningAccepted
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDestroyView() {
|
|
|
|
|
super.onDestroyView()
|
|
|
|
|
_tabsTrayBinding = null
|
|
|
|
@ -160,7 +171,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
}
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.TabsTrayOpened)
|
|
|
|
|
|
|
|
|
|
val navigationInteractor =
|
|
|
|
|
navigationInteractor =
|
|
|
|
|
DefaultNavigationInteractor(
|
|
|
|
|
context = requireContext(),
|
|
|
|
|
activity = activity,
|
|
|
|
@ -174,6 +185,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
collectionStorage = requireComponents.core.tabCollectionStorage,
|
|
|
|
|
showCollectionSnackbar = ::showCollectionSnackbar,
|
|
|
|
|
showBookmarkSnackbar = ::showBookmarkSnackbar,
|
|
|
|
|
showCancelledDownloadWarning = ::showCancelledDownloadWarning,
|
|
|
|
|
accountManager = requireComponents.backgroundServices.accountManager,
|
|
|
|
|
ioDispatcher = Dispatchers.IO
|
|
|
|
|
)
|
|
|
|
@ -190,7 +202,8 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
tabsUseCases = requireComponents.useCases.tabsUseCases,
|
|
|
|
|
selectTabPosition = ::selectTabPosition,
|
|
|
|
|
dismissTray = ::dismissTabsTray,
|
|
|
|
|
showUndoSnackbarForTab = ::showUndoSnackbarForTab
|
|
|
|
|
showUndoSnackbarForTab = ::showUndoSnackbarForTab,
|
|
|
|
|
showCancelledDownloadWarning = ::showCancelledDownloadWarning
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
tabsTrayInteractor = DefaultTabsTrayInteractor(tabsTrayController)
|
|
|
|
@ -371,6 +384,40 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
internal fun onCancelDownloadWarningAccepted(tabId: String?, source: String?) {
|
|
|
|
|
if (tabId != null) {
|
|
|
|
|
tabsTrayInteractor.onDeletePrivateTabWarningAccepted(tabId, source)
|
|
|
|
|
} else {
|
|
|
|
|
navigationInteractor.onCloseAllPrivateTabsWarningConfirmed(private = true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
internal fun showCancelledDownloadWarning(downloadCount: Int, tabId: String?, source: String?) {
|
|
|
|
|
val dialog = DownloadCancelDialogFragment.newInstance(
|
|
|
|
|
downloadCount = downloadCount,
|
|
|
|
|
tabId = tabId,
|
|
|
|
|
source = source,
|
|
|
|
|
promptStyling = DownloadCancelDialogFragment.PromptStyling(
|
|
|
|
|
gravity = Gravity.BOTTOM,
|
|
|
|
|
shouldWidthMatchParent = true,
|
|
|
|
|
positiveButtonBackgroundColor = ThemeManager.resolveAttribute(
|
|
|
|
|
R.attr.accent,
|
|
|
|
|
requireContext()
|
|
|
|
|
),
|
|
|
|
|
positiveButtonTextColor = ThemeManager.resolveAttribute(
|
|
|
|
|
R.attr.contrastText,
|
|
|
|
|
requireContext()
|
|
|
|
|
),
|
|
|
|
|
positiveButtonRadius = (resources.getDimensionPixelSize(R.dimen.tab_corner_radius)).toFloat()
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
onPositiveButtonClicked = ::onCancelDownloadWarningAccepted
|
|
|
|
|
)
|
|
|
|
|
dialog.show(parentFragmentManager, DOWNLOAD_CANCEL_DIALOG_FRAGMENT_TAG)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
internal fun showUndoSnackbarForTab(isPrivate: Boolean) {
|
|
|
|
|
val snackbarMessage =
|
|
|
|
@ -518,6 +565,11 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Suppress("MaxLineLength")
|
|
|
|
|
private fun findPreviousDialogFragment(): DownloadCancelDialogFragment? {
|
|
|
|
|
return parentFragmentManager.findFragmentByTag(DOWNLOAD_CANCEL_DIALOG_FRAGMENT_TAG) as? DownloadCancelDialogFragment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getSnackbarAnchor(): View? {
|
|
|
|
|
return if (requireComponents.settings.accessibilityServicesEnabled) {
|
|
|
|
|
null
|
|
|
|
@ -527,6 +579,8 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
private const val DOWNLOAD_CANCEL_DIALOG_FRAGMENT_TAG = "DOWNLOAD_CANCEL_DIALOG_FRAGMENT_TAG"
|
|
|
|
|
|
|
|
|
|
// Minimum number of list items for which to show the tabs tray as expanded.
|
|
|
|
|
const val EXPAND_AT_LIST_SIZE = 4
|
|
|
|
|
|
|
|
|
|