]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java
rework transaction date handling
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / SendTransactionTask.java
index 5170b9337a362dbcafc55cd6e66360056521157a..0fd4a1b50fc284660d7663197d737f72af330404 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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
@@ -32,6 +32,7 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.NetworkUtil;
+import net.ktnx.mobileledger.utils.SimpleDate;
 import net.ktnx.mobileledger.utils.UrlEncodedFormData;
 
 import java.io.BufferedReader;
@@ -41,8 +42,6 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.GregorianCalendar;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -52,6 +51,12 @@ import java.util.regex.Pattern;
 import static android.os.SystemClock.sleep;
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
+/* TODO: get rid of the custom session/cookie and auth code?
+ *       (the last problem with the POST was the missing content-length header)
+ *       This will resolve itself when hledger-web 1.14+ is released with Debian/stable,
+ *       at which point the HTML form emulation can be dropped entirely
+ */
+
 public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void> {
     private final TaskCallback taskCallback;
     protected String error;
@@ -170,9 +175,9 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         if (token != null)
             params.addPair("_token", token);
 
-        Date transactionDate = ltr.getDate();
+        SimpleDate transactionDate = ltr.getDate();
         if (transactionDate == null) {
-            transactionDate = new GregorianCalendar().getTime();
+            transactionDate = SimpleDate.today();
         }
 
         params.addPair("date", Globals.formatLedgerDate(transactionDate));
@@ -261,7 +266,8 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
                     if (!send_1_15_OK()) {
                         Logger.debug("network", "Version 1.5 request failed. Trying with 1.14");
                         if (!send_1_14_OK()) {
-                            Logger.debug("network", "Version 1.14 failed too. Trying HTML form emulation");
+                            Logger.debug("network",
+                                    "Version 1.14 failed too. Trying HTML form emulation");
                             legacySendOkWithRetry();
                         }
                         else {
@@ -298,8 +304,7 @@ public class SendTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         while (!legacySendOK()) {
             tried++;
             if (tried >= 2)
-                throw new IOException(
-                        String.format("aborting after %d tries", tried));
+                throw new IOException(String.format("aborting after %d tries", tried));
             sleep(100);
         }
     }