Skip to content

Commit

Permalink
Merge pull request #9 from DennisBauer/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
DennisBauer authored Sep 24, 2023
2 parents 2d6fd92 + 2b21edc commit 3adb1e8
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

- run: |
echo "Run, Build Application"
./gradlew build
./gradlew assembleDebug test lint
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
Expand Down
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,38 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = "0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

signingConfigs {
create("release") {
storeFile = file("keystore/android_keystore.jks")
storePassword = System.getenv("SIGNING_STORE_PASSWORD")
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
}
}

buildTypes {
release {
named("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
applicationVariants.all {
outputs.forEach { output ->
if (output is com.android.build.gradle.internal.api.BaseVariantOutputImpl) {
output.outputFileName = "${rootProject.name}_$versionName.apk"
}
}
}
signingConfig = signingConfigs.getByName("release")
}
}
compileOptions {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/de/dbauer/expensetracker/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package de.dbauer.expensetracker

fun Float.toValueString(): String {
return "%.2f".format(this)
import java.text.NumberFormat

fun Float.toCurrencyString(): String {
return NumberFormat.getCurrencyInstance().format(this)
}

fun Float.toLocalString(): String {
return NumberFormat.getInstance().let {
it.minimumFractionDigits = 2
it.format(this)
}
}

fun String.toFloatIgnoreSeparator(): Float {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/de/dbauer/expensetracker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ private fun MainActivityContentPreview() {
id = 0,
name = "Netflix",
description = "My Netflix description",
priceValue = 9.99f,
price = 9.99f,
),
RecurringExpenseData(
id = 1,
name = "Disney Plus",
description = "My Disney Plus description",
priceValue = 5f,
price = 5f,
),
RecurringExpenseData(
id = 2,
name = "Amazon Prime",
description = "My Disney Plus description",
priceValue = 7.95f,
price = 7.95f,
),
),
onRecurringExpenseAdded = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package de.dbauer.expensetracker.data

import de.dbauer.expensetracker.toValueString

data class RecurringExpenseData(
val id: Int,
val name: String,
val description: String,
val priceValue: Float,
) {
val priceString = "${priceValue.toValueString()}" // TODO: Make currency dynamic
}
val price: Float,
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import androidx.compose.ui.unit.dp
import de.dbauer.expensetracker.R
import de.dbauer.expensetracker.data.RecurringExpenseData
import de.dbauer.expensetracker.toFloatIgnoreSeparator
import de.dbauer.expensetracker.toValueString
import de.dbauer.expensetracker.toLocalString
import de.dbauer.expensetracker.ui.theme.ExpenseTrackerTheme

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -104,7 +104,7 @@ private fun EditRecurringExpenseInternal(
mutableStateOf(TextFieldValue(currentData?.description ?: ""))
}
var priceState by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue(currentData?.priceValue?.toValueString() ?: ""))
mutableStateOf(TextFieldValue(currentData?.price?.toLocalString() ?: ""))
}
val priceInputError =
rememberSaveable {
Expand Down Expand Up @@ -166,7 +166,7 @@ private fun EditRecurringExpenseInternal(
CustomTextField(
value = priceState,
onValueChange = { priceState = it },
placeholder = stringResource(R.string.edit_expense_price_placeholder),
placeholder = 0f.toLocalString(),
keyboardOptions =
KeyboardOptions(
keyboardType = KeyboardType.Decimal,
Expand Down Expand Up @@ -320,7 +320,7 @@ private fun onConfirmClicked(
id = currentData?.id ?: 0,
name = name,
description = description,
priceValue = price.toFloatIgnoreSeparator(),
price = price.toFloatIgnoreSeparator(),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.dbauer.expensetracker.R
import de.dbauer.expensetracker.data.RecurringExpenseData
import de.dbauer.expensetracker.toCurrencyString
import de.dbauer.expensetracker.ui.theme.ExpenseTrackerTheme
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
Expand Down Expand Up @@ -151,7 +152,7 @@ private fun RecurringExpense(
}
}
Text(
text = recurringExpenseData.priceString,
text = recurringExpenseData.price.toCurrencyString(),
style = MaterialTheme.typography.headlineSmall,
)
}
Expand All @@ -173,21 +174,21 @@ private fun RecurringExpenseOverviewPreview() {
id = 0,
name = "Netflix",
description = "My Netflix description",
priceValue = 9.99f,
price = 9.99f,
),
RecurringExpenseData(
id = 1,
name = "Disney Plus",
description =
"My Disney Plus very very very very very " +
"very very very very long description",
priceValue = 5f,
price = 5f,
),
RecurringExpenseData(
id = 2,
name = "Amazon Prime with a long name",
description = "",
priceValue = 7.95f,
price = 7.95f,
),
),
onItemClicked = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import de.dbauer.expensetracker.data.RecurringExpenseData
import de.dbauer.expensetracker.toValueString
import de.dbauer.expensetracker.toCurrencyString
import de.dbauer.expensetracker.viewmodel.database.ExpenseRepository
import de.dbauer.expensetracker.viewmodel.database.RecurringExpense
import kotlinx.collections.immutable.ImmutableList
Expand Down Expand Up @@ -42,7 +42,7 @@ class MainActivityViewModel(
id = it.id,
name = it.name!!,
description = it.description!!,
priceValue = it.price!!,
price = it.price!!,
),
)
}
Expand All @@ -58,7 +58,7 @@ class MainActivityViewModel(
id = 0,
name = recurringExpense.name,
description = recurringExpense.description,
price = recurringExpense.priceValue,
price = recurringExpense.price,
),
)
}
Expand All @@ -71,7 +71,7 @@ class MainActivityViewModel(
id = recurringExpense.id,
name = recurringExpense.name,
description = recurringExpense.description,
price = recurringExpense.priceValue,
price = recurringExpense.price,
),
)
}
Expand All @@ -84,7 +84,7 @@ class MainActivityViewModel(
id = recurringExpense.id,
name = recurringExpense.name,
description = recurringExpense.description,
price = recurringExpense.priceValue,
price = recurringExpense.price,
),
)
}
Expand All @@ -93,11 +93,11 @@ class MainActivityViewModel(
private fun updateExpenseSummary() {
var price = 0f
_recurringExpenseData.forEach {
price += it.priceValue
price += it.price
}
_weeklyExpense = "${(price / 30f).toValueString()}" // TODO: Make currency dynamic
_monthlyExpense = "${price.toValueString()}" // TODO: Make currency dynamic
_yearlyExpense = "${(price * 12).toValueString()}" // TODO: Make currency dynamic
_weeklyExpense = (price / 30f).toCurrencyString()
_monthlyExpense = price.toCurrencyString()
_yearlyExpense = (price * 12).toCurrencyString()
}

companion object {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
<string name="edit_expense_name">Name</string>
<string name="edit_expense_name_placeholder">e.g. Netflix</string>
<string name="edit_expense_price">Price</string>
<string name="edit_expense_price_placeholder">0,00</string>
</resources>
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ dependencyResolutionManagement {
}
}

rootProject.name = "Recurring Expense Tracker"
rootProject.name = "RecurringExpenseTracker"
include(":app")

0 comments on commit 3adb1e8

Please sign in to comment.