Skip to content

Commit

Permalink
Remove "removeIf" usages
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Mar 8, 2024
1 parent 802d028 commit 2028b05
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ class AddViewModel
) {
val result = ArrayList(postings.value!!)
result[index] = Triple(newAccount, result[index].second, result[index].third)
result.removeIf { it.first == "" && it.third == "" }
_postings.value = result
_postings.value = removeEmpty(result)
}

fun setCurrency(
Expand All @@ -209,8 +208,18 @@ class AddViewModel
) {
val result = ArrayList(postings.value!!)
result[index] = Triple(result[index].first, result[index].second, newAmount)
result.removeIf { it.first == "" && it.third == "" }
_postings.value = result
_postings.value = removeEmpty(result)
}

fun removeEmpty(postings: List<Triple<String, String, String>>): List<Triple<String, String, String>> {
val result = ArrayList<Triple<String, String, String>>()
for (p in postings) {
if (it.first != "" || it.third != "") {
result.add(p)
}
}
result.add(emptyPosting())
return result
}

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

0 comments on commit 2028b05

Please sign in to comment.