package net.ktnx.mobileledger.ui.new_transaction;
import android.annotation.SuppressLint;
-import android.os.Handler;
-import android.os.Looper;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import net.ktnx.mobileledger.BuildConfig;
+import net.ktnx.mobileledger.db.Currency;
import net.ktnx.mobileledger.db.DB;
import net.ktnx.mobileledger.db.Profile;
import net.ktnx.mobileledger.db.TemplateAccount;
if (amount != null && acc.getNegateAmount() != null && acc.getNegateAmount())
amount = -amount;
- // TODO currency
TransactionAccount accRow = new TransactionAccount(accountName);
accRow.setComment(accountComment);
if (amount != null)
accRow.setAmount(amount);
+ accRow.setCurrency(
+ extractCurrencyFromMatches(matchResult, acc.getCurrencyMatchGroup(),
+ acc.getCurrencyObject()));
newItems.add(accRow);
}
- new Handler(Looper.getMainLooper()).post(() -> replaceItems(newItems));
+ Misc.onMainThread(() -> replaceItems(newItems));
});
}
+ private String extractCurrencyFromMatches(MatchResult m, Integer group, Currency literal) {
+ return extractStringFromMatches(m, group, (literal == null) ? "" : literal.getName());
+ }
private int extractIntFromMatches(MatchResult m, Integer group, Integer literal) {
if (literal != null)
return literal;
if (group != null) {
int grp = group;
- if (grp > 0 & grp <= m.groupCount())
+ if (grp > 0 && grp <= m.groupCount())
try {
return Integer.parseInt(m.group(grp));
}
if (group != null) {
int grp = group;
- if (grp > 0 & grp <= m.groupCount())
+ if (grp > 0 && grp <= m.groupCount())
return m.group(grp);
}
if (group != null) {
int grp = group;
- if (grp > 0 & grp <= m.groupCount())
+ if (grp > 0 && grp <= m.groupCount())
try {
return Float.valueOf(m.group(grp));
}
List<Item> list = Objects.requireNonNull(items.getValue());
TransactionHead head = list.get(0)
.toTransactionHead();
- SimpleDate date = head.getDate();
LedgerTransaction tr = head.asLedgerTransaction();
tr.setComment(head.getComment());
List<Item> newList = new ArrayList<>();
Item.resetIdDispenser();
+ Item currentHead = items.getValue()
+ .get(0);
TransactionHead head = new TransactionHead(tr.transaction.getDescription());
head.setComment(tr.transaction.getComment());
+ if (currentHead instanceof TransactionHead)
+ head.setDate(((TransactionHead) currentHead).date);
newList.add(head);
moveItemLast(newList, singlePositiveIndex);
}
- new Handler(Looper.getMainLooper()).post(() -> {
+ Misc.onMainThread(() -> {
setItems(newList);
noteFocusChanged(1, FocusedElement.Amount);
});
return ItemType.generalData;
}
public LedgerTransaction asLedgerTransaction() {
- return new LedgerTransaction(0, date, description, Data.getProfile());
+ return new LedgerTransaction(0, (date == null) ? SimpleDate.today() : date, description,
+ Data.getProfile());
}
public boolean equalContents(TransactionHead other) {
if (other == null)