private AutoCompleteTextView tvDescription;
private AutoCompleteTextView tvAccount;
private TextView tvComment;
- private TextView tvAmount;
+ private EditText tvAmount;
private LinearLayout lHead;
private ViewGroup lAccount;
private FrameLayout lPadding;
private Observer<Boolean> editableObserver;
private Observer<Boolean> commentVisibleObserver;
private Observer<String> commentObserver;
+ private Observer<Locale> localeObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
private View commentButton;
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();
- if (val.isEmpty())
- tvAmount.setKeyListener(DigitsKeyListener.getInstance(
- "0123456789+-" + decimalSeparator + decimalDot));
- else if (val.contains(decimalSeparator) || val.contains(decimalDot))
- tvAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
- else
- tvAmount.setKeyListener(DigitsKeyListener.getInstance(
- "0123456789" + decimalSeparator + decimalDot));
+ if (val.isEmpty() || (tvAmount.getSelectionStart() == 0))
+ allowed += "-";
+ if (!val.contains(decimalSeparator) && !val.contains(decimalDot))
+ allowed += decimalSeparator + decimalDot;
+
+ tvAmount.setKeyListener(DigitsKeyListener.getInstance(allowed));
syncData();
adapter.model.checkTransactionSubmittable(adapter);
tvComment.addTextChangedListener(tw);
tvAmount.addTextChangedListener(amountWatcher);
- // FIXME: react on locale changes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
tvAmount.setKeyListener(DigitsKeyListener.getInstance(Locale.getDefault(), true, true));
else
else
tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT);
};
+
+ localeObserver = locale -> {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ tvAmount.setKeyListener(DigitsKeyListener.getInstance(locale, true, true));
+ };
}
private void setEditable(Boolean editable) {
tvDate.setEnabled(editable);
.stopObservingFocusedItem(focusedAccountObserver);
this.item.getModel()
.stopObservingAccountCount(accountCountObserver);
+ Data.locale.removeObserver(localeObserver);
this.item = null;
}
.observeFocusedItem(activity, focusedAccountObserver);
item.getModel()
.observeAccountCount(activity, accountCountObserver);
+ Data.locale.observe(activity, localeObserver);
}
}
finally {