import net.ktnx.mobileledger.App;
import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.TransactionListItem;
import java.util.TimeZone;
public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowHolder> {
- private MainModel model;
- private AsyncListDiffer<TransactionListItem> listDiffer;
+ private final MainModel model;
+ private final AsyncListDiffer<TransactionListItem> listDiffer;
public TransactionListAdapter(MainModel model) {
super();
this.model = model;
return oldItem.getTransaction()
.getId() == newItem.getTransaction()
.getId();
+ case HEADER:
+ return true; // there can be only one header
default:
throw new IllegalStateException(
String.format(Locale.US, "Unexpected transaction item type %s",
case TRANSACTION:
return oldItem.getTransaction()
.equals(newItem.getTransaction());
+ case HEADER:
+ // headers don't differ in their contents. they observe the last update
+ // date and react to its changes
+ return true;
default:
throw new IllegalStateException(
String.format(Locale.US, "Unexpected transaction item type %s",
if (item == null)
return;
- switch (item.getType()) {
+ final TransactionListItem.Type newType = item.getType();
+ holder.setType(newType);
+
+ switch (newType) {
case TRANSACTION:
- holder.vTransaction.setVisibility(View.VISIBLE);
- holder.vDelimiter.setVisibility(View.GONE);
LedgerTransaction tr = item.getTransaction();
// debug("transactions", String.format("Filling position %d with %d
break;
case DELIMITER:
SimpleDate date = item.getDate();
- holder.vTransaction.setVisibility(View.GONE);
- holder.vDelimiter.setVisibility(View.VISIBLE);
holder.tvDelimiterDate.setText(DateFormat.getDateInstance()
.format(date.toDate()));
if (item.isMonthShown()) {
holder.vDelimiterThick.setVisibility(View.GONE);
}
break;
+ case HEADER:
+ holder.setLastUpdateText(Data.lastTransactionsUpdateText.get());
+
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + newType);
}
}
-
@NonNull
@Override
public TransactionRowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
}
private static class TransactionLoaderParams {
- LedgerTransaction transaction;
- TransactionRowHolder holder;
- int position;
- String boldAccountName;
+ final LedgerTransaction transaction;
+ final TransactionRowHolder holder;
+ final int position;
+ final String boldAccountName;
TransactionLoaderParams(LedgerTransaction transaction, TransactionRowHolder holder,
int position, String boldAccountName) {
this.transaction = transaction;