Bug 1847024 - Create update analysis card component

fenix/119.0
Cathy Lu 11 months ago committed by mergify[bot]
parent c6d17ce38a
commit 2bc4b7a564

@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.Text import androidx.compose.material.Text
@ -59,10 +60,12 @@ import org.mozilla.fenix.theme.FirefoxTheme
* @param modifier The modifier to be applied to the Composable. * @param modifier The modifier to be applied to the Composable.
*/ */
@Composable @Composable
@Suppress("LongParameterList")
fun ProductAnalysis( fun ProductAnalysis(
productRecommendationsEnabled: Boolean, productRecommendationsEnabled: Boolean,
productAnalysis: AnalysisPresent, productAnalysis: AnalysisPresent,
onOptOutClick: () -> Unit, onOptOutClick: () -> Unit,
onReanalyzeClick: () -> Unit,
onProductRecommendationsEnabledStateChange: (Boolean) -> Unit, onProductRecommendationsEnabledStateChange: (Boolean) -> Unit,
onReviewGradeLearnMoreClick: (String) -> Unit, onReviewGradeLearnMoreClick: (String) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@ -71,6 +74,12 @@ fun ProductAnalysis(
modifier = modifier, modifier = modifier,
verticalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
if (productAnalysis.needsAnalysis) {
ReanalyzeCard(
onReanalyzeClick = onReanalyzeClick,
)
}
if (productAnalysis.reviewGrade != null) { if (productAnalysis.reviewGrade != null) {
ReviewGradeCard( ReviewGradeCard(
reviewGrade = productAnalysis.reviewGrade, reviewGrade = productAnalysis.reviewGrade,
@ -111,6 +120,27 @@ fun ProductAnalysis(
} }
} }
@Composable
private fun ReanalyzeCard(
onReanalyzeClick: () -> Unit,
) {
ReviewQualityCheckInfoCard(
title = stringResource(R.string.review_quality_check_outdated_analysis_warning_title),
type = ReviewQualityCheckInfoType.AnalysisUpdate,
modifier = Modifier.fillMaxWidth(),
buttonText = stringResource(R.string.review_quality_check_outdated_analysis_warning_action),
onButtonClick = onReanalyzeClick,
icon = {
Icon(
painter = painterResource(id = R.drawable.mozac_ic_information_fill_24),
contentDescription = null,
modifier = Modifier.size(24.dp),
tint = FirefoxTheme.colors.iconPrimary,
)
},
)
}
@Composable @Composable
private fun ReviewGradeCard( private fun ReviewGradeCard(
reviewGrade: ReviewQualityCheckState.Grade, reviewGrade: ReviewQualityCheckState.Grade,
@ -504,6 +534,7 @@ private fun ProductAnalysisPreview() {
), ),
), ),
onOptOutClick = {}, onOptOutClick = {},
onReanalyzeClick = {},
onProductRecommendationsEnabledStateChange = { onProductRecommendationsEnabledStateChange = {
productRecommendationsEnabled.value = it productRecommendationsEnabled.value = it
}, },
@ -530,3 +561,20 @@ private fun ReviewQualityInfoPreview() {
} }
} }
} }
@Composable
@LightDarkPreview
private fun ReanalyzeCardPreview() {
FirefoxTheme {
Box(
modifier = Modifier
.fillMaxWidth()
.background(color = FirefoxTheme.colors.layer1)
.padding(all = 16.dp),
) {
ReanalyzeCard(
onReanalyzeClick = {},
)
}
}
}

@ -55,6 +55,7 @@ fun ReviewQualityCheckBottomSheet(
onRequestDismiss() onRequestDismiss()
store.dispatch(ReviewQualityCheckAction.OptOut) store.dispatch(ReviewQualityCheckAction.OptOut)
}, },
onReanalyzeClick = {},
onProductRecommendationsEnabledStateChange = { onProductRecommendationsEnabledStateChange = {
store.dispatch(ReviewQualityCheckAction.ToggleProductRecommendation) store.dispatch(ReviewQualityCheckAction.ToggleProductRecommendation)
}, },
@ -83,6 +84,7 @@ fun ReviewQualityCheckBottomSheet(
private fun ProductReview( private fun ProductReview(
state: ReviewQualityCheckState.OptedIn, state: ReviewQualityCheckState.OptedIn,
onOptOutClick: () -> Unit, onOptOutClick: () -> Unit,
onReanalyzeClick: () -> Unit,
onProductRecommendationsEnabledStateChange: (Boolean) -> Unit, onProductRecommendationsEnabledStateChange: (Boolean) -> Unit,
onReviewGradeLearnMoreClick: (String) -> Unit, onReviewGradeLearnMoreClick: (String) -> Unit,
) { ) {
@ -96,6 +98,7 @@ private fun ProductReview(
productRecommendationsEnabled = state.productRecommendationsPreference, productRecommendationsEnabled = state.productRecommendationsPreference,
productAnalysis = productReviewState, productAnalysis = productReviewState,
onOptOutClick = onOptOutClick, onOptOutClick = onOptOutClick,
onReanalyzeClick = onReanalyzeClick,
onProductRecommendationsEnabledStateChange = onProductRecommendationsEnabledStateChange, onProductRecommendationsEnabledStateChange = onProductRecommendationsEnabledStateChange,
onReviewGradeLearnMoreClick = onReviewGradeLearnMoreClick, onReviewGradeLearnMoreClick = onReviewGradeLearnMoreClick,
) )

@ -137,6 +137,7 @@ enum class ReviewQualityCheckInfoType {
Confirmation, Confirmation,
Error, Error,
Info, Info,
AnalysisUpdate,
; ;
val cardBackgroundColor: Color val cardBackgroundColor: Color
@ -146,6 +147,7 @@ enum class ReviewQualityCheckInfoType {
Confirmation -> FirefoxTheme.colors.layerConfirmation Confirmation -> FirefoxTheme.colors.layerConfirmation
Error -> FirefoxTheme.colors.layerError Error -> FirefoxTheme.colors.layerError
Info -> FirefoxTheme.colors.layerInfo Info -> FirefoxTheme.colors.layerInfo
AnalysisUpdate -> Color.Transparent
} }
val buttonBackgroundColor: Color val buttonBackgroundColor: Color
@ -155,12 +157,14 @@ enum class ReviewQualityCheckInfoType {
Confirmation -> FirefoxTheme.colors.actionConfirmation Confirmation -> FirefoxTheme.colors.actionConfirmation
Error -> FirefoxTheme.colors.actionError Error -> FirefoxTheme.colors.actionError
Info -> FirefoxTheme.colors.actionInfo Info -> FirefoxTheme.colors.actionInfo
AnalysisUpdate -> FirefoxTheme.colors.actionSecondary
} }
val buttonTextColor: Color val buttonTextColor: Color
@Composable @Composable
get() = when { get() = when {
this == Info && !isSystemInDarkTheme() -> FirefoxTheme.colors.textOnColorPrimary this == Info && !isSystemInDarkTheme() -> FirefoxTheme.colors.textOnColorPrimary
this == AnalysisUpdate -> FirefoxTheme.colors.textActionSecondary
else -> FirefoxTheme.colors.textPrimary else -> FirefoxTheme.colors.textPrimary
} }
} }
@ -177,6 +181,7 @@ private class PreviewModelParameterProvider : PreviewParameterProvider<PreviewMo
PreviewModel(ReviewQualityCheckInfoType.Confirmation, R.drawable.mozac_ic_checkmark_24), PreviewModel(ReviewQualityCheckInfoType.Confirmation, R.drawable.mozac_ic_checkmark_24),
PreviewModel(ReviewQualityCheckInfoType.Error, R.drawable.mozac_ic_information_fill_24), PreviewModel(ReviewQualityCheckInfoType.Error, R.drawable.mozac_ic_information_fill_24),
PreviewModel(ReviewQualityCheckInfoType.Info, R.drawable.mozac_ic_information_fill_24), PreviewModel(ReviewQualityCheckInfoType.Info, R.drawable.mozac_ic_information_fill_24),
PreviewModel(ReviewQualityCheckInfoType.AnalysisUpdate, R.drawable.mozac_ic_information_fill_24),
) )
} }

Loading…
Cancel
Save