]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
drop unneeded profile parameter
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryFragment.java
index 79253bfb238faedd682e8dcdcefebca2ae96ca2c..174a4b2c775f0ed43fd25c3ac85bfbcfc0061800 100644 (file)
@@ -31,12 +31,18 @@ import androidx.recyclerview.widget.RecyclerView;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Colors;
+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 AccountSummaryFragment extends MobileLedgerListFragment {
@@ -83,14 +89,21 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
 
         manageFabOnScroll();
 
-        swiper = mainActivity.findViewById(R.id.account_swiper);
+        refreshLayout = mainActivity.findViewById(R.id.account_swipe_refresh_layout);
         Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
-        swiper.setOnRefreshListener(() -> {
+        refreshLayout.setOnRefreshListener(() -> {
             debug("ui", "refreshing accounts via swipe");
             Data.scheduleTransactionListRetrieval(mainActivity);
         });
 
-        Data.accounts.addObserver(
-                (o, arg) -> mainActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+        MobileLedgerProfile profile = Data.getProfile();
+        profile.getDisplayedAccounts()
+               .observe(getViewLifecycleOwner(), this::onAccountsChanged);
+    }
+    private void onAccountsChanged(List<LedgerAccount> accounts) {
+        Logger.debug("async-acc",
+                String.format(Locale.US, "fragment: got new account list (%d items)",
+                        accounts.size()));
+        modelAdapter.setAccounts(accounts);
     }
 }