]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListDelimiterRowHolder.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / transaction_list / TransactionListDelimiterRowHolder.java
1 /*
2  * Copyright © 2024 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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.ui.transaction_list;
19
20 import android.view.View;
21
22 import androidx.constraintlayout.widget.ConstraintLayout;
23
24 import net.ktnx.mobileledger.App;
25 import net.ktnx.mobileledger.databinding.TransactionDelimiterBinding;
26 import net.ktnx.mobileledger.model.TransactionListItem;
27 import net.ktnx.mobileledger.utils.DimensionUtils;
28 import net.ktnx.mobileledger.utils.Globals;
29 import net.ktnx.mobileledger.utils.SimpleDate;
30
31 import java.text.DateFormat;
32 import java.util.GregorianCalendar;
33 import java.util.TimeZone;
34
35 class TransactionListDelimiterRowHolder extends TransactionRowHolderBase {
36     private final TransactionDelimiterBinding b;
37     TransactionListDelimiterRowHolder(TransactionDelimiterBinding binding) {
38         super(binding.getRoot());
39         b = binding;
40     }
41     public void bind(TransactionListItem item) {
42         SimpleDate date = item.getDate();
43         b.transactionDelimiterDate.setText(DateFormat.getDateInstance()
44                                                      .format(date.toDate()));
45         if (item.isMonthShown()) {
46             GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
47             cal.setTime(date.toDate());
48             App.prepareMonthNames();
49             b.transactionDelimiterMonth.setText(
50                     Globals.monthNames[cal.get(GregorianCalendar.MONTH)]);
51             b.transactionDelimiterMonth.setVisibility(View.VISIBLE);
52             b.transactionDelimiterThick.setVisibility(View.VISIBLE);
53             ConstraintLayout.LayoutParams lp =
54                     (ConstraintLayout.LayoutParams) b.transactionDelimiterThick.getLayoutParams();
55             lp.height = DimensionUtils.dp2px(b.getRoot()
56                                               .getContext(), 4);
57             b.transactionDelimiterThick.setLayoutParams(lp);
58         }
59         else {
60             b.transactionDelimiterMonth.setVisibility(View.GONE);
61             ConstraintLayout.LayoutParams lp =
62                     (ConstraintLayout.LayoutParams) b.transactionDelimiterThick.getLayoutParams();
63             lp.height = DimensionUtils.dp2px(b.getRoot()
64                                               .getContext(), 1.3f);
65             b.transactionDelimiterThick.setLayoutParams(lp);
66             b.transactionDelimiterThick.setVisibility(View.VISIBLE);
67         }
68
69     }
70 }