From: Damyan Ivanov Date: Thu, 28 Mar 2019 22:18:03 +0000 (+0200) Subject: new profile field: preferred accounts filter X-Git-Tag: v0.9~47 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=a50108a81e10a6371d1d49e3610c87a46e3ab9b4;p=mobile-ledger.git new profile field: preferred accounts filter to be used in the transaction description auto-completion, preferring transactions that contain an account matching the filter the idea is useful for ledgers manipulated by multiple people with personal accounts who enter transactions with the same description one would expect the auto-completion to pick a transaction that uses accounts of the user rather than transaction using other users' accounts --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 6ebba576..3db7850f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -38,6 +38,7 @@ public final class MobileLedgerProfile { private String uuid; private String name; private boolean permitPosting; + private String preferredAccountsFilter; private String url; private boolean authEnabled; private String authUserName; @@ -57,7 +58,8 @@ public final class MobileLedgerProfile { List list = new ArrayList<>(); SQLiteDatabase db = MLDB.getDatabase(); try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " + - "auth_password, permit_posting, theme, order_no FROM " + + "auth_password, permit_posting, theme, order_no, " + + "preferred_accounts_filter FROM " + "profiles order by order_no", null)) { while (cursor.moveToNext()) { @@ -70,6 +72,7 @@ public final class MobileLedgerProfile { item.setPostingPermitted(cursor.getInt(6) == 1); item.setThemeId(cursor.getInt(7)); item.orderNo = cursor.getInt(8); + item.setPreferredAccountsFilter(cursor.getString(9)); list.add(item); if (item.getUuid().equals(currentProfileUUID)) result = item; } @@ -97,6 +100,15 @@ public final class MobileLedgerProfile { db.endTransaction(); } } + public String getPreferredAccountsFilter() { + return preferredAccountsFilter; + } + public void setPreferredAccountsFilter(String preferredAccountsFilter) { + this.preferredAccountsFilter = preferredAccountsFilter; + } + public void setPreferredAccountsFilter(CharSequence preferredAccountsFilter) { + setPreferredAccountsFilter(String.valueOf(preferredAccountsFilter)); + } public boolean isPostingPermitted() { return permitPosting; } @@ -158,10 +170,12 @@ public final class MobileLedgerProfile { // permitPosting ? "TRUE" : "FALSE", authEnabled ? "TRUE" : "FALSE", themeId)); db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " + "use_authentication, auth_user, " + - "auth_password, theme, order_no) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", + "auth_password, theme, order_no, preferred_accounts_filter) " + + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{uuid, name, permitPosting, url, authEnabled, authEnabled ? authUserName : null, - authEnabled ? authPassword : null, themeId, orderNo + authEnabled ? authPassword : null, themeId, orderNo, + preferredAccountsFilter }); db.setTransactionSuccessful(); } diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index 4568846f..5075b9ae 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -212,7 +212,7 @@ public final class MLDB { class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable { private static final String DB_NAME = "MoLe.db"; - private static final int LATEST_REVISION = 21; + private static final int LATEST_REVISION = 22; private static final String CREATE_DB_SQL = "create_db"; private final Application mContext; diff --git a/app/src/main/res/raw/create_db.sql b/app/src/main/res/raw/create_db.sql index fd2e43e1..d077ded2 100644 --- a/app/src/main/res/raw/create_db.sql +++ b/app/src/main/res/raw/create_db.sql @@ -5,7 +5,7 @@ create unique index un_options on options(profile,name); create table account_values(profile varchar not null, account varchar not null, currency varchar not null default '', keep boolean, value decimal not null ); create unique index un_account_values on account_values(profile,account,currency); create table description_history(description varchar not null primary key, keep boolean, description_upper varchar); -create table profiles(uuid varchar not null primary key, name not null, url not null, use_authentication boolean not null, auth_user varchar, auth_password varchar, order_no integer, permit_posting boolean default 0, theme integer default -1); +create table profiles(uuid varchar not null primary key, name not null, url not null, use_authentication boolean not null, auth_user varchar, auth_password varchar, order_no integer, permit_posting boolean default 0, theme integer default -1, preferred_accounts_filter varchar); create table transactions(profile varchar not null, id integer not null, data_hash varchar not null, date varchar not null, description varchar not null, keep boolean not null default 0); create unique index un_transactions_id on transactions(profile,id); create unique index un_transactions_data_hash on transactions(profile,data_hash); diff --git a/app/src/main/res/raw/sql_22.sql b/app/src/main/res/raw/sql_22.sql new file mode 100644 index 00000000..552397cc --- /dev/null +++ b/app/src/main/res/raw/sql_22.sql @@ -0,0 +1 @@ +alter table profiles add preferred_accounts_filter varchar; \ No newline at end of file