/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
* This file is part of MoLe.
* MoLe is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.TransactionListItem;
+
+import java.util.Observer;
class TransactionRowHolder extends RecyclerView.ViewHolder {
- TextView tvDescription;
- TextView tvComment;
- LinearLayout tableAccounts;
- ConstraintLayout row;
- ConstraintLayout vDelimiter;
- CardView vTransaction;
- TextView tvDelimiterMonth, tvDelimiterDate;
- View vDelimiterThick;
+ final TextView tvDescription;
+ final TextView tvComment;
+ final LinearLayout tableAccounts;
+ final ConstraintLayout row;
+ final ConstraintLayout vDelimiter;
+ final CardView vTransaction;
+ final TextView tvDelimiterMonth, tvDelimiterDate;
+ final View vDelimiterThick;
+ final View vHeader;
+ final TextView tvLastUpdate;
+ TransactionListItem.Type lastType;
+ private Observer lastUpdateObserver;
public TransactionRowHolder(@NonNull View itemView) {
super(itemView);
this.row = itemView.findViewById(R.id.transaction_row);
this.tvDelimiterDate = itemView.findViewById(R.id.transaction_delimiter_date);
this.tvDelimiterMonth = itemView.findViewById(R.id.transaction_delimiter_month);
this.vDelimiterThick = itemView.findViewById(R.id.transaction_delimiter_thick);
+ this.vHeader = itemView.findViewById(R.id.last_update_container);
+ this.tvLastUpdate = itemView.findViewById(R.id.last_update_text);
+ }
+ void setLastUpdateText(String text) {
+ tvLastUpdate.setText(text);
+ }
+ void setType(TransactionListItem.Type newType) {
+ if (newType == lastType)
+ return;
+
+ switch (newType) {
+ case TRANSACTION:
+ vHeader.setVisibility(View.GONE);
+ vTransaction.setVisibility(View.VISIBLE);
+ vDelimiter.setVisibility(View.GONE);
+ break;
+ case DELIMITER:
+ vHeader.setVisibility(View.GONE);
+ vTransaction.setVisibility(View.GONE);
+ vDelimiter.setVisibility(View.VISIBLE);
+ break;
+ case HEADER:
+ vHeader.setVisibility(View.VISIBLE);
+ vTransaction.setVisibility(View.GONE);
+ vDelimiter.setVisibility(View.GONE);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + newType);
+ }
+
+ lastType = newType;
}
}