Retry currency rates update

relevant to #31
This commit is contained in:
sadellie 2023-07-20 22:52:53 +03:00
parent 4e28521ec0
commit eb9b12da28
4 changed files with 18 additions and 5 deletions

View File

@ -962,6 +962,7 @@
<!-- MISC. -->
<string name="loading_label">"Loading…"</string>
<string name="error_label">"Error"</string>
<string name="try_again_label">"Click to try again"</string>
<string name="copied">"Copied %1$s!"</string>
<string name="cancel_label">"Cancel"</string>
<string name="ok_label" translatable="false">"OK"</string>

View File

@ -61,6 +61,7 @@ internal fun ConverterRoute(
clearInput = viewModel::clearInput,
onCursorChange = viewModel::onCursorChange,
cutCallback = viewModel::deleteTokens,
onErrorClick = viewModel::updateCurrenciesRatesIfNeeded,
)
}
@ -77,6 +78,7 @@ private fun ConverterScreen(
clearInput: () -> Unit,
onCursorChange: (TextRange) -> Unit,
cutCallback: () -> Unit,
onErrorClick: () -> Unit,
) {
UnittoScreenWithTopBar(
title = { Text(stringResource(R.string.unit_converter)) },
@ -107,6 +109,7 @@ private fun ConverterScreen(
cutCallback = cutCallback,
pasteCallback = processInput,
formatterSymbols = uiState.formatterSymbols,
onErrorClick = onErrorClick
)
},
content2 = {
@ -144,6 +147,7 @@ private fun PreviewConverterScreen() {
deleteDigit = {},
clearInput = {},
onCursorChange = {},
cutCallback = {}
cutCallback = {},
onErrorClick = {},
)
}

View File

@ -285,7 +285,7 @@ class ConverterViewModel @Inject constructor(
}
}
private fun updateCurrenciesRatesIfNeeded() {
fun updateCurrenciesRatesIfNeeded() {
viewModelScope.launch(Dispatchers.IO) {
_showError.update { false }
_showLoading.update { false }

View File

@ -98,6 +98,7 @@ internal fun TopScreenPart(
cutCallback: () -> Unit,
pasteCallback: (String) -> Unit,
formatterSymbols: FormatterSymbols,
onErrorClick: () -> Unit,
) {
var swapped by remember { mutableStateOf(false) }
val swapButtonRotation: Float by animateFloatAsState(
@ -148,7 +149,8 @@ internal fun TopScreenPart(
modifier = Modifier,
value = calculatedTextFieldValue,
onCursorChange = { newSelection ->
calculatedTextFieldValue = calculatedTextFieldValue.copy(selection = newSelection)
calculatedTextFieldValue =
calculatedTextFieldValue.copy(selection = newSelection)
},
formatterSymbols = formatterSymbols,
textColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f),
@ -237,7 +239,7 @@ internal fun TopScreenPart(
UnformattedTextField(
modifier = Modifier.weight(2f),
value = TextFieldValue(stringResource(R.string.error_label)),
onCursorChange = {},
onCursorChange = { onErrorClick() },
minRatio = 0.7f,
readOnly = true,
textColor = MaterialTheme.colorScheme.error
@ -245,9 +247,15 @@ internal fun TopScreenPart(
}
}
val supportLabelTo = when {
outputValue is ConversionResult.Error -> R.string.try_again_label
(unitTo?.shortName != null) -> unitTo.shortName
else -> R.string.loading_label
}
AnimatedContent(
modifier = Modifier.fillMaxWidth(),
targetState = stringResource(unitTo?.shortName ?: R.string.loading_label),
targetState = stringResource(supportLabelTo),
transitionSpec = {
// Enter animation
(expandHorizontally(clip = false, expandFrom = Alignment.Start) + fadeIn()