]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
cancelable transaction refresh
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / RetrieveTransactionsTask.java
index 13941806240b07f42173e545dc3243b583b25270..701ec506896d19b53be9576e84ed0ae45b588f9e 100644 (file)
@@ -26,7 +26,7 @@ import android.util.Log;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.TransactionListActivity;
 import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.NetworkUtil;
 
@@ -50,7 +50,7 @@ public class RetrieveTransactionsTask extends
     private static final Pattern transactionDescriptionPattern =
             Pattern.compile("<tr class=\"posting\" title=\"(\\S+)\\s(.+)");
     private static final Pattern transactionDetailsPattern =
-            Pattern.compile("^\\s+" + "(\\S[\\S\\s]+\\S)\\s\\s+([-+]?\\d[\\d,.]*)");
+            Pattern.compile("^\\s+" + "(\\S[\\S\\s]+\\S)\\s\\s+([-+]?\\d[\\d,.]*)(?:\\s+(\\S+)$)?");
     private static final Pattern endPattern = Pattern.compile("\\bid=\"addmodal\"");
     protected WeakReference<TransactionListActivity> contextRef;
     protected int error;
@@ -82,6 +82,13 @@ public class RetrieveTransactionsTask extends
         if (context == null) return;
         context.onRetrieveDone(success);
     }
+    @Override
+    protected void onCancelled() {
+        super.onCancelled();
+        TransactionListActivity context = getContext();
+        if (context == null) return;
+        context.onRetrieveDone(false);
+    }
     @SuppressLint("DefaultLocale")
     @Override
     protected Void doInBackground(Params... params) {
@@ -214,9 +221,11 @@ public class RetrieveTransactionsTask extends
                                         if (m.find()) {
                                             String acc_name = m.group(1);
                                             String amount = m.group(2);
+                                            String currency = m.group(3);
                                             amount = amount.replace(',', '.');
-                                            transaction.add_item(new LedgerTransactionItem(acc_name,
-                                                    Float.valueOf(amount)));
+                                            transaction.addAccount(
+                                                    new LedgerTransactionAccount(acc_name,
+                                                            Float.valueOf(amount), currency));
                                             L(String.format("%s = %s", acc_name, amount));
                                         }
                                         else throw new IllegalStateException(