X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FAccountSummaryViewModel.java;h=f01907b397d24c35933110bbcbe7fefc8ec971e2;hb=9afaa87d47292f5351f8ae447a9d3ae557147472;hp=c1f1625812a91baab8aa8bdbe932e7e7970f7bca;hpb=274b2fc48febc60d8507f8a7764a34e97b002949;p=mobile-ledger.git
diff --git a/app/src/main/java/net/ktnx/mobileledger/AccountSummaryViewModel.java b/app/src/main/java/net/ktnx/mobileledger/AccountSummaryViewModel.java
index c1f16258..f01907b3 100644
--- a/app/src/main/java/net/ktnx/mobileledger/AccountSummaryViewModel.java
+++ b/app/src/main/java/net/ktnx/mobileledger/AccountSummaryViewModel.java
@@ -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 .
+ */
+
package net.ktnx.mobileledger;
import android.app.Application;
@@ -11,6 +28,7 @@ import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -18,9 +36,14 @@ import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
+import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
+
import java.util.ArrayList;
import java.util.List;
+import static net.ktnx.mobileledger.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
+
class AccountSummaryViewModel extends AndroidViewModel {
private MobileLedgerDatabase dbh;
private List accounts;
@@ -41,11 +64,11 @@ class AccountSummaryViewModel extends AndroidViewModel {
void reloadAccounts() {
accounts.clear();
- boolean showingHiddenAccounts =
+ boolean showingOnlyStarred =
PreferenceManager.getDefaultSharedPreferences(getApplication())
- .getBoolean("show_hidden_accounts", false);
+ .getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
String sql = "SELECT name, hidden FROM accounts";
- if (!showingHiddenAccounts) sql += " WHERE hidden = 0";
+ if (showingOnlyStarred) sql += " WHERE hidden = 0";
sql += " ORDER BY name";
try (SQLiteDatabase db = dbh.getReadableDatabase()) {
@@ -68,6 +91,22 @@ class AccountSummaryViewModel extends AndroidViewModel {
}
}
}
+ void commitSelections() {
+ try(SQLiteDatabase db = dbh.getWritableDatabase()) {
+ db.beginTransaction();
+ try {
+ for (LedgerAccount acc : accounts) {
+ Log.d("db", String.format("Setting %s to %s", acc.getName(),
+ acc.isHidden() ? "hidden" : "starred"));
+ db.execSQL("UPDATE accounts SET hidden=? WHERE name=?",
+ new Object[]{acc.isHiddenToBe() ? 1 : 0, acc.getName()});
+ }
+ db.setTransactionSuccessful();
+ for (LedgerAccount acc : accounts ) { acc.setHidden(acc.isHiddenToBe()); }
+ }
+ finally { db.endTransaction(); }
+ }
+ }
}
class AccountSummaryAdapter extends RecyclerView.Adapter {
@@ -112,7 +151,7 @@ class AccountSummaryAdapter extends RecyclerView.Adapter