From af787b1e7a2c3b4052650d55f69a3ff1f0be5b3e Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 9 Dec 2021 21:59:23 +0200 Subject: [PATCH] add support for hledger-web 1.23 json schema --- .../java/net/ktnx/mobileledger/json/API.java | 8 +- .../mobileledger/json/AccountListParser.java | 2 + .../json/TransactionListParser.java | 2 + .../json/v1_23/AccountListParser.java | 40 +++++ .../ktnx/mobileledger/json/v1_23/Gateway.java | 36 ++++ .../mobileledger/json/v1_23/ParsedAmount.java | 62 +++++++ .../json/v1_23/ParsedBalance.java | 33 ++++ .../json/v1_23/ParsedLedgerAccount.java | 53 ++++++ .../json/v1_23/ParsedLedgerTransaction.java | 160 ++++++++++++++++++ .../json/v1_23/ParsedPosting.java | 144 ++++++++++++++++ .../json/v1_23/ParsedPrecision.java | 45 +++++ .../mobileledger/json/v1_23/ParsedPrice.java | 78 +++++++++ .../json/v1_23/ParsedQuantity.java | 23 +++ .../json/v1_23/ParsedSourcePos.java | 44 +++++ .../mobileledger/json/v1_23/ParsedStyle.java | 33 ++++ .../json/v1_23/TransactionListParser.java | 44 +++++ .../ui/profiles/ProfileDetailFragment.java | 3 + app/src/main/res/menu/api_version.xml | 4 + app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 20 files changed, 814 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/AccountListParser.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/Gateway.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedAmount.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedBalance.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerAccount.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerTransaction.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPosting.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrecision.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrice.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedQuantity.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedSourcePos.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedStyle.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/json/v1_23/TransactionListParser.java diff --git a/app/src/main/java/net/ktnx/mobileledger/json/API.java b/app/src/main/java/net/ktnx/mobileledger/json/API.java index d634f29e..136bdf55 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/API.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/API.java @@ -23,9 +23,9 @@ 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); + auto(0), html(-1), v1_14(-2), v1_15(-3), v1_19_1(-4), v1_23(-5); private static final SparseArray map = new SparseArray<>(); - public static API[] allVersions = {v1_19_1, v1_15, v1_14}; + public static API[] allVersions = {v1_23, v1_19_1, v1_15, v1_14}; static { for (API item : API.values()) { @@ -56,6 +56,8 @@ public enum API { return resources.getString(R.string.api_1_15); case v1_19_1: return resources.getString(R.string.api_1_19_1); + case v1_23: + return resources.getString(R.string.api_1_23); default: throw new IllegalStateException("Unexpected value: " + value); } @@ -72,6 +74,8 @@ public enum API { return "1.15"; case v1_19_1: return "1.19.1"; + case v1_23: + return "1.23"; default: throw new IllegalStateException("Unexpected value: " + this); } diff --git a/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java index 872cac79..baeeb2ea 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/AccountListParser.java @@ -39,6 +39,8 @@ abstract public class AccountListParser { return new net.ktnx.mobileledger.json.v1_15.AccountListParser(input); case v1_19_1: return new net.ktnx.mobileledger.json.v1_19_1.AccountListParser(input); + case v1_23: + return new net.ktnx.mobileledger.json.v1_23.AccountListParser(input); default: throw new RuntimeException("Unsupported version " + version.toString()); } diff --git a/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java index d707c062..20bf08b7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/TransactionListParser.java @@ -33,6 +33,8 @@ public abstract class TransactionListParser { return new net.ktnx.mobileledger.json.v1_15.TransactionListParser(input); case v1_19_1: return new net.ktnx.mobileledger.json.v1_19_1.TransactionListParser(input); + case v1_23: + return new net.ktnx.mobileledger.json.v1_23.TransactionListParser(input); default: throw new RuntimeException("Unsupported version " + apiVersion.toString()); } diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/AccountListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/AccountListParser.java new file mode 100644 index 00000000..904fb57f --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/AccountListParser.java @@ -0,0 +1,40 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; + +import net.ktnx.mobileledger.json.API; + +import java.io.IOException; +import java.io.InputStream; + +public class AccountListParser extends net.ktnx.mobileledger.json.AccountListParser { + + public AccountListParser(InputStream input) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + ObjectReader reader = mapper.readerFor(ParsedLedgerAccount.class); + + iterator = reader.readValues(input); + } + @Override + public API getApiVersion() { + return API.v1_19_1; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/Gateway.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/Gateway.java new file mode 100644 index 00000000..c04f6f23 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/Gateway.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +import net.ktnx.mobileledger.model.LedgerTransaction; + +public class Gateway extends net.ktnx.mobileledger.json.Gateway { + @Override + public String transactionSaveRequest(LedgerTransaction ledgerTransaction) + throws JsonProcessingException { + ParsedLedgerTransaction jsonTransaction = + ParsedLedgerTransaction.fromLedgerTransaction(ledgerTransaction); + ObjectMapper mapper = new ObjectMapper(); + ObjectWriter writer = mapper.writerFor(ParsedLedgerTransaction.class); + return writer.writeValueAsString(jsonTransaction); + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedAmount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedAmount.java new file mode 100644 index 00000000..58f88c16 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedAmount.java @@ -0,0 +1,62 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedAmount { + private String acommodity; + private ParsedQuantity aquantity; + private boolean aismultiplier; + private ParsedStyle astyle; + private ParsedPrice aprice; + public ParsedAmount() { + } + public ParsedPrice getAprice() { + return aprice; + } + public void setAprice(ParsedPrice aprice) { + this.aprice = aprice; + } + public String getAcommodity() { + return acommodity; + } + public void setAcommodity(String acommodity) { + this.acommodity = acommodity; + } + public ParsedQuantity getAquantity() { + return aquantity; + } + public void setAquantity(ParsedQuantity aquantity) { + this.aquantity = aquantity; + } + public boolean isAismultiplier() { + return aismultiplier; + } + public void setAismultiplier(boolean aismultiplier) { + this.aismultiplier = aismultiplier; + } + public ParsedStyle getAstyle() { + return astyle; + } + public void setAstyle(ParsedStyle astyle) { + this.astyle = astyle; + } + +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedBalance.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedBalance.java new file mode 100644 index 00000000..4f74de41 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedBalance.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedBalance extends net.ktnx.mobileledger.json.ParsedBalance { + private ParsedStyle astyle; + public ParsedBalance() { + } + public ParsedStyle getAstyle() { + return astyle; + } + public void setAstyle(ParsedStyle astyle) { + this.astyle = astyle; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerAccount.java new file mode 100644 index 00000000..6d942e83 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerAccount.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.util.ArrayList; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedLedgerAccount extends net.ktnx.mobileledger.json.ParsedLedgerAccount { + private List aebalance; + private List aibalance; + public ParsedLedgerAccount() { + } + public List getAibalance() { + return aibalance; + } + public void setAibalance(List aibalance) { + this.aibalance = aibalance; + } + public List getAebalance() { + return aebalance; + } + public void setAebalance(List aebalance) { + this.aebalance = aebalance; + } + @Override + public List getSimpleBalance() { + List result = new ArrayList(); + for (ParsedBalance b : getAibalance()) { + result.add(new SimpleBalance(b.getAcommodity(), b.getAquantity() + .asFloat())); + } + + return result; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerTransaction.java new file mode 100644 index 00000000..fe0a2809 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedLedgerTransaction.java @@ -0,0 +1,160 @@ +/* + * Copyright © 2021 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import net.ktnx.mobileledger.model.LedgerTransaction; +import net.ktnx.mobileledger.model.LedgerTransactionAccount; +import net.ktnx.mobileledger.utils.Globals; +import net.ktnx.mobileledger.utils.Misc; +import net.ktnx.mobileledger.utils.SimpleDate; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.ParsedLedgerTransaction { + private String tdate; + private String tdate2 = null; + private String tdescription; + private String tcomment; + private String tcode = ""; + private String tstatus = "Unmarked"; + private String tprecedingcomment = ""; + private int tindex; + private List tpostings; + private List> ttags = new ArrayList<>(); + private List tsourcepos = new ArrayList<>(); + public ParsedLedgerTransaction() { + } + public static ParsedLedgerTransaction fromLedgerTransaction(LedgerTransaction tr) { + ParsedLedgerTransaction result = new ParsedLedgerTransaction(); + result.setTcomment(Misc.nullIsEmpty(tr.getComment())); + result.setTprecedingcomment(""); + + ArrayList postings = new ArrayList<>(); + for (LedgerTransactionAccount acc : tr.getAccounts()) { + if (!acc.getAccountName() + .isEmpty()) + postings.add(ParsedPosting.fromLedgerAccount(acc)); + } + + result.setTpostings(postings); + SimpleDate transactionDate = tr.getDateIfAny(); + if (transactionDate == null) { + transactionDate = SimpleDate.today(); + } + result.setTdate(Globals.formatIsoDate(transactionDate)); + result.setTdate2(null); + result.setTindex(1); + result.setTdescription(tr.getDescription()); + return result; + } + public String getTcode() { + return tcode; + } + public void setTcode(String tcode) { + this.tcode = tcode; + } + public String getTstatus() { + return tstatus; + } + public void setTstatus(String tstatus) { + this.tstatus = tstatus; + } + public List> getTtags() { + return ttags; + } + public void setTtags(List> ttags) { + this.ttags = ttags; + } + public List getTsourcepos() { + return tsourcepos; + } + public void setTsourcepos(List tsourcepos) { + this.tsourcepos = tsourcepos; + } + public String getTprecedingcomment() { + return tprecedingcomment; + } + public void setTprecedingcomment(String tprecedingcomment) { + this.tprecedingcomment = tprecedingcomment; + } + public String getTdate() { + return tdate; + } + public void setTdate(String tdate) { + this.tdate = tdate; + } + public String getTdate2() { + return tdate2; + } + public void setTdate2(String tdate2) { + this.tdate2 = tdate2; + } + public String getTdescription() { + return tdescription; + } + public void setTdescription(String tdescription) { + this.tdescription = tdescription; + } + public String getTcomment() { + return tcomment; + } + public void setTcomment(String tcomment) { + this.tcomment = tcomment; + } + public int getTindex() { + return tindex; + } + public void setTindex(int tindex) { + this.tindex = tindex; + if (tpostings != null) + for (ParsedPosting p : tpostings) { + p.setPtransaction_(tindex); + } + } + public List getTpostings() { + return tpostings; + } + public void setTpostings(List tpostings) { + this.tpostings = tpostings; + } + public void addPosting(ParsedPosting posting) { + posting.setPtransaction_(tindex); + tpostings.add(posting); + } + public LedgerTransaction asLedgerTransaction() throws ParseException { + SimpleDate date = Globals.parseIsoDate(tdate); + LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription); + tr.setComment(Misc.trim(Misc.emptyIsNull(tcomment))); + + List postings = tpostings; + + if (postings != null) { + for (ParsedPosting p : postings) { + tr.addAccount(p.asLedgerAccount()); + } + } + + tr.markDataAsLoaded(); + return tr; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPosting.java new file mode 100644 index 00000000..8f0cdbcd --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPosting.java @@ -0,0 +1,144 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import net.ktnx.mobileledger.model.LedgerTransactionAccount; + +import java.util.ArrayList; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedPosting extends net.ktnx.mobileledger.json.ParsedPosting { + private Void pbalanceassertion; + private String pstatus = "Unmarked"; + private String paccount; + private List pamount; + private String pdate = null; + private String pdate2 = null; + private String ptype = "RegularPosting"; + private String pcomment = ""; + private List> ptags = new ArrayList<>(); + private String poriginal = null; + private int ptransaction_; + public ParsedPosting() { + } + public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) { + ParsedPosting result = new ParsedPosting(); + result.setPaccount(acc.getAccountName()); + + String comment = acc.getComment(); + if (comment == null) + comment = ""; + result.setPcomment(comment); + + ArrayList amounts = new ArrayList<>(); + ParsedAmount amt = new ParsedAmount(); + amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency()); + amt.setAismultiplier(false); + ParsedQuantity qty = new ParsedQuantity(); + qty.setDecimalPlaces(2); + qty.setDecimalMantissa(Math.round(acc.getAmount() * 100)); + amt.setAquantity(qty); + ParsedStyle style = new ParsedStyle(); + style.setAscommodityside(getCommoditySide()); + style.setAscommodityspaced(getCommoditySpaced()); + style.setAsprecision(new ParsedPrecision(2)); + style.setAsdecimalpoint('.'); + amt.setAstyle(style); + if (acc.getCurrency() != null) + amt.setAcommodity(acc.getCurrency()); + amounts.add(amt); + result.setPamount(amounts); + return result; + } + public String getPdate2() { + return pdate2; + } + public void setPdate2(String pdate2) { + this.pdate2 = pdate2; + } + public int getPtransaction_() { + return ptransaction_; + } + public void setPtransaction_(int ptransaction_) { + this.ptransaction_ = ptransaction_; + } + public String getPdate() { + return pdate; + } + public void setPdate(String pdate) { + this.pdate = pdate; + } + public String getPtype() { + return ptype; + } + public void setPtype(String ptype) { + this.ptype = ptype; + } + public String getPcomment() { + return pcomment; + } + public void setPcomment(String pcomment) { + this.pcomment = (pcomment == null) ? null : pcomment.trim(); + } + public List> getPtags() { + return ptags; + } + public void setPtags(List> ptags) { + this.ptags = ptags; + } + public String getPoriginal() { + return poriginal; + } + public void setPoriginal(String poriginal) { + this.poriginal = poriginal; + } + public String getPstatus() { + return pstatus; + } + public void setPstatus(String pstatus) { + this.pstatus = pstatus; + } + public Void getPbalanceassertion() { + return pbalanceassertion; + } + public void setPbalanceassertion(Void pbalanceassertion) { + this.pbalanceassertion = pbalanceassertion; + } + public String getPaccount() { + return paccount; + } + public void setPaccount(String paccount) { + this.paccount = paccount; + } + public List getPamount() { + return pamount; + } + public void setPamount(List pamount) { + this.pamount = pamount; + } + public LedgerTransactionAccount asLedgerAccount() { + ParsedAmount amt = pamount.get(0); + return new LedgerTransactionAccount(paccount, amt.getAquantity() + .asFloat(), amt.getAcommodity(), + getPcomment()); + } + +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrecision.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrecision.java new file mode 100644 index 00000000..ffaac7db --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrecision.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +class ParsedPrecision { + private int contents; + private String tag; + ParsedPrecision() { + tag = "NaturalPrecision"; + } + ParsedPrecision(int contents) { + this.contents = contents; + tag = "Precision"; + } + public int getContents() { + return contents; + } + public void setContents(int contents) { + this.contents = contents; + } + public String getTag() { + return tag; + } + public void setTag(String tag) { + this.tag = tag; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrice.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrice.java new file mode 100644 index 00000000..80a810a6 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedPrice.java @@ -0,0 +1,78 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +class ParsedPrice { + private String tag; + private Contents contents; + public ParsedPrice() { + tag = "NoPrice"; + } + public Contents getContents() { + return contents; + } + public void setContents(Contents contents) { + this.contents = contents; + } + public String getTag() { + return tag; + } + public void setTag(String tag) { + this.tag = tag; + } + private static class Contents { + private ParsedPrice aprice; + private ParsedQuantity aquantity; + private String acommodity; + private boolean aismultiplier; + private ParsedStyle astyle; + public Contents() { + acommodity = ""; + } + public ParsedPrice getAprice() { + return aprice; + } + public void setAprice(ParsedPrice aprice) { + this.aprice = aprice; + } + public ParsedQuantity getAquantity() { + return aquantity; + } + public void setAquantity(ParsedQuantity aquantity) { + this.aquantity = aquantity; + } + public String getAcommodity() { + return acommodity; + } + public void setAcommodity(String acommodity) { + this.acommodity = acommodity; + } + public boolean isAismultiplier() { + return aismultiplier; + } + public void setAismultiplier(boolean aismultiplier) { + this.aismultiplier = aismultiplier; + } + public ParsedStyle getAstyle() { + return astyle; + } + public void setAstyle(ParsedStyle astyle) { + this.astyle = astyle; + } + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedQuantity.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedQuantity.java new file mode 100644 index 00000000..55026935 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedQuantity.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedQuantity extends net.ktnx.mobileledger.json.ParsedQuantity {} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedSourcePos.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedSourcePos.java new file mode 100644 index 00000000..6a62f8dd --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedSourcePos.java @@ -0,0 +1,44 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +class ParsedSourcePos { + private String sourceName; + private int sourceLine; + private int sourceColumn; + public ParsedSourcePos() { + } + public String getSourceName() { + return sourceName; + } + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + public int getSourceLine() { + return sourceLine; + } + public void setSourceLine(int sourceLine) { + this.sourceLine = sourceLine; + } + public int getSourceColumn() { + return sourceColumn; + } + public void setSourceColumn(int sourceColumn) { + this.sourceColumn = sourceColumn; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedStyle.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedStyle.java new file mode 100644 index 00000000..c9bf8bef --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/ParsedStyle.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParsedStyle extends net.ktnx.mobileledger.json.ParsedStyle { + private ParsedPrecision asprecision; + public ParsedStyle() { + } + public ParsedPrecision getAsprecision() { + return asprecision; + } + public void setAsprecision(ParsedPrecision asprecision) { + this.asprecision = asprecision; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_23/TransactionListParser.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/TransactionListParser.java new file mode 100644 index 00000000..7f5350a4 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_23/TransactionListParser.java @@ -0,0 +1,44 @@ +/* + * 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 . + */ + +package net.ktnx.mobileledger.json.v1_23; + +import com.fasterxml.jackson.databind.MappingIterator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; + +import net.ktnx.mobileledger.model.LedgerTransaction; + +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; + +public class TransactionListParser extends net.ktnx.mobileledger.json.TransactionListParser { + + private final MappingIterator iterator; + + public TransactionListParser(InputStream input) throws IOException { + + ObjectMapper mapper = new ObjectMapper(); + ObjectReader reader = mapper.readerFor(ParsedLedgerTransaction.class); + iterator = reader.readValues(input); + } + public LedgerTransaction nextTransaction() throws ParseException { + return iterator.hasNext() ? iterator.next() + .asLedgerTransaction() : null; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index ab0d07d9..99934543 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -341,6 +341,9 @@ public class ProfileDetailFragment extends Fragment { if (itemId == R.id.api_version_menu_html) { apiVer = API.html; } + else if (itemId == R.id.api_version_menu_1_23) { + apiVer = API.v1_23; + } else if (itemId == R.id.api_version_menu_1_19_1) { apiVer = API.v1_19_1; } diff --git a/app/src/main/res/menu/api_version.xml b/app/src/main/res/menu/api_version.xml index cdcb09f2..53da72fb 100644 --- a/app/src/main/res/menu/api_version.xml +++ b/app/src/main/res/menu/api_version.xml @@ -21,6 +21,10 @@ android:id="@+id/api_version_menu_auto" android:title="@string/api_auto" /> + Успешно възстановяване на настройките … а може и да възстановите настройките от резервно копие Недостъпен профил + Версия 1.23 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a709d924..d4fec3ac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,4 +210,5 @@ Configuration restored successfully … or, you may restore from backup Profile not available + Version 1.23 -- 2.39.2