From d2716a2305d7a6505f56aeb66f104c92f090ad21 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 31 Mar 2024 18:06:47 +0300 Subject: [PATCH] store the 'Show zero-balance accounts' setting in the preferences --- app/src/main/java/net/ktnx/mobileledger/App.java | 13 ++++++++++++- .../ui/account_summary/AccountSummaryFragment.java | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index a9a416e7..b0c8e1f7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/App.java +++ b/app/src/main/java/net/ktnx/mobileledger/App.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 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 @@ -41,6 +41,7 @@ public class App extends Application { public static final String PREF_NAME = "MoLe"; public static final String PREF_THEME_HUE = "theme-hue"; public static final String PREF_PROFILE_ID = "profile-id"; + public static final String PREF_SHOW_ZERO_BALANCE_ACCOUNTS = "show-zero-balance-accounts"; public static App instance; private static ProfileDetailModel profileModel; private boolean monthNamesPrepared = false; @@ -68,6 +69,16 @@ public class App extends Application { SharedPreferences prefs = instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); return prefs.getInt(PREF_THEME_HUE, Colors.DEFAULT_HUE_DEG); } + public static boolean getShowZeroBalanceAccounts() { + SharedPreferences prefs = instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + return prefs.getBoolean(PREF_SHOW_ZERO_BALANCE_ACCOUNTS, true); + } + public static void storeShowZeroBalanceAccounts(boolean value) { + SharedPreferences prefs = instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(PREF_SHOW_ZERO_BALANCE_ACCOUNTS, value); + editor.apply(); + } private String getAuthURL() { if (profileModel != null) return profileModel.getUrl(); 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 807c16da..924f7afe 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 @@ -36,6 +36,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.async.GeneralBackgroundTasks; import net.ktnx.mobileledger.databinding.AccountSummaryFragmentBinding; @@ -118,6 +119,8 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Data.observeProfile(this, profile -> onProfileChanged(profile, Boolean.TRUE.equals( model.getShowZeroBalanceAccounts() .getValue()))); + model.getShowZeroBalanceAccounts() + .setValue(App.getShowZeroBalanceAccounts()); } @Override public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) { @@ -138,6 +141,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { .observe(this, v -> { menuShowZeroBalances.setChecked(v); onProfileChanged(Data.getProfile(), v); + App.storeShowZeroBalanceAccounts(v); }); super.onCreateOptionsMenu(menu, inflater); -- 2.39.5