From: Damyan Ivanov Date: Sun, 31 Jan 2021 20:00:41 +0000 (+0200) Subject: ui/machinery support for negated pattern amounts X-Git-Tag: v0.17.0~180 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=ea6e0ebc968bb3a3b7fb913d9e0282d374957815;p=mobile-ledger.git ui/machinery support for negated pattern amounts --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java index 52fa1dc7..eeab37ae 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/PatternDetailsItem.java @@ -114,8 +114,11 @@ abstract public class PatternDetailsItem { acc.setCurrencyMatchGroup(pa.getCurrencyMatchGroup()); final Integer amountMatchGroup = pa.getAmountMatchGroup(); - if (amountMatchGroup != null && amountMatchGroup > 0) + if (amountMatchGroup != null && amountMatchGroup > 0) { acc.setAmountMatchGroup(amountMatchGroup); + final Boolean negateAmount = pa.getNegateAmount(); + acc.setNegateAmount(negateAmount != null && negateAmount); + } else acc.setAmount(pa.getAmount()); @@ -274,9 +277,16 @@ abstract public class PatternDetailsItem { private final PossiblyMatchedValue amount = PossiblyMatchedValue.withLiteralFloat(0f); private final PossiblyMatchedValue currency = new PossiblyMatchedValue<>(); + private boolean negateAmount; private AccountRow() { super(Type.ACCOUNT_ITEM); } + public boolean isNegateAmount() { + return negateAmount; + } + public void setNegateAmount(boolean negateAmount) { + this.negateAmount = negateAmount; + } public int getAccountCommentMatchGroup() { return accountComment.getMatchGroup(); } @@ -343,7 +353,7 @@ abstract public class PatternDetailsItem { } public boolean equalContents(AccountRow o) { return amount.equals(o.amount) && accountName.equals(o.accountName) && - accountComment.equals(o.accountComment); + accountComment.equals(o.accountComment) && negateAmount == o.negateAmount; } public void switchToLiteralAmount() { amount.switchToLiteral(); @@ -367,10 +377,14 @@ abstract public class PatternDetailsItem { else result.setAccountCommentMatchGroup(accountComment.getMatchGroup()); - if (amount.hasLiteralValue()) + if (amount.hasLiteralValue()) { result.setAmount(amount.getValue()); - else + result.setNegateAmount(null); + } + else { result.setAmountMatchGroup(amount.getMatchGroup()); + result.setNegateAmount(negateAmount ? true : null); + } return result; } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java index cdd06c09..140b3a74 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java @@ -262,7 +262,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { acc.getAccountComment()); Float amount = extractFloatFromMatches(m, acc.getAmountMatchGroup(), acc.getAmount()); - if (amount != null && acc.getNegateAmount()) + if (amount != null && acc.getNegateAmount() != null && acc.getNegateAmount()) amount = -amount; if (accountsInInitialState) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java index 1484eab7..c7f42ec1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternDetailsAdapter.java @@ -502,6 +502,9 @@ class PatternDetailsAdapter extends RecyclerView.Adapter getItem().setNegateAmount(isChecked)); } @Override void bind(PatternDetailsItem item) { @@ -539,12 +542,15 @@ class PatternDetailsAdapter extends RecyclerView.Adapter @@ -128,10 +128,18 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:textAppearance="?attr/textAppearanceListItemSecondary" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@id/negate_amount_switch" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/pattern_account_amount_source_label" /> +