Add a Reset button to clear selected currencies, with confirmation
New "Reset" button in the currency picker's top bar (next to Done), shown only when more than the pinned default currency is selected. Tapping it asks for confirmation before removing every other selected currency, via PriceViewModel.onSelectedCurrenciesReset() — same recompute/persist pattern as onFiatCurrencyToggled. Compose uses an AlertDialog; iOS/macOS uses .alert with a destructive Reset action, matching the destructive-role toolbar button that triggers it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -27,6 +27,7 @@ import androidx.compose.material.icons.filled.KeyboardDoubleArrowUp
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
@@ -120,6 +121,7 @@ fun PriceScreen(
|
||||
CurrencyPickerScreen(
|
||||
state = state,
|
||||
onToggle = viewModel::onFiatCurrencyToggled,
|
||||
onReset = viewModel::onSelectedCurrenciesReset,
|
||||
onDone = { showCurrencyPicker = false },
|
||||
)
|
||||
return
|
||||
@@ -501,8 +503,32 @@ private fun CurrencyRowMenu(
|
||||
private fun CurrencyPickerScreen(
|
||||
state: ConverterUiState,
|
||||
onToggle: (String) -> Unit,
|
||||
onReset: () -> Unit,
|
||||
onDone: () -> Unit,
|
||||
) {
|
||||
var showResetConfirmation by remember { mutableStateOf(false) }
|
||||
|
||||
if (showResetConfirmation) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showResetConfirmation = false },
|
||||
title = { Text(stringResource(MR.strings.reset_selected_currencies_confirmation_title)) },
|
||||
text = {
|
||||
Text(stringResource(MR.strings.reset_selected_currencies_confirmation_message, state.defaultCurrencyCode))
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showResetConfirmation = false
|
||||
onReset()
|
||||
},
|
||||
) { Text(stringResource(MR.strings.reset_selected_currencies_button)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showResetConfirmation = false }) { Text(stringResource(MR.strings.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -515,7 +541,14 @@ private fun CurrencyPickerScreen(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(stringResource(MR.strings.currencies_section_title), style = MaterialTheme.typography.headlineSmall)
|
||||
TextButton(onClick = onDone) { Text(stringResource(MR.strings.done)) }
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (state.selectedFiatCurrencies.size > 1) {
|
||||
TextButton(onClick = { showResetConfirmation = true }) {
|
||||
Text(stringResource(MR.strings.reset_selected_currencies_button))
|
||||
}
|
||||
}
|
||||
TextButton(onClick = onDone) { Text(stringResource(MR.strings.done)) }
|
||||
}
|
||||
}
|
||||
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
|
||||
@@ -207,6 +207,16 @@ class PriceViewModel(
|
||||
persistSelectionIfChanged(_uiState.value.selectedFiatCurrencies)
|
||||
}
|
||||
|
||||
/** Removes every selected currency except the pinned [defaultCurrencyCode]. */
|
||||
fun onSelectedCurrenciesReset() {
|
||||
_uiState.update { state ->
|
||||
if (state.selectedFiatCurrencies == listOf(defaultCurrencyCode)) return@update state
|
||||
val newState = state.copy(selectedFiatCurrencies = listOf(defaultCurrencyCode))
|
||||
rates?.let { recomputeFromKnownField(newState, it) } ?: newState
|
||||
}
|
||||
persistSelectionIfChanged(_uiState.value.selectedFiatCurrencies)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders the selected currencies to [newOrder]. Any code in [newOrder] that isn't
|
||||
* currently selected is ignored, and any currently-selected code missing from [newOrder]
|
||||
|
||||
Reference in New Issue
Block a user