]> git.ktnx.net Git - mobile-ledger-staging.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
fix many lint errors/warnings
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryAdapter.java
index 5ffc62f544389cee71151b65aeb1dbf7a3e65c57..30025c2876d7cded8cd12cd9034718bb086e6eb6 100644 (file)
@@ -37,20 +37,26 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.DbOpQueue;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.MainModel;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Locker;
+import net.ktnx.mobileledger.utils.Logger;
 
 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.LedgerRowHolder> {
     public static final int AMOUNT_LIMIT = 3;
-    private AsyncListDiffer<LedgerAccount> listDiffer;
-    AccountSummaryAdapter() {
+    private final AsyncListDiffer<LedgerAccount> listDiffer;
+    private final MainModel model;
+    AccountSummaryAdapter(MainModel model) {
+        this.model = model;
+
         listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback<LedgerAccount>() {
             @Override
             public boolean areItemsTheSame(@NotNull LedgerAccount oldItem,
@@ -86,12 +92,12 @@ public class AccountSummaryAdapter
     public void setAccounts(List<LedgerAccount> newList) {
         listDiffer.submitList(newList);
     }
-    static class LedgerRowHolder extends RecyclerView.ViewHolder {
-        TextView tvAccountName, tvAccountAmounts;
-        ConstraintLayout row;
-        View expanderContainer;
-        ImageView expander;
-        View accountExpanderContainer;
+    class LedgerRowHolder extends RecyclerView.ViewHolder {
+        final TextView tvAccountName, tvAccountAmounts;
+        final ConstraintLayout row;
+        final View expanderContainer;
+        final ImageView expander;
+        final View accountExpanderContainer;
         LedgerAccount mAccount;
         public LedgerRowHolder(@NonNull View itemView) {
             super(itemView);
@@ -126,8 +132,8 @@ public class AccountSummaryAdapter
             if (profile == null) {
                 return;
             }
-            try (Locker ignored = profile.lockAccountsForWriting()) {
-                LedgerAccount realAccount = profile.locateAccount(mAccount.getName());
+            try (Locker ignored = model.lockAccountsForWriting()) {
+                LedgerAccount realAccount = model.locateAccount(mAccount.getName());
                 if (realAccount == null)
                     return;
 
@@ -136,7 +142,7 @@ public class AccountSummaryAdapter
             }
             expanderContainer.animate()
                              .rotation(mAccount.isExpanded() ? 0 : 180);
-            profile.updateDisplayedAccounts();
+            model.updateDisplayedAccounts();
 
             DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
                     new Object[]{mAccount.isExpanded(), mAccount.getName(), profile.getUuid()
@@ -172,14 +178,11 @@ public class AccountSummaryAdapter
             final String accountName = mAccount.getName();
             builder.setTitle(accountName);
             builder.setItems(R.array.acc_ctx_menu, (dialog, which) -> {
-                switch (which) {
-                    case 0:
-                        // show transactions
-                        activity.showAccountTransactions(accountName);
-                        break;
-                    default:
-                        throw new RuntimeException(
-                                String.format("Unknown menu item id (%d)", which));
+                if (which == 0) {// show transactions
+                    activity.showAccountTransactions(accountName);
+                }
+                else {
+                    throw new RuntimeException(String.format("Unknown menu item id (%d)", which));
                 }
                 dialog.dismiss();
             });
@@ -187,6 +190,7 @@ public class AccountSummaryAdapter
             return true;
         }
         public void bindToAccount(LedgerAccount acc) {
+            Logger.debug("accounts", String.format(Locale.US, "Binding to '%s'", acc.getName()));
             Context ctx = row.getContext();
             Resources rm = ctx.getResources();
             mAccount = acc;