From 8e8d01c2db8387ea8267bf1892f262f0bb4e1e37 Mon Sep 17 00:00:00 2001 From: Severin Rudie Date: Wed, 26 Feb 2020 17:04:28 -0800 Subject: [PATCH] For #8800: clear menu highlights on use --- .../toolbar/BrowserToolbarController.kt | 6 ++++++ .../components/toolbar/DefaultToolbarMenu.kt | 9 ++++++--- .../main/java/org/mozilla/fenix/utils/Settings.kt | 15 +++++++++++++++ app/src/main/res/values/preference_keys.xml | 3 +++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index f2161395c1ce..e8f4558dc698 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -43,6 +43,7 @@ import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.getRootView import org.mozilla.fenix.ext.nav +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.lib.Do import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit @@ -157,6 +158,7 @@ class DefaultBrowserToolbarController( } } ToolbarMenu.Item.AddToHomeScreen -> { + activity.settings().installPwaOpened = true MainScope().launch { with(activity.components.useCases.webAppUseCases) { if (isInstallable()) { @@ -265,6 +267,8 @@ class DefaultBrowserToolbarController( deleteAndQuit(activity, scope, snackbar) } is ToolbarMenu.Item.ReaderMode -> { + activity.settings().readerModeOpened = true + val enabled = currentSession?.readerMode ?: activity.components.core.sessionManager.selectedSession?.readerMode ?: false @@ -279,6 +283,8 @@ class DefaultBrowserToolbarController( readerModeController.showControls() } ToolbarMenu.Item.OpenInApp -> { + activity.settings().openInAppOpened = true + val appLinksUseCases = activity.components.useCases.appLinksUseCases val getRedirect = appLinksUseCases.appLinkRedirect 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 5620aeb5d501..c4a7bead5fcd 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 @@ -29,6 +29,7 @@ import org.mozilla.fenix.ReleaseChannel import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.ext.asActivity import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.Settings @@ -245,7 +246,9 @@ class DefaultToolbarMenu( ), isHighlighted = { val webAppUseCases = context.components.useCases.webAppUseCases - webAppUseCases.isPinningSupported() && webAppUseCases.isInstallable() + webAppUseCases.isPinningSupported() && + webAppUseCases.isInstallable() && + !context.settings().installPwaOpened } ) { onItemTapped.invoke(ToolbarMenu.Item.AddToHomeScreen) @@ -309,7 +312,7 @@ class DefaultToolbarMenu( label = context.getString(R.string.browser_menu_read), notificationTint = getColor(context, R.color.whats_new_notification_color) ), - isHighlighted = { true } + isHighlighted = { !context.settings().readerModeOpened } ) { checked -> onItemTapped.invoke(ToolbarMenu.Item.ReaderMode(checked)) } @@ -330,7 +333,7 @@ class DefaultToolbarMenu( label = context.getString(R.string.browser_menu_open_app_link), notificationTint = getColor(context, R.color.whats_new_notification_color) ), - isHighlighted = { true } + isHighlighted = { !context.settings().openInAppOpened } ) { onItemTapped.invoke(ToolbarMenu.Item.OpenInApp) } 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 16d22466594d..c6d7223587db 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -133,6 +133,21 @@ class Settings private constructor( default = "" ) + var readerModeOpened by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_reader_mode_opened), + default = false + ) + + var openInAppOpened by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_open_in_app_opened), + default = false + ) + + var installPwaOpened by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_install_pwa_opened), + default = false + ) + val isCrashReportingEnabled: Boolean get() = isCrashReportEnabledInBuild && preferences.getBoolean( diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 089b061b0721..1b622472f6d7 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -47,6 +47,9 @@ pref_key_experimentation pref_key_showed_private_mode_cfr pref_key_private_mode_opened + pref_key_reader_mode_opened + pref_key_open_in_app_opened + pref_key_install_pwa_opened pref_key_telemetry