Skip to content

Commit

Permalink
For mozilla-mobile#8800: clear menu highlights on use
Browse files Browse the repository at this point in the history
  • Loading branch information
severinrudie authored and BranescuMihai committed Mar 2, 2020
1 parent e967326 commit 31b3863
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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

Expand Down Expand Up @@ -160,6 +161,7 @@ class DefaultBrowserToolbarController(
}
}
ToolbarMenu.Item.AddToHomeScreen -> {
activity.settings().installPwaOpened = true
MainScope().launch {
with(activity.components.useCases.webAppUseCases) {
if (isInstallable()) {
Expand Down Expand Up @@ -268,6 +270,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
Expand All @@ -282,6 +286,8 @@ class DefaultBrowserToolbarController(
readerModeController.showControls()
}
ToolbarMenu.Item.OpenInApp -> {
activity.settings().openInAppOpened = true

val appLinksUseCases =
activity.components.useCases.appLinksUseCases
val getRedirect = appLinksUseCases.appLinkRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.ext.asActivity
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.Settings

Expand Down Expand Up @@ -246,7 +247,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)
Expand Down Expand Up @@ -310,7 +313,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))
}
Expand All @@ -331,7 +334,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)
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<string name="pref_key_experimentation" translatable="false">pref_key_experimentation</string>
<string name="pref_key_showed_private_mode_cfr" translatable="false">pref_key_showed_private_mode_cfr</string>
<string name="pref_key_private_mode_opened" translatable="false">pref_key_private_mode_opened</string>
<string name="pref_key_reader_mode_opened" translatable="false">pref_key_reader_mode_opened</string>
<string name="pref_key_open_in_app_opened" translatable="false">pref_key_open_in_app_opened</string>
<string name="pref_key_install_pwa_opened" translatable="false">pref_key_install_pwa_opened</string>

<!-- Data Choices -->
<string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string>
Expand Down

0 comments on commit 31b3863

Please sign in to comment.