]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
adopt Room for displaying account lists
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / RetrieveTransactionsTask.java
index d092a1cbfc55f1f0294cef1f6fc583248e14efa6..aa47d73d403cc456bf6fca05a7046e8dbd421241 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -28,6 +28,7 @@ import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
 
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.err.HTTPException;
+import net.ktnx.mobileledger.json.API;
 import net.ktnx.mobileledger.json.AccountListParser;
 import net.ktnx.mobileledger.json.ApiNotSupportedException;
 import net.ktnx.mobileledger.json.TransactionListParser;
@@ -120,9 +121,6 @@ public class RetrieveTransactionsTask extends
             return null;
         }
     }
-    public MobileLedgerProfile getProfile() {
-        return profile;
-    }
     @Override
     protected void onProgressUpdate(Progress... values) {
         super.onProgressUpdate(values);
@@ -213,7 +211,7 @@ public class RetrieveTransactionsTask extends
                             else {
                                 parentAccount = null;
                             }
-                            lastAccount = new LedgerAccount(profile, accName, parentAccount);
+                            lastAccount = new LedgerAccount(accName, parentAccount);
 
                             accounts.add(lastAccount);
                             map.put(accName, lastAccount);
@@ -377,7 +375,7 @@ public class RetrieveTransactionsTask extends
             parentAccount = null;
         }
 
-        acc = new LedgerAccount(profile, accountName, parentAccount);
+        acc = new LedgerAccount(accountName, parentAccount);
         createdAccounts.add(acc);
         return acc;
     }
@@ -386,11 +384,11 @@ public class RetrieveTransactionsTask extends
     }
     private List<LedgerAccount> retrieveAccountList()
             throws IOException, HTTPException, ApiNotSupportedException {
-        final SendTransactionTask.API apiVersion = profile.getApiVersion();
-        if (apiVersion.equals(SendTransactionTask.API.auto)) {
+        final API apiVersion = profile.getApiVersion();
+        if (apiVersion.equals(API.auto)) {
             return retrieveAccountListAnyVersion();
         }
-        else if (apiVersion.equals(SendTransactionTask.API.html)) {
+        else if (apiVersion.equals(API.html)) {
             Logger.debug("json",
                     "Declining using JSON API for /accounts with configured legacy API version");
             return null;
@@ -401,7 +399,7 @@ public class RetrieveTransactionsTask extends
     }
     private List<LedgerAccount> retrieveAccountListAnyVersion()
             throws HTTPException, ApiNotSupportedException {
-        for (SendTransactionTask.API ver : SendTransactionTask.API.allVersions) {
+        for (API ver : API.allVersions) {
             try {
                 return retrieveAccountListForVersion(ver);
             }
@@ -416,7 +414,7 @@ public class RetrieveTransactionsTask extends
 
         throw new RuntimeException("This should never be reached");
     }
-    private List<LedgerAccount> retrieveAccountListForVersion(SendTransactionTask.API version)
+    private List<LedgerAccount> retrieveAccountListForVersion(API version)
             throws IOException, HTTPException {
         HttpURLConnection http = NetworkUtil.prepareConnection(profile, "accounts");
         http.setAllowUserInteraction(false);
@@ -467,11 +465,11 @@ public class RetrieveTransactionsTask extends
     }
     private List<LedgerTransaction> retrieveTransactionList()
             throws ParseException, HTTPException, IOException, ApiNotSupportedException {
-        final SendTransactionTask.API apiVersion = profile.getApiVersion();
-        if (apiVersion.equals(SendTransactionTask.API.auto)) {
+        final API apiVersion = profile.getApiVersion();
+        if (apiVersion.equals(API.auto)) {
             return retrieveTransactionListAnyVersion();
         }
-        else if (apiVersion.equals(SendTransactionTask.API.html)) {
+        else if (apiVersion.equals(API.html)) {
             Logger.debug("json",
                     "Declining using JSON API for /accounts with configured legacy API version");
             return null;
@@ -483,7 +481,7 @@ public class RetrieveTransactionsTask extends
     }
     private List<LedgerTransaction> retrieveTransactionListAnyVersion()
             throws ApiNotSupportedException {
-        for (SendTransactionTask.API ver : SendTransactionTask.API.allVersions) {
+        for (API ver : API.allVersions) {
             try {
                 return retrieveTransactionListForVersion(ver);
             }
@@ -498,8 +496,8 @@ public class RetrieveTransactionsTask extends
 
         throw new RuntimeException("This should never be reached");
     }
-    private List<LedgerTransaction> retrieveTransactionListForVersion(
-            SendTransactionTask.API apiVersion) throws IOException, ParseException, HTTPException {
+    private List<LedgerTransaction> retrieveTransactionListForVersion(API apiVersion)
+            throws IOException, ParseException, HTTPException {
         Progress progress = new Progress();
         progress.setTotal(expectedPostingsCount);
 
@@ -554,7 +552,7 @@ public class RetrieveTransactionsTask extends
                         .compareTo(o1.getDate());
             if (res != 0)
                 return res;
-            return Integer.compare(o2.getId(), o1.getId());
+            return Long.compare(o2.getId(), o1.getId());
         });
         return trList;
     }