]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/AccountSummary.java
separate packages for the different aspects of the application
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / AccountSummary.java
index 77a60074164a85fdad88c2e49d92de395b8a585b..9182949828910225deee0e627cea72ae4e8457ae 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright © 2018 Damyan Ivanov.
+ * This file is part of Mobile-Ledger.
+ * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * Mobile-Ledger is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ */
+
 package net.ktnx.mobileledger;
 
 import android.arch.lifecycle.ViewModelProviders;
@@ -24,10 +41,16 @@ import android.view.MenuItem;
 import android.view.View;
 import android.widget.LinearLayout;
 
+import net.ktnx.mobileledger.async.RetrieveAccountsTask;
+import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
+
 import java.lang.ref.WeakReference;
 import java.util.Date;
 import java.util.List;
 
+import static net.ktnx.mobileledger.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
+
 public class AccountSummary extends AppCompatActivity {
     DrawerLayout drawer;
 
@@ -94,7 +117,12 @@ public class AccountSummary extends AppCompatActivity {
                 modelAdapter.startSelection();
                 if (optMenu != null) {
                     optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(true);
-                    optMenu.findItem(R.id.menu_acc_summary_hide_selected).setVisible(true);
+                    optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(true);
+                    optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(false);
+                }
+                {
+                    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_add_transaction);
+                    if (fab != null) fab.hide();
                 }
             }
         }));
@@ -175,11 +203,11 @@ public class AccountSummary extends AppCompatActivity {
         if (mShowHiddenAccounts == null) throw new AssertionError();
 
         sBindPreferenceSummaryToValueListener = (preference, value) -> mShowHiddenAccounts
-                .setChecked(preference.getBoolean("show_hidden_accounts", false));
+                .setChecked(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
         pref.registerOnSharedPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
 
-        mShowHiddenAccounts.setChecked(pref.getBoolean("show_hidden_accounts", false));
+        mShowHiddenAccounts.setChecked(pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
 
         return true;
     }
@@ -206,11 +234,11 @@ public class AccountSummary extends AppCompatActivity {
     public
     void onShowOnlyStarredClicked(MenuItem mi) {
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
-        boolean flag = pref.getBoolean("show_hidden_accounts", false);
+        boolean flag = pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
 
         SharedPreferences.Editor editor = pref.edit();
-        editor.putBoolean("show_hidden_accounts", !flag);
-        Log.d("pref", "Setting show_hidden_accounts to " + (flag ? "false" : "true"));
+        editor.putBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, !flag);
+        Log.d("pref", "Setting show only starred accounts pref to " + (flag ? "false" : "true"));
         editor.apply();
 
         update_account_table();
@@ -235,7 +263,7 @@ public class AccountSummary extends AppCompatActivity {
         task.execute();
 
     }
-    void onAccountRefreshDone(int error) {
+    public void onAccountRefreshDone(int error) {
         SwipeRefreshLayout srl = findViewById(R.id.account_swiper);
         srl.setRefreshing(false);
         if (error != 0) {
@@ -252,11 +280,23 @@ public class AccountSummary extends AppCompatActivity {
         model.reloadAccounts();
         modelAdapter.notifyDataSetChanged();
     }
-    public void onCancelAccSelection(MenuItem item) {
+    void stopSelection() {
         modelAdapter.stopSelection();
         if (optMenu != null) {
             optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(false);
-            optMenu.findItem(R.id.menu_acc_summary_hide_selected).setVisible(false);
+            optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(false);
+            optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(true);
         }
+        {
+            FloatingActionButton fab = findViewById(R.id.btn_add_transaction);
+            if (fab != null) fab.show();
+        }
+    }
+    public void onCancelAccSelection(MenuItem item) {
+        stopSelection();
+    }
+    public void onConfirmAccSelection(MenuItem item) {
+        model.commitSelections();
+        stopSelection();
     }
 }