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;
}
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;
}
private List<LedgerAccount> retrieveAccountListAnyVersion()
throws HTTPException, ApiNotSupportedException {
- for (SendTransactionTask.API ver : SendTransactionTask.API.allVersions) {
+ for (API ver : API.allVersions) {
try {
return retrieveAccountListForVersion(ver);
}
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);
}
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;
}
private List<LedgerTransaction> retrieveTransactionListAnyVersion()
throws ApiNotSupportedException {
- for (SendTransactionTask.API ver : SendTransactionTask.API.allVersions) {
+ for (API ver : API.allVersions) {
try {
return retrieveTransactionListForVersion(ver);
}
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);
package net.ktnx.mobileledger.async;
-import android.content.res.Resources;
import android.os.AsyncTask;
import android.util.Log;
-import android.util.SparseArray;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
-import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
taskCallback.done(error);
}
- public enum API {
- auto(0), html(-1), v1_14(-2), v1_15(-3), v1_19_1(-4);
- private static final SparseArray<API> map = new SparseArray<>();
- public static API[] allVersions = {v1_19_1, v1_15, v1_14};
-
- static {
- for (API item : API.values()) {
- map.put(item.value, item);
- }
- }
-
- private final int value;
-
- API(int value) {
- this.value = value;
- }
- public static API valueOf(int i) {
- return map.get(i, auto);
- }
- public int toInt() {
- return this.value;
- }
- public String getDescription(Resources resources) {
- switch (this) {
- case auto:
- return resources.getString(R.string.api_auto);
- case html:
- return resources.getString(R.string.api_html);
- case v1_14:
- return resources.getString(R.string.api_1_14);
- case v1_15:
- return resources.getString(R.string.api_1_15);
- case v1_19_1:
- return resources.getString(R.string.api_1_19_1);
- default:
- throw new IllegalStateException("Unexpected value: " + value);
- }
- }
- public String getDescription() {
- switch (this) {
- case auto:
- return "(automatic)";
- case html:
- return "(HTML)";
- case v1_14:
- return "1.14";
- case v1_15:
- return "1.15";
- case v1_19_1:
- return "1.19.1";
- default:
- throw new IllegalStateException("Unexpected value: " + this);
- }
- }
- }
}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe 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 MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.json;
+
+import android.content.res.Resources;
+import android.util.SparseArray;
+
+import net.ktnx.mobileledger.R;
+
+public enum API {
+ auto(0), html(-1), v1_14(-2), v1_15(-3), v1_19_1(-4);
+ private static final SparseArray<API> map = new SparseArray<>();
+ public static API[] allVersions = {v1_19_1, v1_15, v1_14};
+
+ static {
+ for (API item : API.values()) {
+ map.put(item.value, item);
+ }
+ }
+
+ private final int value;
+
+ API(int value) {
+ this.value = value;
+ }
+ public static API valueOf(int i) {
+ return map.get(i, auto);
+ }
+ public int toInt() {
+ return this.value;
+ }
+ public String getDescription(Resources resources) {
+ switch (this) {
+ case auto:
+ return resources.getString(R.string.api_auto);
+ case html:
+ return resources.getString(R.string.api_html);
+ case v1_14:
+ return resources.getString(R.string.api_1_14);
+ case v1_15:
+ return resources.getString(R.string.api_1_15);
+ case v1_19_1:
+ return resources.getString(R.string.api_1_19_1);
+ default:
+ throw new IllegalStateException("Unexpected value: " + value);
+ }
+ }
+ public String getDescription() {
+ switch (this) {
+ case auto:
+ return "(automatic)";
+ case html:
+ return "(HTML)";
+ case v1_14:
+ return "1.14";
+ case v1_15:
+ return "1.15";
+ case v1_19_1:
+ return "1.19.1";
+ default:
+ throw new IllegalStateException("Unexpected value: " + this);
+ }
+ }
+}
import com.fasterxml.jackson.databind.MappingIterator;
import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
-import net.ktnx.mobileledger.async.SendTransactionTask;
import net.ktnx.mobileledger.model.LedgerAccount;
import java.io.IOException;
abstract public class AccountListParser {
protected MappingIterator<net.ktnx.mobileledger.json.ParsedLedgerAccount> iterator;
- public static AccountListParser forApiVersion(SendTransactionTask.API version,
- InputStream input) throws IOException {
+ public static AccountListParser forApiVersion(API version, InputStream input)
+ throws IOException {
switch (version) {
case v1_14:
return new net.ktnx.mobileledger.json.v1_14.AccountListParser(input);
}
}
- public abstract SendTransactionTask.API getApiVersion();
+ public abstract API getApiVersion();
public LedgerAccount nextAccount(RetrieveTransactionsTask task,
HashMap<String, LedgerAccount> map) {
if (!iterator.hasNext())
package net.ktnx.mobileledger.json;
-import net.ktnx.mobileledger.async.SendTransactionTask;
import net.ktnx.mobileledger.model.LedgerTransaction;
import java.io.IOException;
import java.text.ParseException;
public abstract class TransactionListParser {
- public static TransactionListParser forApiVersion(SendTransactionTask.API apiVersion,
- InputStream input) throws IOException {
+ public static TransactionListParser forApiVersion(API apiVersion, InputStream input)
+ throws IOException {
switch (apiVersion) {
case v1_14:
return new net.ktnx.mobileledger.json.v1_14.TransactionListParser(input);
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import java.io.IOException;
import java.io.InputStream;
iterator = reader.readValues(input);
}
@Override
- public SendTransactionTask.API getApiVersion() {
- return SendTransactionTask.API.v1_14;
+ public API getApiVersion() {
+ return API.v1_14;
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import java.io.IOException;
import java.io.InputStream;
iterator = reader.readValues(input);
}
@Override
- public SendTransactionTask.API getApiVersion() {
- return SendTransactionTask.API.v1_15;
+ public API getApiVersion() {
+ return API.v1_15;
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import java.io.IOException;
import java.io.InputStream;
iterator = reader.readValues(input);
}
@Override
- public SendTransactionTask.API getApiVersion() {
- return SendTransactionTask.API.v1_19_1;
+ public API getApiVersion() {
+ return API.v1_19_1;
}
}
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import java.util.Locale;
return ((this.major == major) && (this.minor >= minor)) || (this.major > major);
}
@org.jetbrains.annotations.Nullable
- public SendTransactionTask.API getSuitableApiVersion() {
+ public API getSuitableApiVersion() {
if (isPre_1_20_1)
return null;
- return SendTransactionTask.API.v1_19_1;
+ return API.v1_19_1;
}
}
import net.ktnx.mobileledger.App;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.async.DbOpQueue;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.Misc;
import net.ktnx.mobileledger.utils.SimpleDate;
private String authPassword;
private int themeHue;
private int orderNo = -1;
- private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto;
+ private API apiVersion = API.auto;
private FutureDates futureDates = FutureDates.None;
private boolean accountsLoaded;
private boolean transactionsLoaded;
else
this.defaultCommodity = String.valueOf(defaultCommodity);
}
- public SendTransactionTask.API getApiVersion() {
+ public API getApiVersion() {
return apiVersion;
}
- public void setApiVersion(SendTransactionTask.API apiVersion) {
+ public void setApiVersion(API apiVersion) {
this.apiVersion = apiVersion;
}
public void setApiVersion(int apiVersion) {
- this.apiVersion = SendTransactionTask.API.valueOf(apiVersion);
+ this.apiVersion = API.valueOf(apiVersion);
}
public FutureDates getFutureDates() {
return futureDates;
import net.ktnx.mobileledger.BuildConfig;
import net.ktnx.mobileledger.R;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
PopupMenu menu = new PopupMenu(context, v);
menu.inflate(R.menu.api_version);
menu.setOnMenuItemClickListener(item -> {
- SendTransactionTask.API apiVer;
+ API apiVer;
switch (item.getItemId()) {
case R.id.api_version_menu_html:
- apiVer = SendTransactionTask.API.html;
+ apiVer = API.html;
break;
case R.id.api_version_menu_1_19_1:
- apiVer = SendTransactionTask.API.v1_19_1;
+ apiVer = API.v1_19_1;
break;
case R.id.api_version_menu_1_15:
- apiVer = SendTransactionTask.API.v1_15;
+ apiVer = API.v1_15;
break;
case R.id.api_version_menu_1_14:
- apiVer = SendTransactionTask.API.v1_14;
+ apiVer = API.v1_14;
break;
case R.id.api_version_menu_auto:
default:
- apiVer = SendTransactionTask.API.auto;
+ apiVer = API.auto;
}
model.setApiVersion(apiVer);
apiVersionText.setText(apiVer.getDescription(getResources()));
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
-import net.ktnx.mobileledger.async.SendTransactionTask;
+import net.ktnx.mobileledger.json.API;
import net.ktnx.mobileledger.model.Currency;
import net.ktnx.mobileledger.model.HledgerVersion;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
private final MutableLiveData<Boolean> showCommodityByDefault = new MutableLiveData<>(false);
private final MutableLiveData<Boolean> showCommentsByDefault = new MutableLiveData<>(true);
private final MutableLiveData<Boolean> useAuthentication = new MutableLiveData<>(false);
- private final MutableLiveData<SendTransactionTask.API> apiVersion =
- new MutableLiveData<>(SendTransactionTask.API.auto);
+ private final MutableLiveData<API> apiVersion = new MutableLiveData<>(API.auto);
private final MutableLiveData<String> url = new MutableLiveData<>(null);
private final MutableLiveData<String> authUserName = new MutableLiveData<>(null);
private final MutableLiveData<String> authPassword = new MutableLiveData<>(null);
void observeUseAuthentication(LifecycleOwner lfo, Observer<Boolean> o) {
useAuthentication.observe(lfo, o);
}
- SendTransactionTask.API getApiVersion() {
+ API getApiVersion() {
return apiVersion.getValue();
}
- void setApiVersion(SendTransactionTask.API newValue) {
+ void setApiVersion(API newValue) {
if (newValue != apiVersion.getValue())
apiVersion.setValue(newValue);
}
- void observeApiVersion(LifecycleOwner lfo, Observer<SendTransactionTask.API> o) {
+ void observeApiVersion(LifecycleOwner lfo, Observer<API> o) {
apiVersion.observe(lfo, o);
}
HledgerVersion getDetectedVersion() { return detectedVersion.getValue(); }
showCommentsByDefault.setValue(true);
showCommodityByDefault.setValue(false);
setFutureDates(MobileLedgerProfile.FutureDates.None);
- setApiVersion(SendTransactionTask.API.auto);
+ setApiVersion(API.auto);
useAuthentication.setValue(false);
authUserName.setValue("");
authPassword.setValue("");