]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryAdapter.java
index 3a6130754db2dc8e2f064daf2516886733529287..dcc16f3678ed3885605d4b85de77653f1f957b9c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021 Damyan Ivanov.
+ * Copyright © 2024 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
 
 package net.ktnx.mobileledger.ui.account_summary;
 
+import static net.ktnx.mobileledger.utils.Logger.debug;
+
 import android.content.res.Resources;
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -35,6 +34,7 @@ import androidx.recyclerview.widget.DiffUtil;
 import androidx.recyclerview.widget.RecyclerView;
 
 import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.dao.BaseDAO;
 import net.ktnx.mobileledger.databinding.AccountListRowBinding;
 import net.ktnx.mobileledger.databinding.AccountListSummaryRowBinding;
 import net.ktnx.mobileledger.db.Account;
@@ -50,8 +50,6 @@ import org.jetbrains.annotations.NotNull;
 import java.util.List;
 import java.util.Locale;
 
-import static net.ktnx.mobileledger.utils.Logger.debug;
-
 public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.RowHolder> {
     public static final int AMOUNT_LIMIT = 3;
     private static final int ITEM_TYPE_HEADER = 1;
@@ -68,8 +66,10 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                                            @NonNull AccountListItem newItem) {
                 Change changes = new Change();
 
-                final LedgerAccount oldAcc = oldItem.getAccount();
-                final LedgerAccount newAcc = newItem.getAccount();
+                final LedgerAccount oldAcc = oldItem.toAccount()
+                                                    .getAccount();
+                final LedgerAccount newAcc = newItem.toAccount()
+                                                    .getAccount();
 
                 if (!Misc.equalStrings(oldAcc.getName(), newAcc.getName()))
                     changes.add(Change.NAME);
@@ -99,8 +99,10 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                 if (oldType == AccountListItem.Type.HEADER)
                     return true;
 
-                return oldItem.getAccount()
-                              .getId() == newItem.getAccount()
+                return oldItem.toAccount()
+                              .getAccount()
+                              .getId() == newItem.toAccount()
+                                                 .getAccount()
                                                  .getId();
             }
             @Override
@@ -116,6 +118,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
             return 0;
         return listDiffer.getCurrentList()
                          .get(position)
+                         .toAccount()
                          .getAccount()
                          .getId();
     }
@@ -162,7 +165,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
         return (position == 0) ? ITEM_TYPE_HEADER : ITEM_TYPE_ACCOUNT;
     }
     public void setAccounts(List<AccountListItem> newList) {
-        new Handler(Looper.getMainLooper()).post(() -> listDiffer.submitList(newList));
+        Misc.onMainThread(() -> listDiffer.submitList(newList));
     }
     static class Change {
         static final int NAME = 1;
@@ -245,7 +248,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                 return;
             debug("accounts", "Account expander clicked");
 
-            AsyncTask.execute(() -> {
+            BaseDAO.runAsync(() -> {
                 Account dbo = account.toDBO();
                 dbo.setExpanded(!dbo.isExpanded());
                 Logger.debug("accounts",
@@ -260,6 +263,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
         private LedgerAccount getAccount() {
             return listDiffer.getCurrentList()
                              .get(getBindingAdapterPosition())
+                             .toAccount()
                              .getAccount();
         }
         private void toggleAmountsExpanded() {
@@ -277,7 +281,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                 b.accountRowAmountsExpanderContainer.setVisibility(View.VISIBLE);
             }
 
-            AsyncTask.execute(() -> {
+            BaseDAO.runAsync(() -> {
                 Account dbo = account.toDBO();
                 DB.get()
                   .getAccountDAO()
@@ -303,7 +307,8 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
         }
         @Override
         public void bind(AccountListItem item, @Nullable List<Object> payloads) {
-            LedgerAccount acc = item.getAccount();
+            LedgerAccount acc = item.toAccount()
+                                    .getAccount();
 
             Change changes = new Change();
             if (payloads != null) {
@@ -324,7 +329,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
 
             if (changes.has(Change.LEVEL)) {
                 ConstraintLayout.LayoutParams lp =
-                        (ConstraintLayout.LayoutParams) b.accountNameLayout.getLayoutParams();
+                        (ConstraintLayout.LayoutParams) b.flowWrapper.getLayoutParams();
                 lp.setMarginStart(
                         acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 3);
             }