X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Faccount_summary%2FAccountSummaryFragment.java;h=29003b820f484ea75c06bb24a15a578bc83eddd7;hb=5bba2c06a81c87327fdcf3f2a85c3206d932c2f9;hp=fdeb54804e26471bbb2117c1736c29f7b7018fd7;hpb=4f8b4f8bf16aaef182e1aac31a34f88a2adf5fa8;p=mobile-ledger.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 fdeb5480..29003b82 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,6 +25,7 @@ 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; @@ -32,7 +33,7 @@ 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.MainModel; import net.ktnx.mobileledger.ui.MobileLedgerListFragment; import net.ktnx.mobileledger.ui.activity.MainActivity; import net.ktnx.mobileledger.utils.Colors; @@ -70,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); @@ -93,18 +96,16 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged); refreshLayout.setOnRefreshListener(() -> { debug("ui", "refreshing accounts via swipe"); - Data.scheduleTransactionListRetrieval(mainActivity); + model.scheduleTransactionListRetrieval(); }); - MobileLedgerProfile profile = Data.getProfile(); - profile.getDisplayedAccounts() - .observe(getViewLifecycleOwner(), - (accounts) -> onAccountsChanged(profile, accounts)); + model.getDisplayedAccounts() + .observe(getViewLifecycleOwner(), this::onAccountsChanged); } - private void onAccountsChanged(MobileLedgerProfile profile, List accounts) { + private void onAccountsChanged(List accounts) { Logger.debug("async-acc", String.format(Locale.US, "fragment: got new account list (%d items)", accounts.size())); - modelAdapter.setAccounts(profile, accounts); + modelAdapter.setAccounts(accounts); } }