import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
import java.util.Stack;
import java.util.regex.Matcher;
lastAccount = profile.loadAccount(acct_name);
if (lastAccount == null) {
lastAccount = new LedgerAccount(acct_name);
- profile.storeAccount(lastAccount);
+ profile.storeAccount(db, lastAccount);
}
// make sure the parent account(s) are present,
accountList.add(acc);
L(String.format("gap-filling with %s", aName));
accountNames.put(aName, null);
- profile.storeAccount(acc);
+ profile.storeAccount(db, acc);
}
}
if (currency == null) currency = "";
value = value.replace(',', '.');
L("curr=" + currency + ", value=" + value);
- profile.storeAccountValue(lastAccount.getName(), currency,
+ profile.storeAccountValue(db, lastAccount.getName(), currency,
Float.valueOf(value));
lastAccount.addAmount(Float.parseFloat(value), currency);
}
}
}
else {
- profile.storeTransaction(transaction);
+ profile.storeTransaction(db, transaction);
matchedTransactionsCount = 0;
progress.setTotal(maxTransactionId);
}
profile.deleteNotPresentTransactions(db);
db.setTransactionSuccessful();
- Log.d("db", "Updating transaction value stamp");
- Date now = new Date();
- profile.setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
- Data.lastUpdateDate.set(now);
+ profile.setLastUpdateStamp();
return null;
}
profile.markAccountsAsNotPresent(db);
AccountListParser parser = new AccountListParser(resp);
+ ArrayList<LedgerAccount> accountList = new ArrayList<>();
while (true) {
+ throwIfCancelled();
ParsedLedgerAccount parsedAccount = parser.nextAccount();
if (parsedAccount == null) break;
LedgerAccount acc = new LedgerAccount(parsedAccount.getAname());
- profile.storeAccount(acc);
+ profile.storeAccount(db, acc);
for (ParsedBalance b : parsedAccount.getAebalance()) {
- profile.storeAccountValue(acc.getName(), b.getAcommodity(),
+ profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
b.getAquantity().asFloat());
}
+
+ accountList.add(acc);
}
+ throwIfCancelled();
profile.deleteNotPresentAccounts(db);
+ throwIfCancelled();
db.setTransactionSuccessful();
+ Data.accounts.set(accountList);
}
finally {
db.endTransaction();
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
+ throwIfCancelled();
db.beginTransaction();
try {
profile.markTransactionsAsNotPresent(db);
int processedTransactionCount = 0;
while (true) {
+ throwIfCancelled();
ParsedLedgerTransaction parsedTransaction = parser.nextTransaction();
+ throwIfCancelled();
if (parsedTransaction == null) break;
LedgerTransaction transaction = parsedTransaction.asLedgerTransaction();
if (transaction.existsInDb(db)) {
progress.setTotal(progress.getProgress());
publishProgress(progress);
db.setTransactionSuccessful();
+ profile.setLastUpdateStamp();
return true;
}
}
else {
- profile.storeTransaction(transaction);
+ profile.storeTransaction(db, transaction);
matchedTransactionsCount = 0;
progress.setTotal(maxTransactionId);
}
publishProgress(progress);
}
+ throwIfCancelled();
profile.deleteNotPresentTransactions(db);
+ throwIfCancelled();
db.setTransactionSuccessful();
+ profile.setLastUpdateStamp();
}
finally {
db.endTransaction();