From: Damyan Ivanov Date: Fri, 17 Apr 2020 18:53:09 +0000 (+0300) Subject: add profile setting for default currency (db part) X-Git-Tag: v0.12.0~54 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=2cc22789021f37c51810552a0187ab7d7f2c2cbd;p=mobile-ledger.git add profile setting for default currency (db part) --- 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 3d8985fd..8c1f1e5a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -47,6 +47,7 @@ public final class MobileLedgerProfile { private String name; private boolean permitPosting; private boolean showCommodityByDefault; + private String defaultCommodity; private String preferredAccountsFilter; private String url; private boolean authEnabled; @@ -76,6 +77,7 @@ public final class MobileLedgerProfile { orderNo = origin.orderNo; futureDates = origin.futureDates; apiVersion = origin.apiVersion; + defaultCommodity = origin.defaultCommodity; } // loads all profiles into Data.profiles // returns the profile with the given UUID @@ -86,7 +88,7 @@ public final class MobileLedgerProfile { try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " + "auth_password, permit_posting, theme, order_no, " + "preferred_accounts_filter, future_dates, api_version, " + - "show_commodity_by_default FROM " + + "show_commodity_by_default, default_commodity FROM " + "profiles order by order_no", null)) { while (cursor.moveToNext()) { @@ -103,6 +105,7 @@ public final class MobileLedgerProfile { item.setFutureDates(cursor.getInt(10)); item.setApiVersion(cursor.getInt(11)); item.setShowCommodityByDefault(cursor.getInt(12) == 1); + item.setDefaultCommodity(cursor.getString(13)); list.add(item); if (item.getUuid() .equals(currentProfileUUID)) @@ -135,6 +138,18 @@ public final class MobileLedgerProfile { public void setShowCommodityByDefault(boolean showCommodityByDefault) { this.showCommodityByDefault = showCommodityByDefault; } + public String getDefaultCommodity() { + return defaultCommodity; + } + public void setDefaultCommodity(String defaultCommodity) { + this.defaultCommodity = defaultCommodity; + } + public void setDefaultCommodity(CharSequence defaultCommodity) { + if (defaultCommodity == null) + this.defaultCommodity = null; + else + this.defaultCommodity = String.valueOf(defaultCommodity); + } public SendTransactionTask.API getApiVersion() { return apiVersion; } @@ -224,13 +239,13 @@ public final class MobileLedgerProfile { db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " + "use_authentication, auth_user, auth_password, theme, order_no, " + "preferred_accounts_filter, future_dates, api_version, " + - "show_commodity_by_default) " + + "show_commodity_by_default, default_commodity) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{uuid, name, permitPosting, url, authEnabled, authEnabled ? authUserName : null, authEnabled ? authPassword : null, themeHue, orderNo, preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(), - showCommodityByDefault + showCommodityByDefault, defaultCommodity }); db.setTransactionSuccessful(); } diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java index b8d1c3cc..4097cdfd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java @@ -34,7 +34,7 @@ import static net.ktnx.mobileledger.utils.Logger.debug; public class MobileLedgerDatabase extends SQLiteOpenHelper { private static final String DB_NAME = "MoLe.db"; - private static final int LATEST_REVISION = 27; + private static final int LATEST_REVISION = 28; 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 b1c3acd0..f903162a 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, preferred_accounts_filter varchar, future_dates integer, api_version integer, show_commodity_by_default boolean default 0); +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, future_dates integer, api_version integer, show_commodity_by_default boolean default 0, default_commodity 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_28.sql b/app/src/main/res/raw/sql_28.sql new file mode 100644 index 00000000..fa509c1f --- /dev/null +++ b/app/src/main/res/raw/sql_28.sql @@ -0,0 +1 @@ +alter table profiles add default_commodity varchar; \ No newline at end of file