make units configurable in buildconfig

This commit is contained in:
Minecon724 2024-08-15 16:10:00 +02:00
parent 9d43dcfb9b
commit 88095d1edb
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 10 additions and 9 deletions

View file

@ -23,6 +23,9 @@ android {
vectorDrawables {
useSupportLibrary = true
}
buildConfigField("String", "CURRENCY_UNIT", "\"zł\"")
buildConfigField("String", "CURRENCY_CENT", "\"gr\"")
}
buildTypes {
@ -43,6 +46,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.15"

View file

@ -133,7 +133,7 @@ fun BalanceView(balance: Int) {
fontSize = 32.sp
)
Text(
text = "",
text = BuildConfig.CURRENCY_UNIT,
fontSize = 14.sp
)
}
@ -270,10 +270,7 @@ fun AddWalletButton(
fun formatCurrency(units: Int): String {
if (units < 100) {
return "$units gr"
return "$units ${BuildConfig.CURRENCY_CENT}"
}
if (units % 100 == 0) {
return "%d zł".format(units / 100)
}
return "%.2f zł".format(units / 100.0)
return "%.2f %s".format(units / 100.0, BuildConfig.CURRENCY_UNIT)
}

View file

@ -150,7 +150,7 @@ fun App(
fontSize = 32.sp
)
Text(
text = "",
text = BuildConfig.CURRENCY_UNIT,
fontSize = 14.sp
)
}
@ -170,7 +170,7 @@ fun TransactionList(viewModel: WalletViewModel) {
items(transactions) {
Card(
modifier = Modifier
.width(200.dp)
.width(250.dp)
.padding(8.dp)
) {
Row(
@ -186,7 +186,7 @@ fun TransactionList(viewModel: WalletViewModel) {
.weight(1f))
Text(
text = "%.2f".format(it.value / 100.0),
text = "%.2f %s".format(it.value / 100.0, BuildConfig.CURRENCY_UNIT),
color = if (it.value < 0) MaterialTheme.colorScheme.error else Color.Unspecified
)
}