]> git.ktnx.net Git - mobile-ledger.git/commitdiff
proper transaction parsing progress
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 26 Aug 2020 20:05:35 +0000 (23:05 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 26 Aug 2020 20:13:24 +0000 (20:13 +0000)
accounts data has the number of postings which can be used to determine
the remaining work

app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerAccount.java
app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerAccount.java

index 288301f0771cf71b3f81f296ffb4f06f9da2a5c8..ac9ec5093e54ece20790e6107f8fe2d593c5d9af 100644 (file)
@@ -75,6 +75,7 @@ public class RetrieveTransactionsTask
     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;
     }
@@ -131,6 +132,7 @@ public class RetrieveTransactionsTask
     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<>();
@@ -393,6 +395,7 @@ public class RetrieveTransactionsTask
                 throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
 
             AccountListParser parser = new AccountListParser(resp);
+            expectedPostingsCount = 0;
 
             while (true) {
                 throwIfCancelled();
@@ -400,7 +403,7 @@ public class RetrieveTransactionsTask
                 if (parsedAccount == null) {
                     break;
                 }
-
+                expectedPostingsCount += parsedAccount.getAnumpostings();
                 final String accName = parsedAccount.getAname();
                 LedgerAccount acc = map.get(accName);
                 if (acc != null)
@@ -462,6 +465,7 @@ public class RetrieveTransactionsTask
     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);
@@ -480,7 +484,7 @@ public class RetrieveTransactionsTask
 
             TransactionListParser parser = new TransactionListParser(resp);
 
-            int processedTransactionCount = 0;
+            int processedPostings = 0;
 
             while (true) {
                 throwIfCancelled();
@@ -492,7 +496,8 @@ public class RetrieveTransactionsTask
                 LedgerTransaction transaction = parsedTransaction.asLedgerTransaction();
                 trList.add(transaction);
 
-                progress.setProgress(++processedTransactionCount);
+                progress.setProgress(processedPostings += transaction.getAccounts()
+                                                                     .size());
                 publishProgress(progress);
             }
 
index d346cb76009c3d50964a5937576f9960abc2eba0..308140092b6eba78e80b00b072cbb434348c5767 100644 (file)
@@ -26,8 +26,15 @@ public class ParsedLedgerAccount {
     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;
     }
index 89f3cccefc67abb88446c1477fca130ae86de571..460575fc1ea122fc088ec8173a38e9a91a4c02ee 100644 (file)
@@ -26,8 +26,15 @@ public class ParsedLedgerAccount {
     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;
     }