X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=55746dddd1279f803798357fd4441190ea5f9452;hb=667ce42731c95a98926657fea359b56209f9348e;hp=62ab8f4b867b7eb765e02721f94599a0ce0b8713;hpb=7bff7b2c3ea7fe8fcc2febb96d8a432286173c85;p=mobile-ledger.git 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 62ab8f4b..55746ddd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -63,6 +63,7 @@ public final class MobileLedgerProfile { private FutureDates futureDates = FutureDates.None; private boolean accountsLoaded; private boolean transactionsLoaded; + private HledgerVersion detectedVersion; // N.B. when adding new fields, update the copy-constructor below transient private AccountAndTransactionListSaver accountAndTransactionListSaver; public MobileLedgerProfile(String uuid) { @@ -86,6 +87,8 @@ public final class MobileLedgerProfile { defaultCommodity = origin.defaultCommodity; accountsLoaded = origin.accountsLoaded; transactionsLoaded = origin.transactionsLoaded; + if (origin.detectedVersion != null) + detectedVersion = new HledgerVersion(origin.detectedVersion); } // loads all profiles into Data.profiles // returns the profile with the given UUID @@ -97,7 +100,8 @@ public final class MobileLedgerProfile { "auth_password, permit_posting, theme, order_no, " + "preferred_accounts_filter, future_dates, api_version, " + "show_commodity_by_default, default_commodity, " + - "show_comments_by_default FROM " + + "show_comments_by_default, detected_version_pre_1_19, " + + "detected_version_major, detected_version_minor FROM " + "profiles order by order_no", null)) { while (cursor.moveToNext()) { @@ -116,13 +120,28 @@ public final class MobileLedgerProfile { item.setShowCommodityByDefault(cursor.getInt(12) == 1); item.setDefaultCommodity(cursor.getString(13)); item.setShowCommentsByDefault(cursor.getInt(14) == 1); + { + boolean pre_1_20 = cursor.getInt(15) == 1; + int major = cursor.getInt(16); + int minor = cursor.getInt(17); + + if (!pre_1_20 && major == 0 && minor == 0) { + item.detectedVersion = null; + } + else if (pre_1_20) { + item.detectedVersion = new HledgerVersion(true); + } + else { + item.detectedVersion = new HledgerVersion(major, minor); + } + } list.add(item); if (item.getUuid() .equals(currentProfileUUID)) result = item; } } - Data.profiles.setValue(list); + Data.profiles.postValue(list); return result; } public static void storeProfilesOrder() { @@ -142,6 +161,12 @@ public final class MobileLedgerProfile { db.endTransaction(); } } + public HledgerVersion getDetectedVersion() { + return detectedVersion; + } + public void setDetectedVersion(HledgerVersion detectedVersion) { + this.detectedVersion = detectedVersion; + } @Contract(value = "null -> false", pure = true) @Override public boolean equals(@Nullable Object obj) { @@ -179,6 +204,8 @@ public final class MobileLedgerProfile { return false; if (apiVersion != p.apiVersion) return false; + if (!Objects.equals(detectedVersion, p.detectedVersion)) + return false; return futureDates == p.futureDates; } public boolean getShowCommentsByDefault() { @@ -294,13 +321,18 @@ 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, default_commodity, show_comments_by_default) " + - "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "show_commodity_by_default, default_commodity, show_comments_by_default," + + "detected_version_pre_1_19, detected_version_major, " + + "detected_version_minor) " + + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{uuid, name, permitPosting, url, authEnabled, authEnabled ? authUserName : null, authEnabled ? authPassword : null, themeHue, orderNo, preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(), - showCommodityByDefault, defaultCommodity, showCommentsByDefault + showCommodityByDefault, defaultCommodity, showCommentsByDefault, + (detectedVersion != null) && detectedVersion.isPre_1_20(), + (detectedVersion == null) ? 0 : detectedVersion.getMajor(), + (detectedVersion == null) ? 0 : detectedVersion.getMinor() }); db.setTransactionSuccessful(); } @@ -452,12 +484,12 @@ public final class MobileLedgerProfile { db.beginTransactionNonExclusive(); try { Object[] uuid_param = new Object[]{uuid}; - db.execSQL("delete from profiles where uuid=?", uuid_param); - db.execSQL("delete from accounts where profile=?", uuid_param); - db.execSQL("delete from account_values where profile=?", uuid_param); - db.execSQL("delete from transactions where profile=?", uuid_param); db.execSQL("delete from transaction_accounts where profile=?", uuid_param); + db.execSQL("delete from transactions where profile=?", uuid_param); + db.execSQL("delete from account_values where profile=?", uuid_param); + db.execSQL("delete from accounts where profile=?", uuid_param); db.execSQL("delete from options where profile=?", uuid_param); + db.execSQL("delete from profiles where uuid=?", uuid_param); db.setTransactionSuccessful(); } finally {