fix: add currencies and search to them
This commit is contained in:
@@ -1,20 +1,38 @@
|
|||||||
package cc.n0th1ng.tripmoney.screens.listexpense
|
package cc.n0th1ng.tripmoney.screens.listexpense
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.sizeIn
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.RadioButton
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cc.n0th1ng.tripmoney.R
|
import cc.n0th1ng.tripmoney.R
|
||||||
|
import cc.n0th1ng.tripmoney.theme.TripMoneyTheme
|
||||||
|
import cc.n0th1ng.tripmoney.utils.AllPreviews
|
||||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||||
|
import com.composables.icons.materialsymbols.outlined.R.drawable
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CurrencySelectionDialog(
|
fun CurrencySelectionDialog(
|
||||||
@@ -23,29 +41,90 @@ fun CurrencySelectionDialog(
|
|||||||
selected: String
|
selected: String
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
|
modifier = Modifier.sizeIn(maxHeight = 500.dp),
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
title = { Text(stringResource(R.string.pick_currency)) },
|
title = { Text(stringResource(R.string.pick_currency)) },
|
||||||
text = {
|
text = {
|
||||||
Column {
|
val scrollState = rememberLazyListState()
|
||||||
Currencies.names().forEach { currency ->
|
val currencies = Currencies.names()
|
||||||
|
var search by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
LaunchedEffect(selected) {
|
||||||
|
val index = currencies.indexOf(selected)
|
||||||
|
if (index != -1) {
|
||||||
|
scrollState.animateScrollToItem(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = search,
|
||||||
|
onValueChange = { newText ->
|
||||||
|
search = newText
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
trailingIcon = {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(drawable.materialsymbols_ic_search_outlined),
|
||||||
|
contentDescription = "search"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val filteredCurrencies = if (search.isBlank()) {
|
||||||
|
currencies
|
||||||
|
} else {
|
||||||
|
currencies.filter { currency ->
|
||||||
|
currency.lowercase().contains(search.lowercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyColumn(state = scrollState) {
|
||||||
|
items(
|
||||||
|
count = filteredCurrencies.size,
|
||||||
|
key = { index -> filteredCurrencies[index] }
|
||||||
|
) { index ->
|
||||||
|
val currency = filteredCurrencies[index]
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable {
|
.clickable {
|
||||||
onCurrencySelected(currency)
|
onCurrencySelected(currency)
|
||||||
}
|
},
|
||||||
.padding(vertical = 8.dp),
|
verticalAlignment = Alignment.CenterVertically
|
||||||
verticalAlignment = Alignment.CenterVertically) {
|
) {
|
||||||
RadioButton(
|
RadioButton(
|
||||||
selected = selected == currency, onClick = {
|
selected = selected == currency,
|
||||||
onCurrencySelected(currency)
|
onClick = { onCurrencySelected(currency) }
|
||||||
})
|
)
|
||||||
Text(
|
Text(
|
||||||
text = currency, modifier = Modifier.padding(start = 8.dp)
|
text = currency,
|
||||||
|
modifier = Modifier.padding(start = 8.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
confirmButton = {})
|
},
|
||||||
|
confirmButton = {},
|
||||||
|
dismissButton = {
|
||||||
|
Button(
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.secondary),
|
||||||
|
enabled = true,
|
||||||
|
onClick = onDismiss,
|
||||||
|
) { Text(stringResource(R.string.cancel)) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewCurrencySelectionDialog() {
|
||||||
|
TripMoneyTheme {
|
||||||
|
CurrencySelectionDialog(
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
Currencies.names().random()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +326,6 @@ fun PreviewTripPickerScreen() {
|
|||||||
@AllPreviews
|
@AllPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun PreviewTripPickerScreenNoTrip() {
|
fun PreviewTripPickerScreenNoTrip() {
|
||||||
|
|
||||||
TripMoneyTheme {
|
TripMoneyTheme {
|
||||||
TripPickerScreen(
|
TripPickerScreen(
|
||||||
tripsFlow = MutableStateFlow(PagingData.from(emptyList())),
|
tripsFlow = MutableStateFlow(PagingData.from(emptyList())),
|
||||||
|
|||||||
@@ -1,10 +1,169 @@
|
|||||||
package cc.n0th1ng.tripmoney.utils
|
package cc.n0th1ng.tripmoney.utils
|
||||||
|
|
||||||
enum class Currencies {
|
enum class Currencies {
|
||||||
|
AED,
|
||||||
|
AFN,
|
||||||
|
ALL,
|
||||||
|
AMD,
|
||||||
|
ANG,
|
||||||
|
AOA,
|
||||||
|
ARS,
|
||||||
|
AUD,
|
||||||
|
AWG,
|
||||||
|
AZN,
|
||||||
|
BAM,
|
||||||
|
BBD,
|
||||||
|
BDT,
|
||||||
|
BHD,
|
||||||
|
BIF,
|
||||||
|
BMD,
|
||||||
|
BND,
|
||||||
|
BOB,
|
||||||
|
BRL,
|
||||||
|
BSD,
|
||||||
|
BTN,
|
||||||
|
BWP,
|
||||||
|
BYN,
|
||||||
|
BZD,
|
||||||
|
CAD,
|
||||||
|
CDF,
|
||||||
|
CHF,
|
||||||
|
CLP,
|
||||||
|
CNH,
|
||||||
|
CNY,
|
||||||
|
COP,
|
||||||
|
CRC,
|
||||||
|
CUP,
|
||||||
|
CVE,
|
||||||
|
CZK,
|
||||||
|
DJF,
|
||||||
|
DKK,
|
||||||
|
DOP,
|
||||||
|
DZD,
|
||||||
|
EGP,
|
||||||
|
ERN,
|
||||||
|
ETB,
|
||||||
|
FJD,
|
||||||
|
FKP,
|
||||||
|
GBP,
|
||||||
|
GEL,
|
||||||
|
GGP,
|
||||||
|
GHS,
|
||||||
|
GIP,
|
||||||
|
GMD,
|
||||||
|
GNF,
|
||||||
|
GTQ,
|
||||||
|
GYD,
|
||||||
|
HKD,
|
||||||
|
HNL,
|
||||||
|
HTG,
|
||||||
|
HUF,
|
||||||
|
IDR,
|
||||||
|
ILS,
|
||||||
|
IMP,
|
||||||
|
INR,
|
||||||
|
IQD,
|
||||||
|
IRR,
|
||||||
|
ISK,
|
||||||
|
JEP,
|
||||||
|
JMD,
|
||||||
|
JOD,
|
||||||
|
JPY,
|
||||||
|
KES,
|
||||||
|
KGS,
|
||||||
|
KHR,
|
||||||
|
KMF,
|
||||||
|
KRW,
|
||||||
|
KWD,
|
||||||
|
KYD,
|
||||||
|
KZT,
|
||||||
|
LAK,
|
||||||
|
LBP,
|
||||||
|
LKR,
|
||||||
|
LRD,
|
||||||
|
LSL,
|
||||||
|
LYD,
|
||||||
|
MAD,
|
||||||
|
MDL,
|
||||||
|
MGA,
|
||||||
|
MKD,
|
||||||
|
MMK,
|
||||||
|
MNT,
|
||||||
|
MOP,
|
||||||
|
MRO,
|
||||||
|
MRU,
|
||||||
|
MUR,
|
||||||
|
MVR,
|
||||||
|
MWK,
|
||||||
|
MXN,
|
||||||
|
MYR,
|
||||||
|
MZN,
|
||||||
|
NAD,
|
||||||
|
NGN,
|
||||||
|
NIO,
|
||||||
|
NOK,
|
||||||
|
NPR,
|
||||||
|
NZD,
|
||||||
|
OMR,
|
||||||
|
PAB,
|
||||||
|
PEN,
|
||||||
|
PGK,
|
||||||
|
PHP,
|
||||||
|
PKR,
|
||||||
PLN,
|
PLN,
|
||||||
EUR,
|
PYG,
|
||||||
|
QAR,
|
||||||
|
RON,
|
||||||
|
RSD,
|
||||||
|
RUB,
|
||||||
|
RWF,
|
||||||
|
SAR,
|
||||||
|
SBD,
|
||||||
|
SCR,
|
||||||
|
SDG,
|
||||||
|
SEK,
|
||||||
|
SGD,
|
||||||
|
SHP,
|
||||||
|
SLE,
|
||||||
|
SOS,
|
||||||
|
SRD,
|
||||||
|
SSP,
|
||||||
|
STN,
|
||||||
|
SVC,
|
||||||
|
SYP,
|
||||||
|
SZL,
|
||||||
|
THB,
|
||||||
|
TJS,
|
||||||
|
TMT,
|
||||||
|
TND,
|
||||||
|
TOP,
|
||||||
|
TRY,
|
||||||
|
TTD,
|
||||||
|
TWD,
|
||||||
|
TZS,
|
||||||
|
UAH,
|
||||||
|
UGX,
|
||||||
USD,
|
USD,
|
||||||
RON;
|
UYU,
|
||||||
|
UZS,
|
||||||
|
VES,
|
||||||
|
VND,
|
||||||
|
VUV,
|
||||||
|
WST,
|
||||||
|
XAF,
|
||||||
|
XAG,
|
||||||
|
XAU,
|
||||||
|
XCD,
|
||||||
|
XCG,
|
||||||
|
XDR,
|
||||||
|
XOF,
|
||||||
|
XPD,
|
||||||
|
XPF,
|
||||||
|
XPT,
|
||||||
|
YER,
|
||||||
|
ZAR,
|
||||||
|
ZMW,
|
||||||
|
ZWG;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun default(): Currencies {
|
fun default(): Currencies {
|
||||||
|
|||||||
Reference in New Issue
Block a user