From d3e5c2a0024ccde7985ed15183736e6fcdf23dcd Mon Sep 17 00:00:00 2001 From: rahulsainani Date: Tue, 27 Jun 2023 16:07:22 +0200 Subject: [PATCH] Bug 1840578 - Add shopping experience entry point --- .../mozilla/fenix/browser/BrowserFragment.kt | 35 ++++++++++++++++++- .../shopping/ReviewQualityCheckFeature.kt | 28 +++++++++++++++ .../main/res/drawable/ic_shopping_cart.xml | 13 +++++++ .../drawable/ic_shopping_cart_selected.xml | 23 ++++++++++++ app/src/main/res/values/static_strings.xml | 6 ++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt create mode 100644 app/src/main/res/drawable/ic_shopping_cart.xml create mode 100644 app/src/main/res/drawable/ic_shopping_cart_selected.xml 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 2e0f5111d..b0ebc1e39 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.ReviewQualityCheckFeature import org.mozilla.fenix.shortcut.PwaOnboardingObserver import org.mozilla.fenix.theme.ThemeManager @@ -61,8 +62,10 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { private val windowFeature = ViewBoundFeatureWrapper() private val openInAppOnboardingObserver = ViewBoundFeatureWrapper() + private val reviewQualityCheckFeature = ViewBoundFeatureWrapper() private var readerModeAvailable = false + private var reviewQualityCheckAvailable = false private var pwaOnboardingObserver: PwaOnboardingObserver? = null private var forwardAction: BrowserToolbar.TwoStateButton? = null @@ -118,7 +121,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { contentDescription = context.getString(R.string.browser_menu_read), contentDescriptionSelected = context.getString(R.string.browser_menu_read_close), visible = { - readerModeAvailable + readerModeAvailable && !reviewQualityCheckAvailable }, selected = getCurrentTab()?.let { activity?.components?.core?.store?.state?.findTab(it.id)?.readerState?.active @@ -128,6 +131,8 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { browserToolbarView.view.addPageAction(readerModeAction) + initReviewQualityCheck(context, view) + thumbnailsFeature.set( feature = BrowserThumbnails(context, binding.engineView, components.core.store), owner = this, @@ -185,6 +190,34 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { } } + private fun initReviewQualityCheck(context: Context, view: View) { + val reviewQualityCheck = + BrowserToolbar.ToggleButton( + image = AppCompatResources.getDrawable( + context, + R.drawable.ic_shopping_cart, + )!!, + imageSelected = AppCompatResources.getDrawable( + context, + R.drawable.ic_shopping_cart_selected, + )!!, + contentDescription = context.getString(R.string.browser_menu_review_quality_check), + contentDescriptionSelected = context.getString(R.string.browser_menu_review_quality_check_close), + visible = { reviewQualityCheckAvailable }, + listener = {}, + ) + + browserToolbarView.view.addPageAction(reviewQualityCheck) + + reviewQualityCheckFeature.set( + feature = ReviewQualityCheckFeature( + onAvailabilityChange = { reviewQualityCheckAvailable = it }, + ), + owner = this, + view = view, + ) + } + override fun onUpdateToolbarForConfigurationChange(toolbar: BrowserToolbarView) { super.onUpdateToolbarForConfigurationChange(toolbar) diff --git a/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt b/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt new file mode 100644 index 000000000..342135fb0 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/shopping/ReviewQualityCheckFeature.kt @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.shopping + +import mozilla.components.support.base.feature.LifecycleAwareFeature +import org.mozilla.fenix.nimbus.FxNimbus + +/** + * Feature implementation that provides review quality check information for supported product + * pages. + */ +class ReviewQualityCheckFeature( + private val onAvailabilityChange: (isAvailable: Boolean) -> Unit, +) : LifecycleAwareFeature { + + override fun start() { + val isFeatureEnabled = FxNimbus.features.shoppingExperience.value().enabled + // Update to use product page detector api in Bug 1840580 + val isSupportedProductPage = false + onAvailabilityChange(isFeatureEnabled && isSupportedProductPage) + } + + override fun stop() { + // no-op + } +} diff --git a/app/src/main/res/drawable/ic_shopping_cart.xml b/app/src/main/res/drawable/ic_shopping_cart.xml new file mode 100644 index 000000000..ff274f022 --- /dev/null +++ b/app/src/main/res/drawable/ic_shopping_cart.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_shopping_cart_selected.xml b/app/src/main/res/drawable/ic_shopping_cart_selected.xml new file mode 100644 index 000000000..18e160d92 --- /dev/null +++ b/app/src/main/res/drawable/ic_shopping_cart_selected.xml @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index 1db7704d2..0e136e251 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -108,4 +108,10 @@ Something went wrong contacting the Profiler server. URL copied to clipboard successfully + + + + Review quality check + + Close review quality check