From 6ffb3f3a5f8dbf517b0949ba712827060bfe259b Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Mon, 30 Aug 2021 19:33:59 -0400 Subject: [PATCH] For #21095 allow users to configure their home screen. --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 ++++ .../toolbar/BrowserToolbarMenuController.kt | 5 ++++ .../components/toolbar/DefaultToolbarMenu.kt | 10 ++++++++ .../fenix/components/toolbar/ToolbarMenu.kt | 1 + .../org/mozilla/fenix/home/HomeFragment.kt | 13 +++++++--- .../java/org/mozilla/fenix/home/HomeMenu.kt | 11 +++++++++ .../fenix/settings/CustomizationFragment.kt | 24 +++++++++++++++++++ .../java/org/mozilla/fenix/utils/Settings.kt | 20 ++++++++++++++++ .../main/res/layout/fragment_add_login.xml | 6 ++--- app/src/main/res/navigation/nav_graph.xml | 6 +++++ app/src/main/res/values/preference_keys.xml | 2 ++ app/src/main/res/values/strings.xml | 17 +++++++++++-- .../res/xml/customization_preferences.xml | 22 ++++++++++++++++- ...DefaultBrowserToolbarMenuControllerTest.kt | 12 ++++++++++ 14 files changed, 145 insertions(+), 9 deletions(-) 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 9b36994071ea..a8993a9bf230 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 @@ -35,6 +35,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 @@ -319,6 +320,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(), @@ -389,6 +398,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 007cb262ada1..0ac1e002f8f2 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -257,7 +257,7 @@ class HomeFragment : Fragment() { view = binding.root ) - if (FeatureFlags.showRecentTabsFeature) { + if (requireContext().settings().showRecentTabsFeature) { recentTabsListFeature.set( feature = RecentTabsListFeature( browserStore = components.core.store, @@ -268,7 +268,7 @@ class HomeFragment : Fragment() { ) } - if (FeatureFlags.recentBookmarksFeature) { + if (requireContext().settings().showRecentBookmarksFeature) { recentBookmarksFeature.set( feature = RecentBookmarksFeature( homeStore = homeFragmentStore, @@ -854,7 +854,7 @@ class HomeFragment : Fragment() { requireComponents.analytics.metrics.track(Event.HomeMenuSettingsItemClicked) } /* Gexsi begin: disable sync account - is HomeMenu.Item.SyncAccount -> { + HomeMenu.Item.SyncAccount -> { hideOnboardingIfNeeded() val directions = when (it.accountState) { AccountState.AUTHENTICATED -> @@ -870,6 +870,13 @@ class HomeFragment : Fragment() { ) } */ + HomeMenu.Item.CustomizeHome -> { + hideOnboardingIfNeeded() + nav( + R.id.homeFragment, + HomeFragmentDirections.actionGlobalCustomizationFragment() + ) + } HomeMenu.Item.Bookmarks -> { hideOnboardingIfNeeded() nav( 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 8af4f3cdc44f..52b5dfbeb28a 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 @@ -51,6 +52,7 @@ class HomeMenu( */ object WhatsNew : Item() object Help : Item() + object CustomizeHome : Item() object Settings : Item() object Quit : Item() /* Gexsi begin: disable sync @@ -180,6 +182,14 @@ class HomeMenu( } */ + 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( @@ -219,6 +229,7 @@ class HomeMenu( /* Gexsi begin: helpItem, */ + if (FeatureFlags.customizeHome) customizeHomeItem else null, settingsItem, if (settings.shouldDeleteBrowsingDataOnQuit) quitItem else null ).also { items -> diff --git a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt index 135eab05f033..483fa19b4b50 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -144,6 +144,30 @@ class CustomizationFragment : PreferenceFragmentCompat() { isChecked = context.settings().showTopFrecentSites onPreferenceChangeListener = SharedPreferenceUpdater() } + + requirePreference(R.string.pref_key_recent_tabs).apply { + isVisible = FeatureFlags.showRecentTabsFeature + isChecked = context.settings().showRecentTabsFeature + onPreferenceChangeListener = SharedPreferenceUpdater() + } + + requirePreference(R.string.pref_key_recent_bookmarks).apply { + isVisible = FeatureFlags.recentBookmarksFeature + isChecked = context.settings().showRecentBookmarksFeature + onPreferenceChangeListener = SharedPreferenceUpdater() + } + + requirePreference(R.string.pref_key_pocket_homescreen_recommendations).apply { + isVisible = false + isChecked = context.settings().pocketRecommendations + onPreferenceChangeListener = SharedPreferenceUpdater() + } + + requirePreference(R.string.pref_key_history_metadata_feature).apply { + isVisible = FeatureFlags.historyMetadataUIFeature + isChecked = context.settings().historyMetadataUIFeature + onPreferenceChangeListener = SharedPreferenceUpdater() + } } private fun setupGesturesCategory() { diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 6343ca88256e..4c37c88407a3 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -1114,6 +1114,26 @@ class Settings(private val appContext: Context) : PreferencesHolder { featureFlag = FeatureFlags.historyMetadataUIFeature || isHistoryMetadataEnabled ) + /** + * Indicates if the recent tabs functionality should be visible. + * Returns true if the [FeatureFlags.showRecentTabsFeature] and [R.string.pref_key_recent_tabs] are true. + */ + var showRecentTabsFeature by featureFlagPreference( + appContext.getPreferenceKey(R.string.pref_key_recent_tabs), + default = FeatureFlags.showRecentTabsFeature, + featureFlag = FeatureFlags.showRecentTabsFeature + ) + + /** + * Indicates if the recent saved bookmarks functionality should be visible. + * Returns true if the [FeatureFlags.showRecentTabsFeature] and [R.string.pref_key_recent_bookmarks] are true. + */ + var showRecentBookmarksFeature by featureFlagPreference( + appContext.getPreferenceKey(R.string.pref_key_recent_bookmarks), + default = FeatureFlags.recentBookmarksFeature, + featureFlag = FeatureFlags.recentBookmarksFeature + ) + /** * Storing desktop item checkbox value in the home screen menu. * If set to true, next opened tab from home screen will be opened in desktop mode. diff --git a/app/src/main/res/layout/fragment_add_login.xml b/app/src/main/res/layout/fragment_add_login.xml index cf7dfb9ee6e2..af5f2f6085f3 100644 --- a/app/src/main/res/layout/fragment_add_login.xml +++ b/app/src/main/res/layout/fragment_add_login.xml @@ -27,7 +27,7 @@ android:textColor="?primaryText" android:textSize="12sp" android:letterSpacing="0.05" - app:fontFamily="@font/metropolis_semibold" + app:fontFamily="@font/roboto_bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -98,7 +98,7 @@ android:textColor="?primaryText" android:textSize="12sp" android:letterSpacing="0.05" - app:fontFamily="@font/metropolis_semibold" + app:fontFamily="@font/roboto_bold" app:layout_constraintBottom_toTopOf="@id/inputLayoutUsername" app:layout_constraintEnd_toStartOf="@id/clearUsernameTextButton" app:layout_constraintStart_toStartOf="parent" @@ -169,7 +169,7 @@ android:text="@string/preferences_passwords_saved_logins_password" android:textColor="?primaryText" android:textSize="12sp" - app:fontFamily="@font/metropolis_semibold" + app:fontFamily="@font/roboto_bold" app:layout_constraintBottom_toTopOf="@id/inputLayoutPassword" app:layout_constraintEnd_toStartOf="@+id/clearPasswordTextButton" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index a123a0fc3259..b1c16124a051 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/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index a59757d5be85..e204a2bc2626 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -147,6 +147,8 @@ pref_key_dynamic_toolbar pref_key_swipe_toolbar_switch_tabs pref_key_swipe_toolbar_show_tabs + pref_key_recent_tabs + pref_key_recent_bookmarks pref_key_etp_learn_more diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8dab67b71dee..3fa0faf729cd 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 @@ -382,6 +383,16 @@ Add-on collection modified. Quitting the application to apply changes… + + + Jump back in + + Recently saved + + Recently visited + + Pocket + Add-on is not supported @@ -1818,8 +1829,10 @@ To add a new top site, remove one. Touch and hold the site and select remove. OK, Got It + + Show most visited top sites - Show most visited sites + Show most visited sites Name diff --git a/app/src/main/res/xml/customization_preferences.xml b/app/src/main/res/xml/customization_preferences.xml index 2b5a2bb3bf89..7e6315eac256 100644 --- a/app/src/main/res/xml/customization_preferences.xml +++ b/app/src/main/res/xml/customization_preferences.xml @@ -49,7 +49,27 @@ app:iconSpaceReserved="false"> + android:title="@string/top_sites_toggle_top_frecent_sites_2" /> + + + + + + + +