X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FLedgerTransaction.java;h=6a8234f28dc8d7145f8cd578db2353f8f5f41aad;hb=bb80733ae688904e35d325df315505c95ee041dd;hp=5bc8456bb4b81b8939e3b088ad1c9470ad8db0ca;hpb=2c14b80572cc9199f7ed0171786a04931075b50d;p=mobile-ledger.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 5bc8456b..6a8234f2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java @@ -21,6 +21,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.utils.Digest; @@ -35,25 +36,21 @@ import java.util.Comparator; public class LedgerTransaction { private static final String DIGEST_TYPE = "SHA-256"; - public final Comparator comparator = - new Comparator() { - @Override - public int compare(LedgerTransactionAccount o1, LedgerTransactionAccount o2) { - int res = o1.getAccountName() - .compareTo(o2.getAccountName()); - if (res != 0) - return res; - res = o1.getCurrency() - .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()); - } - }; + public final Comparator comparator = (o1, o2) -> { + int res = o1.getAccountName() + .compareTo(o2.getAccountName()); + if (res != 0) + return res; + res = o1.getCurrency() + .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()); + }; private String profile; private Integer id; private SimpleDate date; @@ -77,7 +74,7 @@ public class LedgerTransaction { dataLoaded = false; } public LedgerTransaction(Integer id, SimpleDate date, String description) { - this(id, date, description, Data.profile.getValue()); + this(id, date, description, Data.getProfile()); } public LedgerTransaction(SimpleDate date, String description) { this(null, date, description); @@ -101,6 +98,10 @@ public class LedgerTransaction { accounts.add(item); dataHash = null; } + @Nullable + public SimpleDate getDateIfAny() { + return date; + } @NonNull public SimpleDate getDate() { loadData(App.getDatabase()); @@ -214,4 +215,27 @@ public class LedgerTransaction { public void finishLoading() { dataLoaded = true; } + @Override + public boolean equals(@Nullable Object obj) { + if (obj == null) + return false; + if (!obj.getClass() + .equals(this.getClass())) + return false; + + return ((LedgerTransaction) obj).getDataHash() + .equals(getDataHash()); + } + + public boolean hasAccountNamedLike(String name) { + name = name.toUpperCase(); + for (LedgerTransactionAccount acc : accounts) { + if (acc.getAccountName() + .toUpperCase() + .contains(name)) + return true; + } + + return false; + } }