X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=62ab8f4b867b7eb765e02721f94599a0ce0b8713;hb=7bff7b2c3ea7fe8fcc2febb96d8a432286173c85;hp=e255176beb008b55417f9145df185a0bf06ffe5d;hpb=5bba2c06a81c87327fdcf3f2a85c3206d932c2f9;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 e255176b..62ab8f4b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -20,6 +20,7 @@ package net.ktnx.mobileledger.model; import android.content.res.Resources; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.text.TextUtils; import android.util.SparseArray; import androidx.annotation.Nullable; @@ -332,6 +333,24 @@ public final class MobileLedgerProfile { } public void storeAccountValue(SQLiteDatabase db, int generation, String name, String currency, Float amount) { + if (!TextUtils.isEmpty(currency)) { + boolean exists; + try (Cursor c = db.rawQuery("select 1 from currencies where name=?", + new String[]{currency})) + { + exists = c.moveToFirst(); + } + if (!exists) { + db.execSQL( + "insert into currencies(id, name, position, has_gap) values((select max" + + "(id) from currencies)+1, ?, ?, ?)", new Object[]{currency, + Objects.requireNonNull( + Data.currencySymbolPosition.getValue()).toString(), + Data.currencyGap.getValue() + }); + } + } + db.execSQL("replace into account_values(profile, account, " + "currency, value, generation) values(?, ?, ?, ?, ?);", new Object[]{uuid, name, Misc.emptyIsNull(currency), amount, generation}); @@ -527,7 +546,7 @@ public final class MobileLedgerProfile { { while (c.moveToNext()) { Currency currency = new Currency(c.getInt(0), c.getString(1), - Currency.Position.valueOf(c.getInt(2)), c.getInt(3) == 1); + Currency.Position.valueOf(c.getString(2)), c.getInt(3) == 1); result.add(currency); } } @@ -548,7 +567,7 @@ public final class MobileLedgerProfile { { if (cursor.moveToFirst()) { return new Currency(cursor.getInt(0), cursor.getString(1), - Currency.Position.valueOf(cursor.getInt(2)), cursor.getInt(3) == 1); + Currency.Position.valueOf(cursor.getString(2)), cursor.getInt(3) == 1); } return null; } @@ -566,7 +585,7 @@ public final class MobileLedgerProfile { public enum FutureDates { None(0), OneWeek(7), TwoWeeks(14), OneMonth(30), TwoMonths(60), ThreeMonths(90), SixMonths(180), OneYear(365), All(-1); - private static SparseArray map = new SparseArray<>(); + private static final SparseArray map = new SparseArray<>(); static { for (FutureDates item : FutureDates.values()) {