+/*
+ * 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;
private String session;
private String backend_url;
private LedgerTransaction ltr;
+ protected String error;
private SharedPreferences pref;
void setPref(SharedPreferences pref) {
Iterator<LedgerTransactionItem> items = ltr.getItemsIterator();
while (items.hasNext()) {
LedgerTransactionItem item = items.next();
- params.add_pair("account", item.get_account_name());
- if (item.is_amount_set())
- params.add_pair("amount", String.format(Locale.US, "%1.2f", item.get_amount()));
+ params.add_pair("account", item.getAccountName());
+ if (item.isAmountSet())
+ params.add_pair("amount", String.format(Locale.US, "%1.2f", item.getAmount()));
else params.add_pair("amount", "");
}
}
@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;
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
- task_callback.done();
+ task_callback.done(error);
}
}