Bug 1814986 - Create the logic fork for the Tabs Tray to Compose rewrite

fenix/112.0
Noah Bond 2 years ago committed by mergify[bot]
parent 61349926a8
commit 1f72ce51d3

@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tabstray
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.theme.FirefoxTheme
/**
* Top-level UI for displaying the Tabs Tray feature.
*/
@Composable
fun TabsTray() {
Box(
modifier = Modifier.fillMaxSize()
.background(FirefoxTheme.colors.layer1),
) {
Text(
text = "Tabs Tray to Compose",
color = FirefoxTheme.colors.textPrimary,
style = FirefoxTheme.typography.body1,
)
}
}
@LightDarkPreview
@Composable
private fun TabsTrayPreview() {
FirefoxTheme {
TabsTray()
}
}

@ -14,6 +14,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.setFragmentResultListener
@ -59,6 +60,7 @@ import org.mozilla.fenix.tabstray.ext.collectionMessage
import org.mozilla.fenix.tabstray.ext.make
import org.mozilla.fenix.tabstray.ext.showWithTheme
import org.mozilla.fenix.tabstray.syncedtabs.SyncedTabsIntegration
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.allowUndo
import kotlin.math.max
@ -115,27 +117,12 @@ class TabsTrayFragment : AppCompatDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?) =
TabsTrayDialog(requireContext(), theme) { tabsTrayInteractor }
@Suppress("LongMethod")
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_tabsTrayDialogBinding = FragmentTabTrayDialogBinding.inflate(
inflater,
container,
false,
)
_tabsTrayBinding = ComponentTabstray2Binding.inflate(
inflater,
tabsTrayDialogBinding.root,
true,
)
_fabButtonBinding = ComponentTabstrayFabBinding.inflate(
LayoutInflater.from(tabsTrayDialogBinding.root.context),
tabsTrayDialogBinding.root,
true,
)
val args by navArgs<TabsTrayFragmentArgs>()
args.accessPoint.takeIf { it != TabsTrayAccessPoint.None }?.let {
TabsTray.accessPoint[it.name.lowercase()].add()
@ -146,6 +133,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
TabsTrayState.Mode.Normal
}
val initialPage = args.page
val activity = activity as HomeActivity
tabsTrayStore = StoreProvider.get(this) {
TabsTrayStore(
@ -159,34 +147,6 @@ class TabsTrayFragment : AppCompatDialogFragment() {
)
}
return tabsTrayDialogBinding.root
}
override fun onStart() {
super.onStart()
findPreviousDialogFragment()?.let { dialog ->
dialog.onAcceptClicked = ::onCancelDownloadWarningAccepted
}
}
override fun onDestroyView() {
super.onDestroyView()
_tabsTrayBinding = null
_tabsTrayDialogBinding = null
_fabButtonBinding = null
}
@Suppress("LongMethod")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val activity = activity as HomeActivity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
fabButtonBinding.newTabButton.accessibilityTraversalAfter =
tabsTrayBinding.tabLayout.id
}
TabsTray.opened.record(NoExtras())
navigationInteractor =
DefaultNavigationInteractor(
context = requireContext(),
@ -226,6 +186,62 @@ class TabsTrayFragment : AppCompatDialogFragment() {
controller = tabsTrayController,
)
return if (requireContext().settings().enableTabsTrayToCompose) {
ComposeView(requireContext()).apply {
setContent {
FirefoxTheme {
TabsTray()
}
}
}
} else {
_tabsTrayDialogBinding = FragmentTabTrayDialogBinding.inflate(
inflater,
container,
false,
)
_tabsTrayBinding = ComponentTabstray2Binding.inflate(
inflater,
tabsTrayDialogBinding.root,
true,
)
_fabButtonBinding = ComponentTabstrayFabBinding.inflate(
LayoutInflater.from(tabsTrayDialogBinding.root.context),
tabsTrayDialogBinding.root,
true,
)
tabsTrayDialogBinding.root
}
}
override fun onStart() {
super.onStart()
findPreviousDialogFragment()?.let { dialog ->
dialog.onAcceptClicked = ::onCancelDownloadWarningAccepted
}
}
override fun onDestroyView() {
super.onDestroyView()
_tabsTrayBinding = null
_tabsTrayDialogBinding = null
_fabButtonBinding = null
}
@Suppress("LongMethod")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
TabsTray.opened.record(NoExtras())
if (!requireContext().settings().enableTabsTrayToCompose) {
val activity = activity as HomeActivity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
fabButtonBinding.newTabButton.accessibilityTraversalAfter =
tabsTrayBinding.tabLayout.id
}
setupMenu(navigationInteractor)
setupPager(
context = view.context,
@ -255,18 +271,6 @@ class TabsTrayFragment : AppCompatDialogFragment() {
displayMetrics = requireContext().resources.displayMetrics,
)
tabsFeature.set(
feature = TabsFeature(
tabsTray = TabSorter(
requireContext().settings(),
tabsTrayStore,
),
store = requireContext().components.core.store,
),
owner = this,
view = view,
)
tabsTrayCtaBinding.set(
feature = TabsTrayInfoBannerBinding(
context = view.context,
@ -353,17 +357,6 @@ class TabsTrayFragment : AppCompatDialogFragment() {
view = view,
)
secureTabsTrayBinding.set(
feature = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = requireComponents.settings,
fragment = this,
dialog = dialog as TabsTrayDialog,
),
owner = this,
view = view,
)
tabsTrayInactiveTabsOnboardingBinding.set(
feature = TabsTrayInactiveTabsOnboardingBinding(
context = requireContext(),
@ -375,6 +368,30 @@ class TabsTrayFragment : AppCompatDialogFragment() {
owner = this,
view = view,
)
}
tabsFeature.set(
feature = TabsFeature(
tabsTray = TabSorter(
requireContext().settings(),
tabsTrayStore,
),
store = requireContext().components.core.store,
),
owner = this,
view = view,
)
secureTabsTrayBinding.set(
feature = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = requireComponents.settings,
fragment = this,
dialog = dialog as TabsTrayDialog,
),
owner = this,
view = view,
)
syncedTabsIntegration.set(
feature = SyncedTabsIntegration(
@ -397,12 +414,14 @@ class TabsTrayFragment : AppCompatDialogFragment() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (!requireContext().settings().enableTabsTrayToCompose) {
trayBehaviorManager.updateDependingOnOrientation(newConfig.orientation)
if (requireContext().settings().gridTabView) {
tabsTrayBinding.tabsTray.adapter?.notifyDataSetChanged()
}
}
}
@VisibleForTesting
internal fun onCancelDownloadWarningAccepted(tabId: String?, source: String?) {

Loading…
Cancel
Save