From 88095d1edb2ed71c66457cbb9f9ea641cc3375f7 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 15 Aug 2024 16:10:00 +0200 Subject: [PATCH] make units configurable in buildconfig --- app/build.gradle.kts | 4 ++++ app/src/main/java/eu/m724/coincounter/MainActivity.kt | 9 +++------ app/src/main/java/eu/m724/coincounter/WalletActivity.kt | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 11d703f..5818509 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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" diff --git a/app/src/main/java/eu/m724/coincounter/MainActivity.kt b/app/src/main/java/eu/m724/coincounter/MainActivity.kt index 9b92518..243fdea 100644 --- a/app/src/main/java/eu/m724/coincounter/MainActivity.kt +++ b/app/src/main/java/eu/m724/coincounter/MainActivity.kt @@ -133,7 +133,7 @@ fun BalanceView(balance: Int) { fontSize = 32.sp ) Text( - text = "zł", + 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) } \ No newline at end of file diff --git a/app/src/main/java/eu/m724/coincounter/WalletActivity.kt b/app/src/main/java/eu/m724/coincounter/WalletActivity.kt index 924287e..bc42dbe 100644 --- a/app/src/main/java/eu/m724/coincounter/WalletActivity.kt +++ b/app/src/main/java/eu/m724/coincounter/WalletActivity.kt @@ -150,7 +150,7 @@ fun App( fontSize = 32.sp ) Text( - text = "zł", + 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 ) }