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;h=168941f87fb4ed39b165d91f96edbd711d7de133;hp=b3920fe4d5e5a9acba517ad8ec842f38fbc72839;hb=ff3be47725919f5284a2a4e2348d1ab6fd561325;hpb=c0b1645b9f14e6b25803efd2fa048e27030ba5e6 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 b3920fe4..168941f8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -25,6 +25,7 @@ import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.MLDB; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.UUID; @@ -181,9 +182,7 @@ public final class MobileLedgerProfile { db.endTransaction(); } } - public void storeAccount(LedgerAccount acc) { - SQLiteDatabase db = MLDB.getWritableDatabase(); - + public void storeAccount(SQLiteDatabase db, LedgerAccount acc) { // replace into is a bad idea because it would reset hidden to its default value // we like the default, but for new accounts only db.execSQL("update accounts set level = ?, keep = 1 where profile=? and name = ?", @@ -194,14 +193,12 @@ public final class MobileLedgerProfile { acc.getLevel() }); } - public void storeAccountValue(String name, String currency, Float amount) { - SQLiteDatabase db = MLDB.getWritableDatabase(); + public void storeAccountValue(SQLiteDatabase db, String name, String currency, Float amount) { db.execSQL("replace into account_values(profile, account, " + "currency, value, keep) values(?, ?, ?, ?, 1);", new Object[]{uuid, name, currency, amount}); } - public void storeTransaction(LedgerTransaction tr) { - SQLiteDatabase db = MLDB.getWritableDatabase(); + public void storeTransaction(SQLiteDatabase db, LedgerTransaction tr) { tr.fillDataHash(); db.execSQL("DELETE from transactions WHERE profile=? and id=?", new Object[]{uuid, tr.getId()}); @@ -312,4 +309,38 @@ public final class MobileLedgerProfile { public void setThemeId(Object o) { setThemeId(Integer.valueOf(String.valueOf(o)).intValue()); } + public void markTransactionsAsNotPresent(SQLiteDatabase db) { + db.execSQL("UPDATE transactions set keep=0 where profile=?", new String[]{uuid}); + + } + public void markAccountsAsNotPresent(SQLiteDatabase db) { + db.execSQL("update account_values set keep=0 where profile=?;", new String[]{uuid}); + db.execSQL("update accounts set keep=0 where profile=?;", new String[]{uuid}); + + } + public void deleteNotPresentAccounts(SQLiteDatabase db) { + db.execSQL("delete from account_values where keep=0 and profile=?", new String[]{uuid}); + db.execSQL("delete from accounts where keep=0 and profile=?", new String[]{uuid}); + } + public void markTransactionAsPresent(SQLiteDatabase db, LedgerTransaction transaction) { + db.execSQL("UPDATE transactions SET keep = 1 WHERE profile = ? and id=?", + new Object[]{uuid, transaction.getId() + }); + } + public void markTransactionsBeforeTransactionAsPresent(SQLiteDatabase db, + LedgerTransaction transaction) { + db.execSQL("UPDATE transactions SET keep=1 WHERE profile = ? and id < ?", + new Object[]{uuid, transaction.getId() + }); + + } + public void deleteNotPresentTransactions(SQLiteDatabase db) { + db.execSQL("DELETE FROM transactions WHERE profile=? AND keep = 0", new String[]{uuid}); + } + public void setLastUpdateStamp() { + Log.d("db", "Updating transaction value stamp"); + Date now = new Date(); + setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime()); + Data.lastUpdateDate.set(now); + } }