]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
provide a common routine for running something on the main thread
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryAdapter.java
index 488af1f42ca13018af0df78735121c7765e83d40..6b8d0930f4920d10edfd62f7ec2e9df70a4faac2 100644 (file)
@@ -19,8 +19,6 @@ package net.ktnx.mobileledger.ui.account_summary;
 
 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;
@@ -149,7 +147,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                 throw new IllegalStateException("Unexpected value: " + viewType);
         }
 
-        Logger.debug("acc-ui", "Creating " + result);
+//        Logger.debug("acc-ui", "Creating " + result);
         return result;
     }
     @Override
@@ -162,7 +160,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;
@@ -214,8 +212,8 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
         @Override
         public void bind(AccountListItem item, @Nullable List<Object> payloads) {
             Resources r = itemView.getResources();
-            Logger.debug("acc", itemView.getContext()
-                                        .toString());
+//            Logger.debug("acc", itemView.getContext()
+//                                        .toString());
             ((AccountListItem.Header) item).getText()
                                            .observe((LifecycleOwner) itemView.getContext(),
                                                    b.lastUpdateText::setText);
@@ -259,7 +257,7 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
         @NotNull
         private LedgerAccount getAccount() {
             return listDiffer.getCurrentList()
-                             .get(getAdapterPosition())
+                             .get(getBindingAdapterPosition())
                              .getAccount();
         }
         private void toggleAmountsExpanded() {
@@ -312,8 +310,8 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                         changes.add((Change) p);
                 }
             }
-            debug("accounts",
-                    String.format(Locale.US, "Binding to '%s' to %s", acc.getName(), this));
+//            debug("accounts",
+//                    String.format(Locale.US, "Binding '%s' to %s", acc.getName(), this));
 
             Resources rm = b.getRoot()
                             .getContext()
@@ -335,9 +333,9 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAd
                 if (changes.has(Change.EXPANDED)) {
                     int wantedRotation = acc.isExpanded() ? 0 : 180;
                     if (b.accountExpanderContainer.getRotation() != wantedRotation) {
-                        Logger.debug("acc-ui",
-                                String.format(Locale.ROOT, "Rotating %s to %d", acc.getName(),
-                                        wantedRotation));
+//                        Logger.debug("acc-ui",
+//                                String.format(Locale.ROOT, "Rotating %s to %d", acc.getName(),
+//                                        wantedRotation));
                         b.accountExpanderContainer.animate()
                                                   .rotation(wantedRotation);
                     }