]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/SaveTransactionTask.java
add license boilerplates for authored content
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / SaveTransactionTask.java
index 79cf7dc27f538daa68ff3dd6e4f88624bb975179..6ebfc511e0f1151a3e8880f9b9bdf5ae0e99e266 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright © 2018 Damyan Ivanov.
+ * This file is part of Mobile-Ledger.
+ * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * Mobile-Ledger is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ */
+
 package net.ktnx.mobileledger;
 
 import android.content.SharedPreferences;
@@ -25,6 +42,7 @@ class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void> {
     private String session;
     private String backend_url;
     private LedgerTransaction ltr;
+    protected String error;
 
     private SharedPreferences pref;
     void setPref(SharedPreferences pref) {
@@ -120,23 +138,27 @@ class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void> {
 
     @Override
     protected Void doInBackground(LedgerTransaction... ledgerTransactions) {
-        backend_url = pref.getString("backend_url", "");
-        ltr = ledgerTransactions[0];
+        error = null;
         try {
+            backend_url = pref.getString("backend_url", "");
+            ltr = ledgerTransactions[0];
+
             int tried = 0;
-            while (! send_ok() ) {
+            while (!send_ok()) {
                 try {
                     tried++;
-                    if (tried >= 3)
+                    if (tried >= 2)
                         throw new IOException(String.format("aborting after %d tries", tried));
                     sleep(100);
-                } catch (InterruptedException e) {
+                }
+                catch (InterruptedException e) {
                     e.printStackTrace();
                 }
             }
         }
-        catch (IOException e) {
+        catch (Exception e) {
             e.printStackTrace();
+            error = e.getMessage();
         }
 
         return null;
@@ -145,6 +167,6 @@ class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void> {
     @Override
     protected void onPostExecute(Void aVoid) {
         super.onPostExecute(aVoid);
-        task_callback.done();
+        task_callback.done(error);
     }
 }