]> git.ktnx.net Git - mobile-ledger.git/commitdiff
add profile setting for default currency (db part)
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 17 Apr 2020 18:53:09 +0000 (21:53 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 17 Apr 2020 18:53:09 +0000 (21:53 +0300)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
app/src/main/res/raw/create_db.sql
app/src/main/res/raw/sql_28.sql [new file with mode: 0644]

index 3d8985fdea2d097c56a488de4568093364ea19fb..8c1f1e5a38186861541c47e353b5aed8e0122c64 100644 (file)
@@ -47,6 +47,7 @@ public final class MobileLedgerProfile {
     private String name;
     private boolean permitPosting;
     private boolean showCommodityByDefault;
     private String name;
     private boolean permitPosting;
     private boolean showCommodityByDefault;
+    private String defaultCommodity;
     private String preferredAccountsFilter;
     private String url;
     private boolean authEnabled;
     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;
         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
     }
     // 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, " +
         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()) {
                                          "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.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))
                 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 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;
     }
     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, " +
             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(),
                        "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();
         }
                     });
             db.setTransactionSuccessful();
         }
index b8d1c3cce741a6c1855ec3ec079f1d5cbed49b21..4097cdfd595bd4b47eec5c3fa284c44e074c54a9 100644 (file)
@@ -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";
 
 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;
     private static final String CREATE_DB_SQL = "create_db";
 
     private final Application mContext;
index b1c3acd031e0a042673a816ba0a066ea93f11309..f903162a9acc0be06c2a972603fba95afe88677d 100644 (file)
@@ -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 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);
 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 (file)
index 0000000..fa509c1
--- /dev/null
@@ -0,0 +1 @@
+alter table profiles add default_commodity varchar;
\ No newline at end of file