X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=55746dddd1279f803798357fd4441190ea5f9452;hp=c9e358e292451c83468ddefc923c2393a9df3fa4;hb=667ce42731c95a98926657fea359b56209f9348e;hpb=9b2ed5acac2771812a115f83273691b55185c4fd 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 c9e358e2..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,6 +120,21 @@ 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)) @@ -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(); }