/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
db.execSQL("UPDATE accounts SET hidden=? WHERE profile=? AND name=?",
new Object[]{acc.isHiddenByStarToBe() ? 1 : 0, profile, acc.getName()
});
-
- acc.setHiddenByStar(acc.isHiddenByStarToBe());
- if (!params[0].showOnlyStarred || !acc.isHiddenByStar()) newList.add(acc);
}
db.setTransactionSuccessful();
}
/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
public class CommitAccountsTaskParams {
ObservableList<LedgerAccount> accountList;
- boolean showOnlyStarred;
public CommitAccountsTaskParams(ObservableList<LedgerAccount> accountList, boolean showOnlyStarred) {
this.accountList = accountList;
- this.showOnlyStarred = showOnlyStarred;
}
}
/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
LedgerAccount acc = profile.tryLoadAccount(db, aName);
if (acc == null) {
acc = new LedgerAccount(aName);
- acc.setHiddenByStar(lastAccount.isHiddenByStar());
acc.setExpanded(!lastAccount.hasSubAccounts() ||
lastAccount.isExpanded());
}
private String shortName;
private int level;
private String parentName;
- private boolean hiddenByStar;
private boolean hiddenByStarToBe;
private boolean expanded;
private List<LedgerAmount> amounts;
public LedgerAccount(String name) {
this.setName(name);
- hiddenByStar = false;
}
public LedgerAccount(String name, float amount) {
this.setName(name);
- this.hiddenByStar = false;
this.expanded = true;
this.amounts = new ArrayList<LedgerAmount>();
this.addAmount(amount);
// - it is starred (not hidden by a star)
// - and it has an expanded parent or is a top account
public boolean isVisible() {
- if (hiddenByStar) return false;
-
if (level == 0) return true;
return isVisible(Data.accounts);
public boolean isParentOf(LedgerAccount potentialChild) {
return potentialChild.getName().startsWith(name + ":");
}
- public boolean isHiddenByStar() {
- return hiddenByStar;
- }
- public void setHiddenByStar(boolean hiddenByStar) {
- this.hiddenByStar = hiddenByStar;
- }
private void stripName() {
level = 0;
shortName = name;
public String getParentName() {
return parentName;
}
- public void togglehidden() {
- hiddenByStar = !hiddenByStar;
- }
-
public boolean isHiddenByStarToBe() {
return hiddenByStarToBe;
}
public void storeAccount(SQLiteDatabase db, LedgerAccount acc) {
// replace into is a bad idea because it would reset hidden to its default value
// we like the default, but for new accounts only
- db.execSQL("update accounts set level = ?, keep = 1, hidden=?, expanded=? " +
+ db.execSQL("update accounts set level = ?, keep = 1, expanded=? " +
"where profile=? and name = ?",
- new Object[]{acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded(), uuid,
- acc.getName()
+ new Object[]{acc.getLevel(), acc.isExpanded(), uuid, acc.getName()
});
- db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, hidden, " +
- "expanded, keep) " + "select ?,?,?,?,?,?,?,1 where (select changes() = 0)",
+ db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, " +
+ "expanded, keep) " + "select ?,?,?,?,?,?,1 where (select changes() = 0)",
new Object[]{uuid, acc.getName(), acc.getName().toUpperCase(), acc.getParentName(),
- acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded()
+ acc.getLevel(), acc.isExpanded()
});
// debug("accounts", String.format("Stored account '%s' in DB [%s]", acc.getName(), uuid));
}
}
@Nullable
public LedgerAccount tryLoadAccount(SQLiteDatabase db, String accName) {
- try (Cursor cursor = db.rawQuery(
- "SELECT a.hidden, a.expanded, (select 1 from accounts a2 " +
- "where a2.profile = a.profile and a2.name like a.name||':%' limit 1) " +
- "FROM accounts a WHERE a.profile = ? and a.name=?", new String[]{uuid, accName}))
+ try (Cursor cursor = db.rawQuery("SELECT a.expanded, (select 1 from accounts a2 " +
+ "where a2.profile = a.profile and a2.name like a" +
+ ".name||':%' limit 1) " +
+ "FROM accounts a WHERE a.profile = ? and a.name=?", new String[]{uuid, accName}))
{
if (cursor.moveToFirst()) {
LedgerAccount acc = new LedgerAccount(accName);
- acc.setHiddenByStar(cursor.getInt(0) == 1);
- acc.setExpanded(cursor.getInt(1) == 1);
- acc.setHasSubAccounts(cursor.getInt(2) == 1);
+ acc.setExpanded(cursor.getInt(0) == 1);
+ acc.setHasSubAccounts(cursor.getInt(1) == 1);
try (Cursor c2 = db.rawQuery(
"SELECT value, currency FROM account_values WHERE profile = ? " +
import android.content.Context;
import android.content.res.Resources;
-import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
holder.accountExpanderContainer.setVisibility(View.GONE);
}
- if (acc.isHiddenByStar()) {
- holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
- holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
- }
- else {
- holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
- holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
- }
-
holder.row.setTag(R.id.POS, position);
}
}
public class MobileLedgerDatabase extends SQLiteOpenHelper {
private static final String DB_NAME = "MoLe.db";
- private static final int LATEST_REVISION = 34;
+ private static final int LATEST_REVISION = 35;
private static final String CREATE_DB_SQL = "create_db";
private final Application mContext;
--
-- You should have received a copy of the GNU General Public License
-- along with MoLe. If not, see <https://www.gnu.org/licenses/>.
-create table accounts(profile varchar not null, name varchar not null, name_upper varchar not null, hidden boolean not null default 0, keep boolean not null default 0, level integer not null, parent_name varchar, expanded default 1, amounts_expanded boolean default 0);
+create table accounts(profile varchar not null, name varchar not null, name_upper varchar not null, keep boolean not null default 0, level integer not null, parent_name varchar, expanded default 1, amounts_expanded boolean default 0);
create unique index un_accounts on accounts(profile, name);
create table options(profile varchar not null, name varchar not null, value varchar);
create unique index un_options on options(profile,name);
create index idx_transaction_description on transactions(description);
create table transaction_accounts(profile varchar not null, transaction_id integer not null, account_name varchar not null, currency varchar not null default '', amount decimal not null, comment varchar, constraint fk_transaction_accounts_acc foreign key(profile,account_name) references accounts(profile,account_name), constraint fk_transaction_accounts_trn foreign key(profile, transaction_id) references transactions(profile,id));
create table currencies(id integer not null primary key, name varchar not null, position varchar not null, has_gap boolean not null);
--- updated to revision 34
\ No newline at end of file
+-- updated to revision 35
\ No newline at end of file
--- /dev/null
+-- Copyright © 2020 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
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your opinion), any later version.
+--
+-- MoLe 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 MoLe. If not, see <https://www.gnu.org/licenses/>.
+create table accounts_new(profile varchar not null, name varchar not null, name_upper varchar not null, keep boolean not null default 0, level integer not null, parent_name varchar, expanded default 1, amounts_expanded boolean default 0);
+insert into accounts_new(profile, name, name_upper, keep, level, parent_name, expanded, amounts_expanded) select profile, name, name_upper, keep, level, parent_name, expanded, amounts_expanded from accounts;
+drop table accounts;
+alter table accounts_new rename to accounts;