Skip to content

Commit

Permalink
Make sure actions on a transaction occur with the right transaction w…
Browse files Browse the repository at this point in the history
…hen filtered (#185)

Fixes #184.
  • Loading branch information
chvp authored Oct 5, 2024
1 parent 5e03352 commit 9723a16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/src/main/java/be/chvp/nanoledger/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ fun MainContent(
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(transactions?.size ?: 0) {
val index = transactions!!.size - it - 1
val (originalIndex, transaction) = transactions!![index]
TransactionCard(
transactions!![index],
index == selected,
{ mainViewModel.toggleSelect(index) },
transaction,
originalIndex == selected,
{ mainViewModel.toggleSelect(originalIndex) },
Modifier.fillMaxWidth().padding(
8.dp,
if (it == 0) 8.dp else 4.dp,
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/be/chvp/nanoledger/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class MainViewModel
val filteredTransactions =
transactions.switchMap { ts ->
_query.map { query ->
val indexedTs = ts.mapIndexed { index, t -> index to t }
if (query.equals("")) {
ts
indexedTs
} else {
ts.filter { t -> t.contains(query) }
indexedTs.filter { (i, t) -> t.contains(query) }
}
}
}
Expand Down

0 comments on commit 9723a16

Please sign in to comment.