From: Damyan Ivanov Date: Sun, 14 Jun 2020 11:23:42 +0000 (+0300) Subject: add support for transaction-level comments in the JSON-based parser X-Git-Tag: v0.14.0~30 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=4b22cf80c51f475d28d4779975effb9882aa3a6e;p=mobile-ledger.git add support for transaction-level comments in the JSON-based parser --- diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java index 058319a3..926717cc 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedLedgerTransaction.java @@ -22,6 +22,7 @@ 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 java.text.ParseException; import java.util.ArrayList; @@ -146,6 +147,7 @@ public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.Parse public LedgerTransaction asLedgerTransaction() throws ParseException { Date date = Globals.parseIsoDate(tdate); LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription); + tr.setComment(Misc.trim(Misc.emptyIsNull(tcomment))); List postings = tpostings; diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java index 1cffcfac..305a2ade 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedLedgerTransaction.java @@ -22,6 +22,7 @@ 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 java.text.ParseException; import java.util.ArrayList; @@ -144,6 +145,7 @@ public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.Parse public LedgerTransaction asLedgerTransaction() throws ParseException { Date date = Globals.parseIsoDate(tdate); LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription); + tr.setComment(Misc.trim(Misc.emptyIsNull(tcomment))); List postings = tpostings; diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java index c4dc7875..b912541f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java @@ -21,6 +21,7 @@ import android.app.Activity; import android.content.res.Configuration; import android.view.WindowManager; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -77,4 +78,10 @@ public class Misc { return true; return text.length() == 0; } + public static String trim(@Nullable String string) { + if (string == null) + return null; + + return string.trim(); + } }