+ public synchronized void loadData(SQLiteDatabase db) {
+ if (dataLoaded)
+ return;
+
+ try (Cursor cTr = db.rawQuery(
+ "SELECT year, month, day, description, comment from transactions WHERE profile=? " +
+ "AND id=?", new String[]{profile, String.valueOf(id)}))
+ {
+ if (cTr.moveToFirst()) {
+ date = new SimpleDate(cTr.getInt(0), cTr.getInt(1), cTr.getInt(2));
+ description = cTr.getString(3);
+ comment = cTr.getString(4);
+
+ accounts.clear();
+
+ 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()) {
+// debug("transactions",
+// String.format("Loaded %d: %s %1.2f %s", id, cAcc.getString(0),
+// cAcc.getFloat(1), cAcc.getString(2)));
+ addAccount(new LedgerTransactionAccount(cAcc.getString(0), cAcc.getFloat(1),
+ cAcc.getString(2), cAcc.getString(3)));
+ }
+
+ finishLoading();
+ }
+ }
+ }
+
+ }
+ public String getDataHash() {
+ fillDataHash();
+ return dataHash;
+ }
+ 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;
+ }
+ public void markDataAsLoaded() {
+ dataLoaded = true;
+ }