@ -49,10 +49,9 @@ import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.HighlightType
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent.AnalysisStatus
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent.HighlightsInfo
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.RecommendedProductState
import org.mozilla.fenix.shopping.store.forCompactMode
import org.mozilla.fenix.theme.FirefoxTheme
import java.util.SortedMap
private val combinedParentHorizontalPadding = 32. dp
private val productRecommendationImageSize = 60. dp
@ -68,13 +67,14 @@ private const val PRODUCT_RECOMMENDATION_IMPRESSION_THRESHOLD = 0.5f
* @param productVendor The vendor of the product .
* @param isSettingsExpanded Whether or not the settings card is expanded .
* @param isInfoExpanded Whether or not the info card is expanded .
* @param isHighlightsExpanded Whether or not the highlights card is expanded .
* @param onOptOutClick Invoked when the user opts out of the review quality check feature .
* @param onReanalyzeClick Invoked when the user clicks to re - analyze a product .
* @param onProductRecommendationsEnabledStateChange Invoked when the user changes the product
* recommendations toggle state .
* @param onReviewGradeLearnMoreClick Invoked when the user clicks to learn more about review grades .
* @param onFooterLinkClick Invoked when the user clicks on the footer link .
* @param on ShowMoreRecentReviewsClicked Invoked when the user clicks to show more recent reviews .
* @param on HighlightsExpandToggleClick Invoked when the user clicks to show more recent reviews .
* @param onSettingsExpandToggleClick Invoked when the user expands or collapses the settings card .
* @param onInfoExpandToggleClick Invoked when the user expands or collapses the info card .
* @param onRecommendedProductClick Invoked when the user clicks on the product recommendation .
@ -89,12 +89,13 @@ fun ProductAnalysis(
productVendor : ReviewQualityCheckState . ProductVendor ,
isSettingsExpanded : Boolean ,
isInfoExpanded : Boolean ,
isHighlightsExpanded : Boolean ,
onOptOutClick : ( ) -> Unit ,
onReanalyzeClick : ( ) -> Unit ,
onProductRecommendationsEnabledStateChange : ( Boolean ) -> Unit ,
onReviewGradeLearnMoreClick : ( ) -> Unit ,
onFooterLinkClick : ( ) -> Unit ,
on ShowMoreRecentReviewsClicked : ( ) -> Unit ,
on HighlightsExpandToggleClick : ( ) -> Unit ,
onSettingsExpandToggleClick : ( ) -> Unit ,
onInfoExpandToggleClick : ( ) -> Unit ,
onRecommendedProductClick : ( aid : String , url : String ) -> Unit ,
@ -133,12 +134,11 @@ fun ProductAnalysis(
)
}
if ( productAnalysis . highlights != null ) {
if ( productAnalysis . highlights Info != null ) {
HighlightsCard (
highlights = productAnalysis . highlights ,
highlightsFadeVisible = productAnalysis . highlightsFadeVisible ,
showMoreButtonVisible = productAnalysis . showMoreButtonVisible ,
onShowMoreRecentReviewsClicked = onShowMoreRecentReviewsClicked ,
highlightsInfo = productAnalysis . highlightsInfo ,
onHighlightsExpandToggleClick = onHighlightsExpandToggleClick ,
isExpanded = isHighlightsExpanded ,
modifier = Modifier . fillMaxWidth ( ) ,
)
}
@ -254,20 +254,17 @@ private fun AdjustedProductRatingCard(
@Suppress ( " LongMethod " )
@Composable
private fun HighlightsCard (
highlights : Map < HighlightType , List < String > > ,
highlightsFadeVisible : Boolean ,
showMoreButtonVisible : Boolean ,
onShowMoreRecentReviewsClicked : ( ) -> Unit ,
highlightsInfo : HighlightsInfo ,
isExpanded : Boolean ,
onHighlightsExpandToggleClick : ( ) -> Unit ,
modifier : Modifier = Modifier ,
) {
ReviewQualityCheckCard ( modifier = modifier ) {
var isExpanded by remember { mutableStateOf ( false ) }
val highlightsForCompactMode = remember ( highlights ) { highlights . forCompactMode ( ) }
val highlightsToDisplay = remember ( isExpanded , highlights ) {
val highlightsToDisplay = remember ( isExpanded , highlightsInfo . highlights ) {
if ( isExpanded ) {
highlights
highlightsInfo . highlights
} else {
highlights ForCompactMode
highlights Info. highlights ForCompactMode
}
}
@ -309,7 +306,7 @@ private fun HighlightsCard(
targetState = isExpanded ,
label = " HighlightsCard-Crossfade " ,
) { expanded ->
if ( expanded . not ( ) && highlights FadeVisible) {
if ( expanded . not ( ) && highlights Info. highlights FadeVisible) {
Spacer (
modifier = Modifier
. height ( 32. dp )
@ -327,7 +324,7 @@ private fun HighlightsCard(
}
}
if ( showMoreButtonVisible) {
if ( highlightsInfo. showMoreButtonVisible) {
Spacer ( modifier = Modifier . height ( 8. dp ) )
Divider ( modifier = Modifier . extendWidthToParentBorder ( ) )
@ -340,12 +337,7 @@ private fun HighlightsCard(
} else {
stringResource ( R . string . review _quality _check _highlights _show _more )
} ,
onClick = {
if ( !is Expanded ) {
onShowMoreRecentReviewsClicked ( )
}
isExpanded = isExpanded . not ( )
} ,
onClick = onHighlightsExpandToggleClick ,
)
}
}
@ -517,31 +509,33 @@ private class ProductAnalysisPreviewModel(
analysisStatus : AnalysisStatus = AnalysisStatus . UP _TO _DATE ,
adjustedRating : Float ? = 3.6f ,
productUrl : String = " " ,
highlights : SortedMap < HighlightType , List < String > > ? = sortedMapOf (
HighlightType . QUALITY to listOf (
" High quality " ,
" Excellent craftsmanship " ,
" Superior materials " ,
) ,
HighlightType . PRICE to listOf (
" Affordable prices " ,
" Great value for money " ,
" Discounted offers " ,
) ,
HighlightType . SHIPPING to listOf (
" Fast and reliable shipping " ,
" Free shipping options " ,
" Express delivery " ,
) ,
HighlightType . PACKAGING _AND _APPEARANCE to listOf (
" Elegant packaging " ,
" Attractive appearance " ,
" Beautiful design " ,
) ,
HighlightType . COMPETITIVENESS to listOf (
" Competitive pricing " ,
" Strong market presence " ,
" Unbeatable deals " ,
highlightsInfo : HighlightsInfo = HighlightsInfo (
mapOf (
HighlightType . QUALITY to listOf (
" High quality " ,
" Excellent craftsmanship " ,
" Superior materials " ,
) ,
HighlightType . PRICE to listOf (
" Affordable prices " ,
" Great value for money " ,
" Discounted offers " ,
) ,
HighlightType . SHIPPING to listOf (
" Fast and reliable shipping " ,
" Free shipping options " ,
" Express delivery " ,
) ,
HighlightType . PACKAGING _AND _APPEARANCE to listOf (
" Elegant packaging " ,
" Attractive appearance " ,
" Beautiful design " ,
) ,
HighlightType . COMPETITIVENESS to listOf (
" Competitive pricing " ,
" Strong market presence " ,
" Unbeatable deals " ,
) ,
) ,
) ,
recommendedProductState : RecommendedProductState = RecommendedProductState . Initial ,
@ -554,7 +548,7 @@ private class ProductAnalysisPreviewModel(
analysisStatus = analysisStatus ,
adjustedRating = adjustedRating ,
productUrl = productUrl ,
highlights = highlights ,
highlights Info = highlights Info ,
recommendedProductState = recommendedProductState ,
) ,
productVendor = productVendor ,
@ -576,10 +570,12 @@ private class ProductAnalysisPreviewModelParameterProvider :
reviewGrade = null ,
) ,
ProductAnalysisPreviewModel (
highlights = sortedMapOf (
HighlightType . QUALITY to listOf (
" High quality " ,
" Excellent craftsmanship " ,
highlightsInfo = HighlightsInfo (
mapOf (
HighlightType . QUALITY to listOf (
" High quality " ,
" Excellent craftsmanship " ,
) ,
) ,
) ,
) ,
@ -613,6 +609,7 @@ private fun ProductAnalysisPreview(
var productRecommendationsEnabled by remember { mutableStateOf ( model . productRecommendationsEnabled ) }
var isSettingsExpanded by remember { mutableStateOf ( false ) }
var isInfoExpanded by remember { mutableStateOf ( false ) }
var isHighlightsExpanded by remember { mutableStateOf ( false ) }
ProductAnalysis (
productRecommendationsEnabled = productRecommendationsEnabled ,
@ -620,6 +617,7 @@ private fun ProductAnalysisPreview(
productVendor = model . productVendor ,
isSettingsExpanded = isSettingsExpanded ,
isInfoExpanded = isInfoExpanded ,
isHighlightsExpanded = isHighlightsExpanded ,
onOptOutClick = { } ,
onReanalyzeClick = { } ,
onProductRecommendationsEnabledStateChange = {
@ -627,7 +625,7 @@ private fun ProductAnalysisPreview(
} ,
onReviewGradeLearnMoreClick = { } ,
onFooterLinkClick = { } ,
on ShowMoreRecentReviewsClicked = { } ,
on HighlightsExpandToggleClick = { isHighlightsExpanded = !is HighlightsExpanded } ,
onSettingsExpandToggleClick = { isSettingsExpanded = !is SettingsExpanded } ,
onInfoExpandToggleClick = { isInfoExpanded = !is InfoExpanded } ,
onRecommendedProductClick = { _ , _ -> } ,