import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.OperationCanceledException;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.OperationCanceledException;
import net.ktnx.mobileledger.err.HTTPException;
import net.ktnx.mobileledger.json.AccountListParser;
import net.ktnx.mobileledger.json.ParsedBalance;
import net.ktnx.mobileledger.err.HTTPException;
import net.ktnx.mobileledger.json.AccountListParser;
import net.ktnx.mobileledger.json.ParsedBalance;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.ui.activity.MainActivity;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.ui.activity.MainActivity;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
Pattern.compile("^\\s+(\\S[\\S\\s]+\\S)\\s\\s+([-+]?\\d[\\d,.]*)(?:\\s+(\\S+)$)?");
private static final Pattern reEnd = Pattern.compile("\\bid=\"addmodal\"");
private WeakReference<MainActivity> contextRef;
Pattern.compile("^\\s+(\\S[\\S\\s]+\\S)\\s\\s+([-+]?\\d[\\d,.]*)(?:\\s+(\\S+)$)?");
private static final Pattern reEnd = Pattern.compile("\\bid=\"addmodal\"");
private WeakReference<MainActivity> contextRef;
// %3A is '='
private Pattern reAccountName = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\"");
private Pattern reAccountValue = Pattern.compile(
"<span class=\"[^\"]*\\bamount\\b[^\"]*\">\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?</span>");
// %3A is '='
private Pattern reAccountName = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\"");
private Pattern reAccountValue = Pattern.compile(
"<span class=\"[^\"]*\\bamount\\b[^\"]*\">\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?</span>");
- public RetrieveTransactionsTask(WeakReference<MainActivity> contextRef) {
+ private MobileLedgerProfile profile;
+ public RetrieveTransactionsTask(WeakReference<MainActivity> contextRef,
+ MobileLedgerProfile profile) {
}
private static void L(String msg) {
//debug("transaction-parser", msg);
}
private static void L(String msg) {
//debug("transaction-parser", msg);
throws IOException, ParseException, HTTPException {
Progress progress = new Progress();
int maxTransactionId = Progress.INDETERMINATE;
throws IOException, ParseException, HTTPException {
Progress progress = new Progress();
int maxTransactionId = Progress.INDETERMINATE;
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
lastAccount.addAmount(val, currency);
for (LedgerAccount syn : syntheticAccounts.values()) {
syn.addAmount(val, currency);
lastAccount.addAmount(val, currency);
for (LedgerAccount syn : syntheticAccounts.values()) {
syn.addAmount(val, currency);
- profile.storeAccountValue(db, syn.getName(), currency, val);
+ profile.storeAccountValue(db, syn.getName(), currency,
+ val);
- L(String.format("found transaction %d → expecting description",
+ L(String.format(Locale.ENGLISH,
+ "found transaction %d → expecting description",
return String.format("Error parsing date '%s'", date);
}
state = ParserState.EXPECTING_TRANSACTION_DETAILS;
return String.format("Error parsing date '%s'", date);
}
state = ParserState.EXPECTING_TRANSACTION_DETAILS;
- L(String.format("transaction %d created for %s (%s) →" +
- " expecting details", transactionId, date,
- m.group(2)));
+ L(String.format(Locale.ENGLISH,
+ "transaction %d created for %s (%s) →" +
+ " expecting details", transactionId, date, m.group(2)));
transaction.addAccount(
new LedgerTransactionAccount(acc_name,
Float.valueOf(amount), currency));
transaction.addAccount(
new LedgerTransactionAccount(acc_name,
Float.valueOf(amount), currency));
- L(String.format("%d: %s = %s", transaction.getId(),
- acc_name, amount));
+ L(String.format(Locale.ENGLISH, "%d: %s = %s",
+ transaction.getId(), acc_name, amount));
}
else throw new IllegalStateException(String.format(
"Can't parse transaction %d " + "details: %s",
}
else throw new IllegalStateException(String.format(
"Can't parse transaction %d " + "details: %s",
new String[]{profile.getUuid()});
db.execSQL("update accounts set keep=0 where profile=?;", new String[]{profile.getUuid()});
}
new String[]{profile.getUuid()});
db.execSQL("update accounts set keep=0 where profile=?;", new String[]{profile.getUuid()});
}
throws IOException, HTTPException {
Progress progress = new Progress();
throws IOException, HTTPException {
Progress progress = new Progress();
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
publishProgress(progress);
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
publishProgress(progress);
ArrayList<LedgerAccount> accountList = new ArrayList<>();
boolean listFilledOK = false;
try (InputStream resp = http.getInputStream()) {
ArrayList<LedgerAccount> accountList = new ArrayList<>();
boolean listFilledOK = false;
try (InputStream resp = http.getInputStream()) {
throws IOException, ParseException, HTTPException {
Progress progress = new Progress();
int maxTransactionId = Progress.INDETERMINATE;
throws IOException, ParseException, HTTPException {
Progress progress = new Progress();
int maxTransactionId = Progress.INDETERMINATE;
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
if (transactionOrder == DetectedTransactionOrder.UNKNOWN) {
if (orderAccumulator > 30) {
transactionOrder = DetectedTransactionOrder.FILE;
if (transactionOrder == DetectedTransactionOrder.UNKNOWN) {
if (orderAccumulator > 30) {
transactionOrder = DetectedTransactionOrder.FILE;
"Detected native file order after %d transactions (factor %d)",
processedTransactionCount, orderAccumulator));
progress.setTotal(Data.transactions.size());
}
else if (orderAccumulator < -30) {
transactionOrder = DetectedTransactionOrder.REVERSE_CHRONOLOGICAL;
"Detected native file order after %d transactions (factor %d)",
processedTransactionCount, orderAccumulator));
progress.setTotal(Data.transactions.size());
}
else if (orderAccumulator < -30) {
transactionOrder = DetectedTransactionOrder.REVERSE_CHRONOLOGICAL;
"Detected reverse chronological order after %d transactions (factor %d)",
processedTransactionCount, orderAccumulator));
}
"Detected reverse chronological order after %d transactions (factor %d)",
processedTransactionCount, orderAccumulator));
}
- if (!retrieveAccountList(profile) || !retrieveTransactionList(profile))
- return retrieveTransactionListLegacy(profile);
+ if (!retrieveAccountList() || !retrieveTransactionList())
+ return retrieveTransactionListLegacy();