X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FLedgerTransaction.java;h=5d5b7d51ed19f14ffe1ca9e464ff7ee7050b355b;hb=e0adac791ac4ccc9629c98ab46189b9f8047e41b;hp=071e0640b693c2f0f39f6cf8e67afaaae5f68cdb;hpb=6291644e547c813c9fd49d684c7755a7a563a10e;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java index 071e0640..5d5b7d51 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java @@ -23,7 +23,7 @@ import android.database.sqlite.SQLiteDatabase; import net.ktnx.mobileledger.utils.Digest; import net.ktnx.mobileledger.utils.Globals; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.text.ParseException; import java.util.ArrayList; @@ -44,6 +44,10 @@ public class LedgerTransaction { .compareTo(o2.getCurrency()); if (res != 0) return res; + res = o1.getComment() + .compareTo(o2.getComment()); + if (res != 0) + return res; return Float.compare(o1.getAmount(), o2.getAmount()); } }; @@ -51,6 +55,7 @@ public class LedgerTransaction { private Integer id; private Date date; private String description; + private String comment; private ArrayList accounts; private String dataHash; private boolean dataLoaded; @@ -107,6 +112,12 @@ public class LedgerTransaction { this.description = description; dataHash = null; } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } public int getId() { return id; } @@ -116,11 +127,14 @@ public class LedgerTransaction { try { Digest sha = new Digest(DIGEST_TYPE); StringBuilder data = new StringBuilder(); + data.append("ver1"); data.append(profile); data.append(getId()); data.append('\0'); data.append(getDescription()); data.append('\0'); + data.append(getComment()); + data.append('\0'); data.append(Globals.formatLedgerDate(getDate())); data.append('\0'); for (LedgerTransactionAccount item : accounts) { @@ -133,7 +147,7 @@ public class LedgerTransaction { data.append(item.getComment()); } sha.update(data.toString() - .getBytes(Charset.forName("UTF-8"))); + .getBytes(StandardCharsets.UTF_8)); dataHash = sha.digestToHexString(); } catch (NoSuchAlgorithmException e) { @@ -157,7 +171,7 @@ public class LedgerTransaction { return; try (Cursor cTr = db.rawQuery( - "SELECT date, description from transactions WHERE profile=? AND id=?", + "SELECT date, description, comment from transactions WHERE profile=? AND id=?", new String[]{profile, String.valueOf(id)})) { if (cTr.moveToFirst()) { @@ -172,10 +186,11 @@ public class LedgerTransaction { dateString, id)); } description = cTr.getString(1); + comment = cTr.getString(2); - try (Cursor cAcc = db.rawQuery("SELECT account_name, amount, currency, comment FROM " + - "transaction_accounts WHERE " + - "profile=? AND transaction_id = ?", + try (Cursor cAcc = db.rawQuery( + "SELECT account_name, amount, currency, comment FROM " + + "transaction_accounts WHERE profile=? AND transaction_id = ?", new String[]{profile, String.valueOf(id)})) { while (cAcc.moveToNext()) {