X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Faccount_summary%2FAccountSummaryFragment.java;h=9f2344fb605bbad3c2a09cc3a4110b9a64108592;hb=d08ab8235d0fd152c772b2dd5ffa1ca5747f67b1;hp=8eef8fbeaf3256ce9d984087760e4b3e39f82e67;hpb=233b37f00eb4abcda08cacade8ab6d13a8e0ebcf;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 8eef8fbe..9f2344fb 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -31,12 +31,17 @@ 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.ArrayList; + import static net.ktnx.mobileledger.utils.Logger.debug; public class AccountSummaryFragment extends MobileLedgerListFragment { @@ -46,14 +51,10 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { super.onCreate(savedInstanceState); debug("flow", "AccountSummaryFragment.onCreate()"); setHasOptionsMenu(true); - - Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(), - this::onBackgroundTaskRunningChanged); } public void onAttach(@NotNull Context context) { super.onAttach(context); debug("flow", "AccountSummaryFragment.onAttach()"); - mActivity = (MainActivity) context; } @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -68,30 +69,41 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { debug("flow", "AccountSummaryFragment.onActivityCreated()"); super.onActivityCreated(savedInstanceState); + Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(), + this::onBackgroundTaskRunningChanged); + modelAdapter = new AccountSummaryAdapter(); + MainActivity mainActivity = getMainActivity(); - mActivity.mAccountSummaryFragment = this; - root = mActivity.findViewById(R.id.account_root); - LinearLayoutManager llm = new LinearLayoutManager(mActivity); + root = mainActivity.findViewById(R.id.account_root); + LinearLayoutManager llm = new LinearLayoutManager(mainActivity); llm.setOrientation(RecyclerView.VERTICAL); root.setLayoutManager(llm); root.setAdapter(modelAdapter); DividerItemDecoration did = - new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL); + new DividerItemDecoration(mainActivity, DividerItemDecoration.VERTICAL); root.addItemDecoration(did); - mActivity.fabShouldShow(); + mainActivity.fabShouldShow(); manageFabOnScroll(); - swiper = mActivity.findViewById(R.id.account_swiper); + swiper = mainActivity.findViewById(R.id.account_swiper); Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged); swiper.setOnRefreshListener(() -> { debug("ui", "refreshing accounts via swipe"); - Data.scheduleTransactionListRetrieval(mActivity); + Data.scheduleTransactionListRetrieval(mainActivity); }); - Data.accounts.addObserver( - (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged())); + Data.profile.observe(getViewLifecycleOwner(), profile -> profile.getAccounts() + .observe( + getViewLifecycleOwner(), + (accounts) -> onAccountsChanged( + profile, + accounts))); + } + private void onAccountsChanged(MobileLedgerProfile profile, ArrayList accounts) { + Logger.debug("async-acc", "fragment: got new account list"); + modelAdapter.setAccounts(profile, accounts); } }