Bug 1840332 - Create ReviewQualityCheckState

fenix/117.0
rahulsainani 12 months ago committed by mergify[bot]
parent c0292f3846
commit 095a0ec50b

@ -0,0 +1,12 @@
/* 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.state
import mozilla.components.lib.state.Action
/**
* Actions for review quality check feature.
*/
sealed interface ReviewQualityCheckAction : Action

@ -0,0 +1,138 @@
/* 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.state
import mozilla.components.lib.state.State
/**
* UI state of the review quality check feature.
*/
sealed interface ReviewQualityCheckState : State {
/**
* The initial state of the feature, it's also the default state set in the store.
*/
object Initial : ReviewQualityCheckState
/**
* The state when the user has not opted in for the feature.
*/
object NotOptedIn : ReviewQualityCheckState
/**
* The state when the user has opted in for the feature.
*
* @property productReviewState The state of the product the user is browsing.
* @property productRecommendationsPreference User preference whether to show product
* recommendations. True if product recommendations should be shown.
*/
data class OptedIn(
val productReviewState: ProductReviewState = ProductReviewState.Loading,
val productRecommendationsPreference: Boolean,
) : ReviewQualityCheckState {
/**
* The state of the product the user is browsing.
*/
sealed interface ProductReviewState {
/**
* Denotes content is loading.
*/
object Loading : ProductReviewState
/**
* Denotes an error has occurred.
*/
object Error : ProductReviewState
/**
* Denotes no analysis is present for the product the user is browsing.
*
* @property productUrl The url of the product the user is browsing.
*/
data class NoAnalysisPresent(
val productUrl: String,
) : ProductReviewState
/**
* Denotes the state where analysis of the product is fetched and available.
*
* @property productId The id of the product, e.g ASIN, SKU.
* @property reviewGrade The review grade of the product.
* @property needsAnalysis If true, the analysis is stale and that to get the fresh
* data, reanalysis is needed.
* @property adjustedRating The adjusted rating taking review quality into consideration.
* @property productUrl The url of the product the user is browsing.
* @property highlights Optional highlights based on recent reviews of the product.
* @property recommendedProductState The state of the recommended product.
*/
data class ProductAnalysis(
val productId: String,
val reviewGrade: Grade,
val needsAnalysis: Boolean,
val adjustedRating: Float,
val productUrl: String,
val highlights: Map<HighlightType, List<String>>?,
val recommendedProductState: RecommendedProductState = RecommendedProductState.Initial,
) : ProductReviewState
}
}
/**
* Review Grade of the product - A being the best and F being the worst. There is no grade E.
*/
enum class Grade {
A, B, C, D, F
}
/**
* Factors for which highlights are available based on recent reviews of the product.
*/
enum class HighlightType {
QUALITY, PRICE, SHIPPING, PACKAGING_AND_APPEARANCE, COMPETITIVENESS
}
/**
* The state of the recommended product.
*/
sealed interface RecommendedProductState {
/**
* The initial state of the recommended product.
*/
object Initial : RecommendedProductState
/**
* The state when the recommended product is loading.
*/
object Loading : RecommendedProductState
/**
* The state when an error has occurred while fetching the recommended product.
*/
object Error : RecommendedProductState
/**
* The state when the recommended product is available.
*
* @property name The name of the product.
* @property productUrl The url of the product.
* @property imageUrl The url of the image of the product.
* @property formattedPrice The formatted price of the product.
* @property reviewGrade The review grade of the product.
* @property adjustedRating The adjusted rating of the product.
* @property isSponsored True if the product is sponsored.
* @property analysisUrl The url of the analysis of the product.
*/
data class Product(
val name: String,
val productUrl: String,
val imageUrl: String,
val formattedPrice: String,
val reviewGrade: Grade,
val adjustedRating: Float,
val isSponsored: Boolean,
val analysisUrl: String,
) : RecommendedProductState
}
}

@ -0,0 +1,15 @@
/* 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.state
import mozilla.components.lib.state.Store
/**
* Store for review quality check feature.
*/
class ReviewQualityCheckStore : Store<ReviewQualityCheckState, ReviewQualityCheckAction>(
initialState = ReviewQualityCheckState.Initial,
reducer = { _, _ -> ReviewQualityCheckState.Initial },
)

@ -29,6 +29,7 @@ import androidx.compose.ui.unit.dp
import mozilla.components.ui.colors.PhotonColors
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState.Grade
import org.mozilla.fenix.theme.FirefoxTheme
private val height = 24.dp
@ -47,7 +48,7 @@ private val reviewGradeFColorExpanded = Color(0xFFF9DBE1)
/**
* Review Grade of the product - A being the best and F being the worst.
*/
enum class ReviewGrade(
private enum class ReviewGrade(
val stringResourceId: Int,
val backgroundColor: Color,
val expandedTextBackgroundColor: Color,
@ -83,15 +84,15 @@ enum class ReviewGrade(
* UI for displaying the review grade.
*
* @param modifier The modifier to be applied to the Composable.
* @param reviewGrade The grade of the product.
* @param grade The grade of the product.
*/
@Composable
fun ReviewGradeCompact(
modifier: Modifier = Modifier,
reviewGrade: ReviewGrade,
grade: Grade,
) {
ReviewGradeLetter(
reviewGrade = reviewGrade,
reviewGrade = grade.toReviewGrade(),
modifier = modifier.border(
border = BorderStroke(
width = 1.dp,
@ -106,13 +107,15 @@ fun ReviewGradeCompact(
* UI for displaying the review grade with descriptive text.
*
* @param modifier The modifier to be applied to the Composable.
* @param reviewGrade The grade of the product.
* @param grade The grade of the product.
*/
@Composable
fun ReviewGradeExpanded(
modifier: Modifier = Modifier,
reviewGrade: ReviewGrade,
grade: Grade,
) {
val reviewGrade = grade.toReviewGrade()
Row(
modifier = modifier
.background(
@ -172,6 +175,18 @@ private fun ReviewGradeLetter(
}
}
/**
* Maps [Grade] to [ReviewGrade].
*/
private fun Grade.toReviewGrade(): ReviewGrade =
when (this) {
Grade.A -> ReviewGrade.A
Grade.B -> ReviewGrade.B
Grade.C -> ReviewGrade.C
Grade.D -> ReviewGrade.D
Grade.F -> ReviewGrade.F
}
@Composable
@LightDarkPreview
private fun ReviewGradePreview() {
@ -181,13 +196,13 @@ private fun ReviewGradePreview() {
.background(FirefoxTheme.colors.layer1)
.padding(16.dp),
) {
ReviewGrade.values().forEach {
Grade.values().forEach {
Row(
horizontalArrangement = Arrangement.spacedBy(32.dp),
) {
ReviewGradeCompact(reviewGrade = it)
ReviewGradeCompact(grade = it)
ReviewGradeExpanded(reviewGrade = it)
ReviewGradeExpanded(grade = it)
}
Spacer(modifier = Modifier.height(16.dp))

Loading…
Cancel
Save