X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Faccount_summary%2FAccountSummaryFragment.java;h=5f4ffe57f2c4213188c526ceb311df6af03c6b54;hb=2d85826653a8ba3e619afc83c5c91216a7fdb0b6;hp=79253bfb238faedd682e8dcdcefebca2ae96ca2c;hpb=b54a11eca1e4d0a03a3076047dc77f68666d4338;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 79253bfb..5f4ffe57 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -25,18 +25,25 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.R; +import net.ktnx.mobileledger.model.AccountListItem; import net.ktnx.mobileledger.model.Data; +import net.ktnx.mobileledger.ui.MainModel; 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 { @@ -64,10 +71,12 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { debug("flow", "AccountSummaryFragment.onActivityCreated()"); super.onActivityCreated(savedInstanceState); + MainModel model = new ViewModelProvider(requireActivity()).get(MainModel.class); + Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(), this::onBackgroundTaskRunningChanged); - modelAdapter = new AccountSummaryAdapter(); + modelAdapter = new AccountSummaryAdapter(model); MainActivity mainActivity = getMainActivity(); root = mainActivity.findViewById(R.id.account_root); @@ -83,14 +92,20 @@ 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); + model.scheduleTransactionListRetrieval(); }); - Data.accounts.addObserver( - (o, arg) -> mainActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged())); + model.getDisplayedAccounts() + .observe(getViewLifecycleOwner(), this::onAccountsChanged); + } + private void onAccountsChanged(List accounts) { + Logger.debug("async-acc", + String.format(Locale.US, "fragment: got new account list (%d items)", + accounts.size())); + modelAdapter.setAccounts(accounts); } }