From 2028b05e8593bfddf33591151688db163e9e1078 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Fri, 8 Mar 2024 20:28:35 +0100 Subject: [PATCH] Remove "removeIf" usages --- .../be/chvp/nanoledger/ui/add/AddViewModel.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt b/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt index 5b2e984..b1f377b 100644 --- a/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt +++ b/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt @@ -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( @@ -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>): List> { + val result = ArrayList>() + for (p in postings) { + if (it.first != "" || it.third != "") { + result.add(p) + } + } + result.add(emptyPosting()) + return result } fun emptyPosting(): Triple {