private Observer<Currency> currencyObserver;
private Observer<Boolean> showCurrencyObserver;
private Observer<String> commentObserver;
+ private Observer<Boolean> amountValidityObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
private View commentButton;
});
transactionCommentLayout.findViewById(R.id.comment_button)
- .setOnClickListener(v -> {
- tvTransactionComment.setVisibility(View.VISIBLE);
- tvTransactionComment.requestFocus();
- });
+ .setOnClickListener(v -> {
+ tvTransactionComment.setVisibility(View.VISIBLE);
+ tvTransactionComment.requestFocus();
+ });
mProfile = Data.profile.getValue();
if (mProfile == null)
if (id == R.id.comment) {
commentFocusChanged(commentLayout, tvComment, hasFocus);
}
- else if ( id == R.id.transaction_comment) {
+ else if (id == R.id.transaction_comment) {
commentFocusChanged(transactionCommentLayout, tvTransactionComment, hasFocus);
}
};
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
- // only one decimal separator is allowed
- // plus and minus are allowed only at the beginning
- String allowed = "0123456789";
- String val = s.toString();
- Logger.debug("input", val);
- if (val.isEmpty() || (tvAmount.getSelectionStart() == 0))
- allowed += "-";
- if (!val.contains(decimalSeparator) && !val.contains(decimalDot))
- allowed += decimalSeparator + decimalDot;
-
- tvAmount.setKeyListener(DigitsKeyListener.getInstance(allowed));
- }
if (syncData())
adapter.checkTransactionSubmittable();
transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE);
};
+
+ amountValidityObserver = valid -> {
+ tvAmount.setCompoundDrawablesRelativeWithIntrinsicBounds(
+ valid ? 0 : R.drawable.ic_error_outline_black_24dp, 0, 0, 0);
+ tvAmount.setMinEms(valid ? 4 : 5);
+ };
}
private void commentFocusChanged(View layout, TextView textView, boolean hasFocus) {
int textColor;
if (amount.isEmpty()) {
account.resetAmount();
-// account.setCurrency(null);
+ item.validateAmount();
}
else {
try {
amount = amount.replace(decimalSeparator, decimalDot);
account.setAmount(Float.parseFloat(amount));
+ item.validateAmount();
}
catch (NumberFormatException e) {
Logger.debug("new-trans", String.format(
"assuming amount is not set due to number format exception. " +
"input was '%s'", amount));
- account.resetAmount();
+ account.invalidateAmount();
+ item.invalidateAmount();
}
final String curr = String.valueOf(tvCurrency.getText());
if (curr.equals(tvCurrency.getContext()
this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
this.item.stopObservingComment(commentObserver);
this.item.getModel().showComments.removeObserver(showCommentsObserver);
+ this.item.stopObservingAmountValidity(amountValidityObserver);
this.item = null;
}
item.observeComment(activity, commentObserver);
item.getModel()
.observeAccountCount(activity, accountCountObserver);
+ item.observeAmountValidity(activity, amountValidityObserver);
break;
}
}