X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;ds=inline;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Ftransaction_list%2FTransactionRowHolder.java;h=0d41e19a1f93fa51003e16b29fb4f606a3911719;hb=d0c7376f092d1778ec8bab43cd2017eab723d521;hp=5e975969e678812c591671b044bd6b7ef95f24ee;hpb=a1d55154e1c9fb72fcd60de31d6e64e8d046f96d;p=mobile-ledger.git
diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
index 5e975969..0d41e19a 100644
--- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
+++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
@@ -1,40 +1,109 @@
/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of Mobile-Ledger.
- * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * Copyright © 2020 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
* the Free Software Foundation, either version 3 of the License, or
* (at your opinion), any later version.
*
- * Mobile-Ledger is distributed in the hope that it will be useful,
+ * MoLe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License terms for details.
*
* You should have received a copy of the GNU General Public License
- * along with Mobile-Ledger. If not, see .
+ * along with MoLe. If not, see .
*/
package net.ktnx.mobileledger.ui.transaction_list;
-import android.support.annotation.NonNull;
-import android.support.constraint.ConstraintLayout;
-import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
+import androidx.annotation.NonNull;
+import androidx.cardview.widget.CardView;
+import androidx.constraintlayout.widget.ConstraintLayout;
+import androidx.recyclerview.widget.RecyclerView;
+
import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.TransactionListItem;
+
+import java.util.Observer;
class TransactionRowHolder extends RecyclerView.ViewHolder {
- TextView tvDescription, tvDate;
- LinearLayout tableAccounts;
- ConstraintLayout row;
+ 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.tvDescription = itemView.findViewById(R.id.transaction_row_description);
- this.tvDate = itemView.findViewById(R.id.transaction_row_date);
+ this.tvComment = itemView.findViewById(R.id.transaction_comment);
this.tableAccounts = itemView.findViewById(R.id.transaction_row_acc_amounts);
+ this.vDelimiter = itemView.findViewById(R.id.transaction_delimiter);
+ this.vTransaction = itemView.findViewById(R.id.transaction_card_view);
+ 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);
+ }
+ private void initLastUpdateObserver() {
+ if (lastUpdateObserver != null)
+ return;
+
+ lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastTransactionsUpdateText.get());
+
+ Data.lastTransactionsUpdateText.addObserver(lastUpdateObserver);
+ }
+ void setLastUpdateText(String text) {
+ tvLastUpdate.setText(text);
+ }
+ private void dropLastUpdateObserver() {
+ if (lastUpdateObserver == null)
+ return;
+
+ Data.lastTransactionsUpdateText.deleteObserver(lastUpdateObserver);
+ lastUpdateObserver = null;
+ }
+ 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);
+ dropLastUpdateObserver();
+ break;
+ case DELIMITER:
+ vHeader.setVisibility(View.GONE);
+ vTransaction.setVisibility(View.GONE);
+ vDelimiter.setVisibility(View.VISIBLE);
+ dropLastUpdateObserver();
+ break;
+ case HEADER:
+ vHeader.setVisibility(View.VISIBLE);
+ vTransaction.setVisibility(View.GONE);
+ vDelimiter.setVisibility(View.GONE);
+ initLastUpdateObserver();
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + newType);
+ }
+
+ lastType = newType;
}
}