+/*
+ * 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.app.Application;
import android.widget.LinearLayout;
import android.widget.TextView;
+import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.utils.MLDB;
+
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<LedgerAccount> accounts;
public AccountSummaryViewModel(@NonNull Application application) {
super(application);
- dbh = new MobileLedgerDatabase(application);
}
- List<LedgerAccount> getAccounts() {
+ List<LedgerAccount> getAccounts(Context context) {
if (accounts == null) {
accounts = new ArrayList<>();
- reloadAccounts();
+ reloadAccounts(context);
}
return accounts;
}
- void reloadAccounts() {
+ void reloadAccounts(Context context) {
accounts.clear();
boolean showingOnlyStarred =
PreferenceManager.getDefaultSharedPreferences(getApplication())
if (showingOnlyStarred) sql += " WHERE hidden = 0";
sql += " ORDER BY name";
- try (SQLiteDatabase db = dbh.getReadableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getReadableDatabase(context)) {
try (Cursor cursor = db
.rawQuery(sql,null))
{
}
}
}
- void commitSelections() {
- try(SQLiteDatabase db = dbh.getWritableDatabase()) {
+ void commitSelections(Context context) {
+ try(SQLiteDatabase db = MLDB.getWritableDatabase(context)) {
db.beginTransaction();
try {
for (LedgerAccount acc : accounts) {