private Pattern reAccountValue = Pattern.compile(
"<span class=\"[^\"]*\\bamount\\b[^\"]*\">\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?</span>");
private MobileLedgerProfile profile;
+ private int expectedPostingsCount = -1;
public RetrieveTransactionsTask(@NonNull MobileLedgerProfile profile) {
this.profile = profile;
}
private String retrieveTransactionListLegacy() throws IOException, HTTPException {
Progress progress = Progress.indeterminate();
progress.setState(ProgressState.RUNNING);
+ progress.setTotal(expectedPostingsCount);
int maxTransactionId = -1;
ArrayList<LedgerAccount> list = new ArrayList<>();
HashMap<String, LedgerAccount> map = new HashMap<>();
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
AccountListParser parser = new AccountListParser(resp);
+ expectedPostingsCount = 0;
while (true) {
throwIfCancelled();
if (parsedAccount == null) {
break;
}
-
+ expectedPostingsCount += parsedAccount.getAnumpostings();
final String accName = parsedAccount.getAname();
LedgerAccount acc = map.get(accName);
if (acc != null)
private boolean retrieveTransactionList() throws IOException, ParseException, HTTPException {
Progress progress = new Progress();
int maxTransactionId = Data.transactions.size();
+ progress.setTotal(expectedPostingsCount);
HttpURLConnection http = NetworkUtil.prepareConnection(profile, "transactions");
http.setAllowUserInteraction(false);
TransactionListParser parser = new TransactionListParser(resp);
- int processedTransactionCount = 0;
+ int processedPostings = 0;
while (true) {
throwIfCancelled();
LedgerTransaction transaction = parsedTransaction.asLedgerTransaction();
trList.add(transaction);
- progress.setProgress(++processedTransactionCount);
+ progress.setProgress(processedPostings += transaction.getAccounts()
+ .size());
publishProgress(progress);
}
private List<ParsedBalance> aebalance;
private List<ParsedBalance> aibalance;
private String aname;
+ private int anumpostings;
public ParsedLedgerAccount() {
}
+ public int getAnumpostings() {
+ return anumpostings;
+ }
+ public void setAnumpostings(int anumpostings) {
+ this.anumpostings = anumpostings;
+ }
public List<ParsedBalance> getAebalance() {
return aebalance;
}
private List<ParsedBalance> aebalance;
private List<ParsedBalance> aibalance;
private String aname;
+ private int anumpostings;
public ParsedLedgerAccount() {
}
+ public int getAnumpostings() {
+ return anumpostings;
+ }
+ public void setAnumpostings(int anumpostings) {
+ this.anumpostings = anumpostings;
+ }
public List<ParsedBalance> getAebalance() {
return aebalance;
}