@ -38,13 +38,17 @@ import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import mozilla.components.concept.engine.translate.TranslationError
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.BetaLabel
import org.mozilla.fenix.compose.LinkText
import org.mozilla.fenix.compose.LinkTextState
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.compose.button.PrimaryButton
import org.mozilla.fenix.compose.button.TertiaryButton
import org.mozilla.fenix.compose.button.TextButton
import org.mozilla.fenix.shopping.ui.ReviewQualityCheckInfoCard
import org.mozilla.fenix.shopping.ui.ReviewQualityCheckInfoType
import org.mozilla.fenix.theme.FirefoxTheme
/ * *
@ -54,6 +58,7 @@ import org.mozilla.fenix.theme.FirefoxTheme
fun TranslationsDialogBottomSheet (
learnMoreUrl : String ,
showFirstTimeTranslation : Boolean ,
translationError : TranslationError ? = null ,
onSettingClicked : ( ) -> Unit ,
onLearnMoreClicked : ( ) -> Unit ,
onTranslateButtonClick : ( ) -> Unit ,
@ -83,22 +88,35 @@ fun TranslationsDialogBottomSheet(
TranslationsDialogInfoMessage ( onLearnMoreClicked , learnMoreUrl )
}
translationError ?. let {
TranslationErrorWarning ( translationError )
}
Spacer ( modifier = Modifier . height ( 14. dp ) )
when ( orientation ) {
Configuration . ORIENTATION _LANDSCAPE -> {
TranslationsDialogContentInLandscapeMode ( onTranslateButtonClick )
}
if ( translationError !is TranslationError . CouldNotLoadLanguagesError ) {
when ( orientation ) {
Configuration . ORIENTATION _LANDSCAPE -> {
TranslationsDropdownsInLandscapeMode ( )
}
else -> {
TranslationsDialogContentInPortraitMode ( onTranslateButtonClick )
else -> {
TranslationsDropdownsInPortraitMode ( )
}
}
Spacer ( modifier = Modifier . height ( 16. dp ) )
}
TranslationsDialogActionButtons (
onTranslateButtonClick = onTranslateButtonClick ,
translationError = translationError ,
)
}
}
@Composable
private fun TranslationsDialogContentInPortraitMode ( onTranslateButtonClick : ( ) -> Unit ) {
private fun TranslationsD ropdownsInPortraitMode( ) {
Column {
TranslationsDropdown (
header = stringResource ( id = R . string . translations _bottom _sheet _translate _from ) ,
@ -109,15 +127,11 @@ private fun TranslationsDialogContentInPortraitMode(onTranslateButtonClick: () -
TranslationsDropdown (
header = stringResource ( id = R . string . translations _bottom _sheet _translate _to ) ,
)
Spacer ( modifier = Modifier . height ( 16. dp ) )
TranslationsDialogActionButtons ( onTranslateButtonClick )
}
}
@Composable
private fun TranslationsD ialogContentInLandscapeMode( onTranslateButtonClick : ( ) -> Unit ) {
private fun TranslationsD ropdownsInLandscapeMode( ) {
Column {
Row {
TranslationsDropdown (
@ -131,10 +145,6 @@ private fun TranslationsDialogContentInLandscapeMode(onTranslateButtonClick: ()
header = stringResource ( id = R . string . translations _bottom _sheet _translate _to ) ,
)
}
Spacer ( modifier = Modifier . height ( 16. dp ) )
TranslationsDialogActionButtons ( onTranslateButtonClick )
}
}
@ -179,6 +189,51 @@ private fun TranslationsDialogHeader(
}
}
@Composable
private fun TranslationErrorWarning ( translationError : TranslationError ) {
val modifier = Modifier
. padding ( top = 8. dp )
. fillMaxWidth ( )
when ( translationError ) {
is TranslationError . CouldNotTranslateError -> {
ReviewQualityCheckInfoCard (
title = stringResource ( id = R . string . translation _error _could _not _translate _warning _text ) ,
type = ReviewQualityCheckInfoType . Error ,
modifier = modifier ,
)
}
is TranslationError . CouldNotLoadLanguagesError -> {
ReviewQualityCheckInfoCard (
title = stringResource ( id = R . string . translation _error _could _not _load _languages _warning _text ) ,
type = ReviewQualityCheckInfoType . Error ,
modifier = modifier ,
)
}
is TranslationError . LanguageNotSupportedError -> {
ReviewQualityCheckInfoCard (
title = stringResource (
id = R . string . translation _error _language _not _supported _warning _text ,
" Uzbek " ,
) ,
type = ReviewQualityCheckInfoType . Info ,
modifier = modifier ,
footer = stringResource (
id = R . string . translation _error _language _not _supported _learn _more ,
) to LinkTextState (
text = stringResource ( id = R . string . translation _error _language _not _supported _learn _more ) ,
url = " https://www.mozilla.org " ,
onClick = { } ,
) ,
)
}
else -> { }
}
}
@Composable
private fun TranslationsDialogInfoMessage (
onLearnMoreClicked : ( ) -> Unit ,
@ -241,7 +296,10 @@ private fun TranslationsDropdown(
}
@Composable
private fun TranslationsDialogActionButtons ( onTranslateButtonClick : ( ) -> Unit ) {
private fun TranslationsDialogActionButtons (
onTranslateButtonClick : ( ) -> Unit ,
translationError : TranslationError ? = null ,
) {
val isTranslationInProgress = remember { mutableStateOf ( false ) }
Row (
@ -249,8 +307,15 @@ private fun TranslationsDialogActionButtons(onTranslateButtonClick: () -> Unit)
horizontalArrangement = Arrangement . End ,
verticalAlignment = Alignment . CenterVertically ,
) {
val negativeButtonTitle =
if ( translationError is TranslationError . LanguageNotSupportedError ) {
stringResource ( id = R . string . translations _bottom _sheet _negative _button _error )
} else {
stringResource ( id = R . string . translations _bottom _sheet _negative _button )
}
TextButton (
text = stringResource ( id = R . string . translations _bottom _sheet _negative _button ) ,
text = negativeButtonTitle ,
modifier = Modifier ,
onClick = { } ,
)
@ -265,12 +330,30 @@ private fun TranslationsDialogActionButtons(onTranslateButtonClick: () -> Unit)
icon = painterResource ( id = R . drawable . mozac _ic _sync _24 ) ,
)
} else {
PrimaryButton (
text = stringResource ( id = R . string . translations _bottom _sheet _positive _button ) ,
modifier = Modifier . wrapContentSize ( ) ,
) {
isTranslationInProgress . value = true
onTranslateButtonClick ( )
val positiveButtonTitle =
if ( translationError is TranslationError . CouldNotLoadLanguagesError ) {
stringResource ( id = R . string . translations _bottom _sheet _positive _button _error )
} else {
stringResource ( id = R . string . translations _bottom _sheet _positive _button )
}
if ( translationError is TranslationError . LanguageNotSupportedError ) {
TertiaryButton (
text = positiveButtonTitle ,
enabled = false ,
modifier = Modifier . wrapContentSize ( ) ,
) {
isTranslationInProgress . value = true
onTranslateButtonClick ( )
}
} else {
PrimaryButton (
text = positiveButtonTitle ,
modifier = Modifier . wrapContentSize ( ) ,
) {
isTranslationInProgress . value = true
onTranslateButtonClick ( )
}
}
}
}
@ -283,6 +366,7 @@ private fun TranslationsDialogBottomSheetPreview() {
TranslationsDialogBottomSheet (
learnMoreUrl = " " ,
showFirstTimeTranslation = true ,
translationError = TranslationError . LanguageNotSupportedError ( null ) ,
onSettingClicked = { } ,
onLearnMoreClicked = { } ,
onTranslateButtonClick = { } ,