]> git.ktnx.net Git - mobile-ledger.git/commitdiff
store the 'Show zero-balance accounts' setting in the preferences
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Mar 2024 15:06:47 +0000 (18:06 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Mar 2024 15:06:47 +0000 (18:06 +0300)
app/src/main/java/net/ktnx/mobileledger/App.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java

index a9a416e7bb3c15a8e49c51f1aedb45f1307d0bee..b0c8e1f7574cc9f8048774dbd67000df0b99de15 100644 (file)
@@ -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();
index 807c16daf8540af877827e2729d0e848f733d3c3..924f7afe86a1f4d55081b7f7389b33de520c5721 100644 (file)
@@ -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);