diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 228ae7fd28e8..1e3374658302 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -58,4 +58,9 @@ object FeatureFlags { * Enables showing the home screen behind the search dialog */ val showHomeBehindSearch = Config.channel.isNightlyOrDebug + + /** + * Enables customizing the home screen + */ + val customizeHome = Config.channel.isNightlyOrDebug } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt index aec201d844a4..3abc0642a261 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt @@ -221,6 +221,10 @@ class DefaultBrowserToolbarMenuController( val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment() navController.nav(R.id.browserFragment, directions) } + is ToolbarMenu.Item.CustomizeHome -> browserAnimator.captureEngineViewAndDrawStatically { + val directions = BrowserFragmentDirections.actionBrowserFragmentToCustomFragment() + navController.nav(R.id.browserFragment, directions) + } is ToolbarMenu.Item.SyncAccount -> { val directions = when (item.accountState) { AccountState.AUTHENTICATED -> @@ -384,6 +388,7 @@ class DefaultBrowserToolbarMenuController( is ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP is ToolbarMenu.Item.Share -> Event.BrowserMenuItemTapped.Item.SHARE is ToolbarMenu.Item.Settings -> Event.BrowserMenuItemTapped.Item.SETTINGS + is ToolbarMenu.Item.CustomizeHome -> return is ToolbarMenu.Item.RequestDesktop -> if (item.isChecked) { Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_ON diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt index 01e6c28b3373..cc7a90e27f4e 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt @@ -34,6 +34,7 @@ import mozilla.components.feature.webcompat.reporter.WebCompatReporterFeature import mozilla.components.lib.state.ext.flowScoped import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.accounts.FenixAccountManager import org.mozilla.fenix.experiments.ExperimentBranch @@ -308,6 +309,14 @@ open class DefaultToolbarMenu( onItemTapped.invoke(ToolbarMenu.Item.Settings) } + val customizeHomeItem = BrowserMenuImageText( + label = context.getString(R.string.browser_menu_customize_home), + imageResource = R.drawable.ic_customize, + iconTintColorResource = primaryTextColor() + ) { + onItemTapped.invoke(ToolbarMenu.Item.CustomizeHome) + } + val bookmarksItem = BrowserMenuImageTextCheckboxButton( imageResource = R.drawable.ic_bookmarks_menu, iconTintColorResource = primaryTextColor(), @@ -372,6 +381,7 @@ open class DefaultToolbarMenu( addToTopSitesItem, saveToCollectionItem, BrowserMenuDivider(), + if (FeatureFlags.customizeHome) customizeHomeItem else null, settingsItem, if (shouldDeleteDataOnQuit) deleteDataOnQuit else null, if (shouldUseBottomToolbar) BrowserMenuDivider() else null, diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt index 8477905b998b..898744839b1b 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt @@ -34,6 +34,7 @@ interface ToolbarMenu { object History : Item() object Downloads : Item() object NewTab : Item() + object CustomizeHome : Item() } val menuBuilder: BrowserMenuBuilder diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index fbe49c5b532e..14d323d49398 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -853,6 +853,13 @@ class HomeFragment : Fragment() { ) requireComponents.analytics.metrics.track(Event.HomeMenuSettingsItemClicked) } + HomeMenu.Item.CustomizeHome -> { + hideOnboardingIfNeeded() + nav( + R.id.homeFragment, + HomeFragmentDirections.actionGlobalCustomizationFragment() + ) + } is HomeMenu.Item.SyncAccount -> { hideOnboardingIfNeeded() val directions = when (it.accountState) { diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 9c368ee423df..d63618e43f56 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -23,6 +23,7 @@ import mozilla.components.concept.sync.AccountObserver import mozilla.components.concept.sync.AuthType import mozilla.components.concept.sync.OAuthAccount import mozilla.components.support.ktx.android.content.getColorFromAttr +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.accounts.AccountState import org.mozilla.fenix.components.accounts.FenixAccountManager @@ -49,6 +50,7 @@ class HomeMenu( data class SyncAccount(val accountState: AccountState) : Item() object WhatsNew : Item() object Help : Item() + object CustomizeHome : Item() object Settings : Item() object Quit : Item() object ReconnectSync : Item() @@ -167,6 +169,14 @@ class HomeMenu( onItemTapped.invoke(Item.Help) } + val customizeHomeItem = BrowserMenuImageText( + context.getString(R.string.browser_menu_customize_home), + R.drawable.ic_customize, + primaryTextColor + ) { + onItemTapped.invoke(Item.CustomizeHome) + } + // Use nimbus to set the icon and title. val variables = experiments.getVariables(FeatureId.NIMBUS_VALIDATION) val settingsItem = BrowserMenuImageText( @@ -200,6 +210,7 @@ class HomeMenu( BrowserMenuDivider(), whatsNewItem, helpItem, + if (FeatureFlags.customizeHome) customizeHomeItem else null, settingsItem, if (settings.shouldDeleteBrowsingDataOnQuit) quitItem else null ).also { items -> diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index d29b594d0c16..034501146855 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -57,6 +57,9 @@ + @@ -199,6 +202,9 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 02848fb22053..53d30b8a10f8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,7 +194,8 @@ Add Edit - + + Customize home Home screen diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt index de3e419c8fcc..4b5a70364c9a 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt @@ -337,6 +337,18 @@ class DefaultBrowserToolbarMenuControllerTest { verify { navController.navigate(directions, null) } } + @Test + fun `WHEN CustomizeHome menu item is pressed THEN menu item is handled`() = runBlockingTest { + val item = ToolbarMenu.Item.CustomizeHome + + val controller = createController(scope = this, store = browserStore) + controller.handleToolbarItemInteraction(item) + + val directions = BrowserFragmentDirections.actionBrowserFragmentToCustomFragment() + + verify { navController.navigate(directions, null) } + } + @Test fun `WHEN bookmark menu item is pressed THEN navigate to bookmarks page`() = runBlockingTest { val item = ToolbarMenu.Item.Bookmarks