From: Damyan Ivanov Date: Tue, 29 Jan 2019 19:56:38 +0000 (+0200) Subject: make AccountSummaryViewModel a static class X-Git-Tag: v0.4.1~2 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=9f35f59fcffd6b9778b36bf31f8b94d91411664f;p=mobile-ledger.git make AccountSummaryViewModel a static class creating an instance fails in release builds and there is nothing dynamic there so a static class seems ok --- 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 6ce84c78..b6943adc 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 @@ -17,7 +17,6 @@ package net.ktnx.mobileledger.ui.account_summary; -import android.arch.lifecycle.ViewModelProviders; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -50,7 +49,6 @@ import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_O public class AccountSummaryFragment extends MobileLedgerListFragment { MenuItem mShowOnlyStarred; - private AccountSummaryViewModel model; private AccountSummaryAdapter modelAdapter; private Menu optMenu; private FloatingActionButton fab; @@ -98,7 +96,6 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Log.d("flow", "AccountSummaryFragment.onActivityCreated()"); super.onActivityCreated(savedInstanceState); - model = ViewModelProviders.of(this).get(AccountSummaryViewModel.class); modelAdapter = new AccountSummaryAdapter(); root = mActivity.findViewById(R.id.account_root); @@ -164,13 +161,13 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Data.accounts.addObserver( (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged())); Data.profile.addObserver( - (o, arg) -> mActivity.runOnUiThread(() -> model.scheduleAccountListReload())); + (o, arg) -> mActivity.runOnUiThread(() -> AccountSummaryViewModel.scheduleAccountListReload())); update_account_table(); } private void update_account_table() { if (this.getContext() == null) return; - model.scheduleAccountListReload(); + AccountSummaryViewModel.scheduleAccountListReload(); } void stopSelection() { modelAdapter.stopSelection(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryViewModel.java index 2234d3cd..574665b0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryViewModel.java @@ -35,7 +35,7 @@ class AccountSummaryViewModel extends ViewModel { task.execute( new CommitAccountsTaskParams(Data.accounts.get(), Data.optShowOnlyStarred.get())); } - void scheduleAccountListReload() { + static void scheduleAccountListReload() { if (Data.profile.get() == null) return; UAT task = new UAT();