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());
private final PossiblyMatchedValue<Float> amount =
PossiblyMatchedValue.withLiteralFloat(0f);
private final PossiblyMatchedValue<Currency> 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();
}
}
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();
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;
}
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) {
b.patternDetailsAccountAmount.setText(Data.formatNumber(amt));
});
+
+ b.negateAmountSwitch.setOnCheckedChangeListener(
+ (buttonView, isChecked) -> getItem().setNegateAmount(isChecked));
}
@Override
void bind(PatternDetailsItem item) {
Float amt = accRow.getAmount();
b.patternDetailsAccountAmount.setText((amt == null) ? null : String.format(
Data.locale.getValue(), "%,4.2f", (accRow.getAmount())));
+ b.negateAmountSwitch.setVisibility(View.GONE);
}
else {
b.patternDetailsAccountAmountSource.setText(
String.format(Locale.US, "Group %d (%s)", accRow.getAmountMatchGroup(),
getMatchGroupText(accRow.getAmountMatchGroup())));
b.patternDetailsAccountAmountLayout.setVisibility(View.GONE);
+ b.negateAmountSwitch.setVisibility(View.VISIBLE);
+ b.negateAmountSwitch.setChecked(accRow.isNegateAmount());
}
b.patternAccountNameSourceLabel.setOnClickListener(
paDAO.update(dbAccount);
Logger.debug("pattern-db", String.format(Locale.US,
- "Stored pattern account %d, account=%s, comment=%s, item=%s",
+ "Stored pattern account %d, account=%s, comment=%s, neg=%s, item=%s",
dbAccount.getId(), dbAccount.getAccountName(),
- dbAccount.getAccountComment(), accRowItem));
+ dbAccount.getAccountComment(), dbAccount.getNegateAmount(), accRowItem));
}
});
}
android:paddingTop="@dimen/text_margin"
android:text="@string/account_amount_source_label"
android:textAppearance="?attr/textAppearanceListItem"
- app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintEnd_toStartOf="@id/negate_amount_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/pattern_details_account_comment_layout"
/>
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"
/>
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/negate_amount_switch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintBottom_toBottomOf="@id/pattern_details_account_amount_source"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="@id/pattern_account_amount_source_label"
+ />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/pattern_details_account_amount_layout"
android:layout_width="match_parent"