X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionModel.java;h=f17f77b17b1c97c8e2e461779c751c95f1456f0b;hb=3173a61c334646acf7cdd776b1001243dddd1baa;hp=2bcf82fb8d46ce3d54d193436087eaf4bba83ba4;hpb=916547239190f7daf921f2066593637cfca877fc;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index 2bcf82fb..f17f77b1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -29,6 +29,7 @@ import androidx.lifecycle.Observer; 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; @@ -100,7 +101,9 @@ public class NewTransactionModel extends ViewModel { * make old items replaceable in-place. makes the new values visually blend in */ private void renumberItems() { - final List list = items.getValue(); + renumberItems(items.getValue()); + } + private void renumberItems(List list) { if (list == null) { return; } @@ -189,8 +192,10 @@ public class NewTransactionModel extends ViewModel { List list = new ArrayList<>(); Item.resetIdDispenser(); list.add(new TransactionHead("")); - list.add(new TransactionAccount("")); - list.add(new TransactionAccount("")); + final String defaultCurrency = Objects.requireNonNull(Data.getProfile()) + .getDefaultCommodity(); + list.add(new TransactionAccount("", defaultCurrency)); + list.add(new TransactionAccount("", defaultCurrency)); noteFocusChanged(0, FocusedElement.Description); renumberItems(); isSubmittable.setValue(false); @@ -259,7 +264,6 @@ public class NewTransactionModel extends ViewModel { if (Misc.emptyIsNull(transactionComment) != null) head.setComment(transactionComment); - Item.resetIdDispenser(); List newItems = new ArrayList<>(); newItems.add(head); @@ -290,25 +294,31 @@ public class NewTransactionModel extends ViewModel { 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); } + renumberItems(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)); } @@ -325,7 +335,7 @@ public class NewTransactionModel extends ViewModel { if (group != null) { int grp = group; - if (grp > 0 & grp <= m.groupCount()) + if (grp > 0 && grp <= m.groupCount()) return m.group(grp); } @@ -337,7 +347,7 @@ public class NewTransactionModel extends ViewModel { 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)); } @@ -463,8 +473,12 @@ public class NewTransactionModel extends ViewModel { List 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);