Skip to content

Commit

Permalink
Stop using some more modern Java constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Mar 4, 2024
1 parent 85ffca1 commit 913bb9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ class LedgerRepository
fileUri
?.let { context.contentResolver.openInputStream(it) }
?.let { BufferedReader(InputStreamReader(it)) }
?.use { it.lines().forEach { result.add(it) } }
?.use { reader ->
var line = reader.readLine()
while(line != null) {
result.add(line)
line = reader.readLine()
}
}
val extracted = extractTransactions(result)
_fileContents.postValue(result)
_transactions.postValue(extracted)
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ class AddViewModel
) {
val result = ArrayList(postings.value!!)
result[index] = Triple(newAccount, result[index].second, result[index].third)
result.removeIf { it.first == "" && it.third == "" }
result.add(emptyPosting())
_postings.value = result
val filteredResult = ArrayList<Triple<String, String, String>>()
for (triple in result) {
if (triple.first != "" || triple.third != "") {
filteredResult.add(triple)
}
}
filteredResult.add(emptyPosting())
_postings.value = filteredResult
}

fun setCurrency(
Expand All @@ -206,9 +211,14 @@ class AddViewModel
) {
val result = ArrayList(postings.value!!)
result[index] = Triple(result[index].first, result[index].second, newAmount)
result.removeIf { it.first == "" && it.third == "" }
result.add(emptyPosting())
_postings.value = result
val filteredResult = ArrayList<Triple<String, String, String>>()
for (triple in result) {
if (triple.first != "" || triple.third != "") {
filteredResult.add(triple)
}
}
filteredResult.add(emptyPosting())
_postings.value = filteredResult
}

fun emptyPosting(): Triple<String, String, String> {
Expand Down

0 comments on commit 913bb9e

Please sign in to comment.