For #23808 - Add secret setting for enabling Task Continuity feature

upstream-sync
Noah Bond 2 years ago committed by mergify[bot]
parent 5153cee0e0
commit 15c58b7261

@ -53,5 +53,11 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
isChecked = context.settings().nimbusUsePreview isChecked = context.settings().nimbusUsePreview
onPreferenceChangeListener = SharedPreferenceUpdater() onPreferenceChangeListener = SharedPreferenceUpdater()
} }
requirePreference<SwitchPreference>(R.string.pref_key_enable_task_continuity).apply {
isVisible = true
isChecked = context.settings().enableTaskContinuityEnhancements
onPreferenceChangeListener = SharedPreferenceUpdater()
}
} }
} }

@ -6,14 +6,15 @@ package org.mozilla.fenix.tabstray.ext
import mozilla.components.browser.storage.sync.SyncedDeviceTabs import mozilla.components.browser.storage.sync.SyncedDeviceTabs
import mozilla.components.browser.toolbar.MAX_URI_LENGTH import mozilla.components.browser.toolbar.MAX_URI_LENGTH
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.tabstray.syncedtabs.SyncedTabsListItem import org.mozilla.fenix.tabstray.syncedtabs.SyncedTabsListItem
/** /**
* Converts a list of [SyncedDeviceTabs] into a list of [SyncedTabsListItem]. * Converts a list of [SyncedDeviceTabs] into a list of [SyncedTabsListItem].
*/ */
fun List<SyncedDeviceTabs>.toComposeList(): List<SyncedTabsListItem> = asSequence().flatMap { (device, tabs) -> fun List<SyncedDeviceTabs>.toComposeList(
if (FeatureFlags.taskContinuityFeature) { taskContinuityEnabled: Boolean,
): List<SyncedTabsListItem> = asSequence().flatMap { (device, tabs) ->
if (taskContinuityEnabled) {
val deviceTabs = if (tabs.isEmpty()) { val deviceTabs = if (tabs.isEmpty()) {
emptyList() emptyList()
} else { } else {

@ -48,7 +48,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import mozilla.components.browser.storage.sync.TabEntry import mozilla.components.browser.storage.sync.TabEntry
import mozilla.components.feature.syncedtabs.view.SyncedTabsView import mozilla.components.feature.syncedtabs.view.SyncedTabsView
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.compose.PrimaryText import org.mozilla.fenix.compose.PrimaryText
import org.mozilla.fenix.compose.SecondaryText import org.mozilla.fenix.compose.SecondaryText
@ -63,14 +62,18 @@ import mozilla.components.browser.storage.sync.Tab as SyncTab
*/ */
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun SyncedTabsList(syncedTabs: List<SyncedTabsListItem>, onTabClick: (SyncTab) -> Unit) { fun SyncedTabsList(
syncedTabs: List<SyncedTabsListItem>,
taskContinuityEnabled: Boolean,
onTabClick: (SyncTab) -> Unit,
) {
val listState = rememberLazyListState() val listState = rememberLazyListState()
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
state = listState, state = listState,
) { ) {
if (FeatureFlags.taskContinuityFeature) { if (taskContinuityEnabled) {
syncedTabs.forEach { syncedTabItem -> syncedTabs.forEach { syncedTabItem ->
when (syncedTabItem) { when (syncedTabItem) {
is SyncedTabsListItem.DeviceSection -> { is SyncedTabsListItem.DeviceSection -> {
@ -341,7 +344,8 @@ private fun SyncedTabsListPreview() {
FirefoxTheme { FirefoxTheme {
Box(Modifier.background(FirefoxTheme.colors.layer1)) { Box(Modifier.background(FirefoxTheme.colors.layer1)) {
SyncedTabsList( SyncedTabsList(
getFakeSyncedTabList(), syncedTabs = getFakeSyncedTabList(),
taskContinuityEnabled = true,
) { ) {
println("Tab clicked") println("Tab clicked")
} }

@ -17,6 +17,7 @@ import mozilla.components.support.base.observer.Observable
import mozilla.components.support.base.observer.ObserverRegistry import mozilla.components.support.base.observer.ObserverRegistry
import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.tabstray.FloatingActionButtonBinding import org.mozilla.fenix.tabstray.FloatingActionButtonBinding
import org.mozilla.fenix.tabstray.TabsTrayAction import org.mozilla.fenix.tabstray.TabsTrayAction
import org.mozilla.fenix.tabstray.TabsTrayStore import org.mozilla.fenix.tabstray.TabsTrayStore
@ -90,7 +91,13 @@ class SyncedTabsIntegration(
} }
override fun displaySyncedTabs(syncedTabs: List<SyncedDeviceTabs>) { override fun displaySyncedTabs(syncedTabs: List<SyncedDeviceTabs>) {
store.dispatch(TabsTrayAction.UpdateSyncedTabs(syncedTabs.toComposeList())) store.dispatch(
TabsTrayAction.UpdateSyncedTabs(
syncedTabs.toComposeList(
context.settings().enableTaskContinuityEnhancements
)
)
)
} }
/** /**

@ -8,6 +8,7 @@ import android.view.View
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import mozilla.components.lib.state.ext.observeAsComposableState import mozilla.components.lib.state.ext.observeAsComposableState
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.tabstray.NavigationInteractor import org.mozilla.fenix.tabstray.NavigationInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.TabsTrayState import org.mozilla.fenix.tabstray.TabsTrayState
@ -33,7 +34,8 @@ class SyncedTabsPageViewHolder(
FirefoxTheme { FirefoxTheme {
SyncedTabsList( SyncedTabsList(
syncedTabs = tabs ?: emptyList(), syncedTabs = tabs ?: emptyList(),
onTabClick = navigationInteractor::onSyncedTabClicked taskContinuityEnabled = composeView.context.settings().enableTaskContinuityEnhancements,
onTabClick = navigationInteractor::onSyncedTabClicked,
) )
} }
} }

@ -1299,4 +1299,13 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = false, default = false,
featureFlag = FeatureFlags.contileFeature, featureFlag = FeatureFlags.contileFeature,
) )
/**
* Indicates if the Task Continuity enhancements are enabled.
*/
var enableTaskContinuityEnhancements by featureFlagPreference(
key = appContext.getPreferenceKey(R.string.pref_key_enable_task_continuity),
default = false,
featureFlag = FeatureFlags.taskContinuityFeature,
)
} }

@ -204,6 +204,8 @@
<string name="pref_key_enable_top_frecent_sites" translatable="false">pref_key_top_frecent_sites</string> <string name="pref_key_enable_top_frecent_sites" translatable="false">pref_key_top_frecent_sites</string>
<!-- Whether or not the sponsored shortcuts are shown along with the top recent sites shortcuts --> <!-- Whether or not the sponsored shortcuts are shown along with the top recent sites shortcuts -->
<string name="pref_key_enable_contile" translatable="false">pref_key_enable_contile</string> <string name="pref_key_enable_contile" translatable="false">pref_key_enable_contile</string>
<!-- Whether or not the Task Continuity enhancements are shown -->
<string name="pref_key_enable_task_continuity" translatable="false">pref_key_enable_task_continuity</string>
<!-- A value of `true` means the PWA dialog has been showed or user already has PWAs installed --> <!-- A value of `true` means the PWA dialog has been showed or user already has PWAs installed -->
<string name="pref_key_user_knows_about_pwa" translatable="false">pref_key_user_knows_about_pwa</string> <string name="pref_key_user_knows_about_pwa" translatable="false">pref_key_user_knows_about_pwa</string>

@ -43,6 +43,8 @@
<string name="preferences_nimbus_experiments">Nimbus Experiments</string> <string name="preferences_nimbus_experiments">Nimbus Experiments</string>
<!-- Label for using the nimbus collections preview --> <!-- Label for using the nimbus collections preview -->
<string name="preferences_nimbus_use_preview_collection">Use Nimbus Preview Collection (requires restart)</string> <string name="preferences_nimbus_use_preview_collection">Use Nimbus Preview Collection (requires restart)</string>
<!-- Label for enabling the Task Continuity feature -->
<string name="preferences_debug_settings_task_continuity" translatable="false">Enable Task Continuity</string>
<!-- A secret menu option in the tabs tray for making a tab inactive for testing. --> <!-- A secret menu option in the tabs tray for making a tab inactive for testing. -->
<string name="inactive_tabs_menu_item">Make inactive</string> <string name="inactive_tabs_menu_item">Make inactive</string>

@ -25,4 +25,9 @@
android:key="@string/pref_key_nimbus_use_preview" android:key="@string/pref_key_nimbus_use_preview"
android:title="@string/preferences_nimbus_use_preview_collection" android:title="@string/preferences_nimbus_use_preview_collection"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_enable_task_continuity"
android:title="@string/preferences_debug_settings_task_continuity"
app:iconSpaceReserved="false" />
</PreferenceScreen> </PreferenceScreen>

@ -82,7 +82,7 @@ class SyncedDeviceTabsTest {
@Test @Test
fun `GIVEN two synced devices WHEN the compose list is generated THEN two device section is returned`() { fun `GIVEN two synced devices WHEN the compose list is generated THEN two device section is returned`() {
val syncedDeviceList = listOf(oneTabDevice, twoTabDevice) val syncedDeviceList = listOf(oneTabDevice, twoTabDevice)
val listData = syncedDeviceList.toComposeList() val listData = syncedDeviceList.toComposeList(taskContinuityEnabled = true)
assertEquals(2, listData.count()) assertEquals(2, listData.count())
assertTrue(listData[0] is SyncedTabsListItem.DeviceSection) assertTrue(listData[0] is SyncedTabsListItem.DeviceSection)
@ -94,7 +94,7 @@ class SyncedDeviceTabsTest {
@Test @Test
fun `GIVEN one synced device with no tabs WHEN the compose list is generated THEN one device with an empty tabs list is returned`() { fun `GIVEN one synced device with no tabs WHEN the compose list is generated THEN one device with an empty tabs list is returned`() {
val syncedDeviceList = listOf(noTabDevice) val syncedDeviceList = listOf(noTabDevice)
val listData = syncedDeviceList.toComposeList() val listData = syncedDeviceList.toComposeList(taskContinuityEnabled = true)
assertEquals(1, listData.count()) assertEquals(1, listData.count())
assertTrue(listData[0] is SyncedTabsListItem.DeviceSection) assertTrue(listData[0] is SyncedTabsListItem.DeviceSection)

Loading…
Cancel
Save