From d0f75706c0e35d153f1efb9c2a25180b91f6c141 Mon Sep 17 00:00:00 2001 From: Noah Bond Date: Tue, 15 Aug 2023 08:24:50 -0700 Subject: [PATCH] Bug 1848377 - Add secret setting to control the visibility of the Shopping feature --- .../mozilla/fenix/browser/BrowserFragment.kt | 4 ++++ .../fenix/settings/SecretSettingsFragment.kt | 6 ++++++ .../shopping/ReviewQualityCheckFeature.kt | 2 +- .../shopping/ShoppingExperienceFeature.kt | 20 +++++++++++++++---- .../java/org/mozilla/fenix/utils/Settings.kt | 8 ++++++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/static_strings.xml | 2 ++ .../res/xml/secret_settings_preferences.xml | 5 +++++ 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index c28942274c..8f9c59803d 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -50,6 +50,7 @@ import org.mozilla.fenix.ext.settings import org.mozilla.fenix.nimbus.FxNimbus import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialog.CookieBannerReEngagementDialogUtils import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.getCookieBannerUIMode +import org.mozilla.fenix.shopping.DefaultShoppingExperienceFeature import org.mozilla.fenix.shopping.ReviewQualityCheckFeature import org.mozilla.fenix.shortcut.PwaOnboardingObserver import org.mozilla.fenix.theme.ThemeManager @@ -226,6 +227,9 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { reviewQualityCheckFeature.set( feature = ReviewQualityCheckFeature( browserStore = context.components.core.store, + shoppingExperienceFeature = DefaultShoppingExperienceFeature( + settings = requireContext().settings(), + ), onAvailabilityChange = { reviewQualityCheckAvailable = it }, ), owner = this, diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index 8570984bd7..56b9ce54b7 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -64,6 +64,12 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { onPreferenceChangeListener = SharedPreferenceUpdater() } + requirePreference(R.string.pref_key_enable_shopping_experience).apply { + isVisible = Config.channel.isNightlyOrDebug + isChecked = context.settings().enableShoppingExperience + onPreferenceChangeListener = SharedPreferenceUpdater() + } + // for performance reasons, this is only available in Nightly or Debug builds requirePreference(R.string.pref_key_custom_glean_server_url).apply { isVisible = Config.channel.isNightlyOrDebug && BuildConfig.GLEAN_CUSTOM_URL.isNullOrEmpty() diff --git a/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt b/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt index 0b3022c89a..402e8efeb6 100644 --- a/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt +++ b/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt @@ -25,7 +25,7 @@ import mozilla.components.support.base.feature.LifecycleAwareFeature */ class ReviewQualityCheckFeature( private val browserStore: BrowserStore, - private val shoppingExperienceFeature: ShoppingExperienceFeature = ShoppingExperienceFeature(), + private val shoppingExperienceFeature: ShoppingExperienceFeature, private val onAvailabilityChange: (isAvailable: Boolean) -> Unit, ) : LifecycleAwareFeature { private var scope: CoroutineScope? = null diff --git a/app/src/main/java/org/mozilla/fenix/shopping/ShoppingExperienceFeature.kt b/app/src/main/java/org/mozilla/fenix/shopping/ShoppingExperienceFeature.kt index d024204234..b0780dd8c0 100644 --- a/app/src/main/java/org/mozilla/fenix/shopping/ShoppingExperienceFeature.kt +++ b/app/src/main/java/org/mozilla/fenix/shopping/ShoppingExperienceFeature.kt @@ -4,16 +4,28 @@ package org.mozilla.fenix.shopping -import org.mozilla.fenix.nimbus.FxNimbus +import org.mozilla.fenix.utils.Settings /** * An abstraction for shopping experience feature flag. */ -class ShoppingExperienceFeature { +interface ShoppingExperienceFeature { /** * Returns true if the shopping experience feature is enabled. */ - val isEnabled - get() = FxNimbus.features.shoppingExperience.value().enabled + val isEnabled: Boolean +} + +/** + * The default implementation of [ShoppingExperienceFeature]. + * + * @property settings Used to check if the feature is enabled. + */ +class DefaultShoppingExperienceFeature( + private val settings: Settings, +) : ShoppingExperienceFeature { + + override val isEnabled + get() = settings.enableShoppingExperience } 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 06d55084f8..5cb74bed71 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -1789,6 +1789,14 @@ class Settings(private val appContext: Context) : PreferencesHolder { default = FeatureFlags.composeTopSites, ) + /** + * Indicates if the shopping experience feature is enabled. + */ + val enableShoppingExperience by booleanPreference( + key = appContext.getPreferenceKey(R.string.pref_key_enable_shopping_experience), + default = FxNimbus.features.shoppingExperience.value().enabled, + ) + /** * Adjust Activated User sent */ diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index a16d17da38..a4a0b846fd 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -350,6 +350,7 @@ pref_key_custom_sponsored_stories_country pref_key_custom_sponsored_stories_city pref_key_enable_compose_top_sites + pref_key_enable_shopping_experience pref_key_growth_set_as_default diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index 0df13bbe4a..24759128ed 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -66,6 +66,8 @@ Enable Tabs Tray to Compose rewrite Enable Compose Top Sites + + Enable Shopping Experience Make inactive diff --git a/app/src/main/res/xml/secret_settings_preferences.xml b/app/src/main/res/xml/secret_settings_preferences.xml index 9c663362da..3360c80dbb 100644 --- a/app/src/main/res/xml/secret_settings_preferences.xml +++ b/app/src/main/res/xml/secret_settings_preferences.xml @@ -30,6 +30,11 @@ android:key="@string/pref_key_enable_compose_top_sites" android:title="@string/preferences_debug_settings_compose_top_sites" app:iconSpaceReserved="false" /> +