X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Faccount_summary%2FAccountSummaryFragment.java;h=c4f863cb5de753350a8b492d0f8e9be8e83bcb42;hb=e107a105c4588e0b84b1d626a6bed2daf4490c58;hp=174a4b2c775f0ed43fd25c3ac85bfbcfc0061800;hpb=748544f53147c7e811f8b11c081ed162a3870cb3;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 174a4b2c..c4f863cb 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,14 +25,15 @@ 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.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; @@ -66,17 +67,19 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { + public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) { debug("flow", "AccountSummaryFragment.onActivityCreated()"); - super.onActivityCreated(savedInstanceState); + super.onViewCreated(view, 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); + root = view.findViewById(R.id.account_root); LinearLayoutManager llm = new LinearLayoutManager(mainActivity); llm.setOrientation(RecyclerView.VERTICAL); root.setLayoutManager(llm); @@ -89,18 +92,17 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { manageFabOnScroll(); - refreshLayout = mainActivity.findViewById(R.id.account_swipe_refresh_layout); + refreshLayout = view.findViewById(R.id.account_swipe_refresh_layout); 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(), this::onAccountsChanged); + model.getDisplayedAccounts() + .observe(getViewLifecycleOwner(), this::onAccountsChanged); } - private void onAccountsChanged(List accounts) { + private void onAccountsChanged(List accounts) { Logger.debug("async-acc", String.format(Locale.US, "fragment: got new account list (%d items)", accounts.size()));