2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.ui.transaction_list;
20 import android.app.Activity;
21 import android.content.Context;
22 import android.graphics.Typeface;
23 import android.text.Spannable;
24 import android.text.SpannableString;
25 import android.text.style.StyleSpan;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.widget.LinearLayout;
29 import android.widget.TextView;
31 import androidx.annotation.ColorInt;
32 import androidx.annotation.NonNull;
33 import androidx.annotation.Nullable;
35 import net.ktnx.mobileledger.R;
36 import net.ktnx.mobileledger.databinding.TransactionListRowBinding;
37 import net.ktnx.mobileledger.model.LedgerTransaction;
38 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
39 import net.ktnx.mobileledger.model.TransactionListItem;
40 import net.ktnx.mobileledger.utils.Colors;
41 import net.ktnx.mobileledger.utils.Misc;
43 import java.util.Observer;
45 class TransactionRowHolder extends TransactionRowHolderBase {
46 private final TransactionListRowBinding b;
47 TransactionListItem.Type lastType;
48 private Observer lastUpdateObserver;
49 public TransactionRowHolder(@NonNull TransactionListRowBinding binding) {
50 super(binding.getRoot());
53 public void bind(@NonNull LedgerTransaction tr, @Nullable String boldAccountName) {
54 b.transactionRowDescription.setText(tr.getDescription());
55 String trComment = Misc.emptyIsNull(tr.getComment());
56 if (trComment == null)
57 b.transactionComment.setVisibility(View.GONE);
59 b.transactionComment.setText(trComment);
60 b.transactionComment.setVisibility(View.VISIBLE);
64 Context ctx = b.getRoot()
66 LayoutInflater inflater = ((Activity) ctx).getLayoutInflater();
67 for (LedgerTransactionAccount acc : tr.getAccounts()) {
68 LinearLayout row = (LinearLayout) b.transactionRowAccAmounts.getChildAt(rowIndex);
70 row = new LinearLayout(ctx);
71 inflater.inflate(R.layout.transaction_list_row_accounts_table_row, row);
72 b.transactionRowAccAmounts.addView(row);
75 TextView dummyText = row.findViewById(R.id.dummy_text);
76 TextView accName = row.findViewById(R.id.transaction_list_acc_row_acc_name);
77 TextView accComment = row.findViewById(R.id.transaction_list_acc_row_acc_comment);
78 TextView accAmount = row.findViewById(R.id.transaction_list_acc_row_acc_amount);
80 if ((boldAccountName != null) && acc.getAccountName()
81 .startsWith(boldAccountName))
83 accName.setTextColor(Colors.secondary);
84 accAmount.setTextColor(Colors.secondary);
86 SpannableString ss = new SpannableString(acc.getAccountName());
87 ss.setSpan(new StyleSpan(Typeface.BOLD), 0, boldAccountName.length(),
88 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
92 @ColorInt int textColor = dummyText.getTextColors()
94 accName.setTextColor(textColor);
95 accAmount.setTextColor(textColor);
96 accName.setText(acc.getAccountName());
99 String comment = acc.getComment();
100 if (comment != null && !comment.isEmpty()) {
101 accComment.setText(comment);
102 accComment.setVisibility(View.VISIBLE);
105 accComment.setVisibility(View.GONE);
107 accAmount.setText(acc.toString());
112 if (b.transactionRowAccAmounts.getChildCount() > rowIndex) {
113 b.transactionRowAccAmounts.removeViews(rowIndex,
114 b.transactionRowAccAmounts.getChildCount() - rowIndex);