X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Ftransaction_list%2FTransactionListAdapter.java;h=febca0191ecb02525c8bd47b7205f26dcb8b76f5;hp=7004dd7d8d026aa1446bf6b64a51bc692460730b;hb=e12bae55fb75c0c30055dd34ded195e75feb3844;hpb=90706eb1669fb560578f49565939ad28059d12fe diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java index 7004dd7d..febca019 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java @@ -34,26 +34,57 @@ import android.widget.TextView; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; +import net.ktnx.mobileledger.model.TransactionListItem; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.MLDB; +import java.text.DateFormat; +import java.util.Date; + import static net.ktnx.mobileledger.utils.DimensionUtils.dp2px; public class TransactionListAdapter extends RecyclerView.Adapter { private String boldAccountName; public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) { - LedgerTransaction tr = TransactionListViewModel.getTransaction(position); - // in a race when transaction value is reduced, but the model hasn't been notified yet - // the view will disappear when the notifications reaches the model, so by simply omitting - // the out-of-range get() call nothing bad happens - just a to-be-deleted view remains - // a bit longer - if (tr == null) return; + TransactionListItem item = TransactionListViewModel.getTransactionListItem(position); + + if (item.getType() == TransactionListItem.Type.TRANSACTION) { + holder.vTransaction.setVisibility(View.VISIBLE); + holder.vDelimiter.setVisibility(View.GONE); + LedgerTransaction tr = item.getTransaction(); + // in a race when transaction value is reduced, but the model hasn't been notified yet + // the view will disappear when the notifications reaches the model, so by simply omitting + // the out-of-range get() call nothing bad happens - just a to-be-deleted view remains + // a bit longer + if (tr == null) return; + + LedgerTransaction previous = null; + TransactionListItem previousItem = null; + if (position > 0) + previousItem = TransactionListViewModel.getTransactionListItem(position - 1); // Log.d("transactions", String.format("Filling position %d with %d accounts", position, // tr.getAccounts().size())); - TransactionLoader loader = new TransactionLoader(); - loader.execute(new TransactionLoaderParams(tr, holder, position, boldAccountName)); + TransactionLoader loader = new TransactionLoader(); + loader.execute( + new TransactionLoaderParams(tr, previous, holder, position, boldAccountName)); + + // WORKAROUND what seems to be a bug in CardHolder somewhere + // when a view that was previously holding a delimiter is re-purposed + // occasionally it stays too short (not high enough) + holder.vTransaction.measure(View.MeasureSpec + .makeMeasureSpec(holder.itemView.getWidth(), View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + } + else { + Date date = item.getDate(); + holder.vTransaction.setVisibility(View.GONE); + holder.vDelimiter.setVisibility(View.VISIBLE); + holder.tvDelimiterDate.setText(DateFormat.getDateInstance().format(date)); + holder.tvDelimiterMonth + .setText(item.isMonthShown() ? Globals.monthNames[date.getMonth()] : ""); + } } @NonNull @@ -83,11 +114,18 @@ public class TransactionListAdapter extends RecyclerView.Adapter