commentFocusChanged(b.comment, false);
adapter.model.getFocusInfo()
- .observe(activity, focusInfo -> {
- if (ignoreFocusChanges) {
- Logger.debug("new-trans", "Ignoring focus change");
- return;
- }
- ignoreFocusChanges = true;
- try {
- if (((focusInfo == null) || (focusInfo.element == null) ||
- focusInfo.position != getAdapterPosition()) ||
- itemView.hasFocus())
- return;
-
- NewTransactionModel.Item item = getItem();
- if (item instanceof NewTransactionModel.TransactionHead) {
- NewTransactionModel.TransactionHead head =
- item.toTransactionHead();
- // bad idea - double pop-up, and not really necessary.
- // the user can tap the input to get the calendar
- //if (!tvDate.hasFocus()) tvDate.requestFocus();
- switch (focusInfo.element) {
- case TransactionComment:
- b.transactionComment.setVisibility(View.VISIBLE);
- b.transactionComment.requestFocus();
- break;
- case Description:
- boolean focused =
- b.newTransactionDescription.requestFocus();
-// tvDescription.dismissDropDown();
- if (focused)
- Misc.showSoftKeyboard(
- (NewTransactionActivity) b.getRoot()
- .getContext());
- break;
- }
- }
- else if (item instanceof NewTransactionModel.TransactionAccount) {
- NewTransactionModel.TransactionAccount acc =
- item.toTransactionAccount();
- switch (focusInfo.element) {
- case Amount:
- b.accountRowAccAmounts.requestFocus();
- break;
- case Comment:
- b.comment.setVisibility(View.VISIBLE);
- b.comment.requestFocus();
- break;
- case Account:
- boolean focused = b.accountRowAccName.requestFocus();
-// b.accountRowAccName.dismissDropDown();
- if (focused)
- Misc.showSoftKeyboard(
- (NewTransactionActivity) b.getRoot()
- .getContext());
- break;
- }
- }
- }
- finally {
- ignoreFocusChanges = false;
- }
- });
+ .observe(activity, this::applyFocus);
Data.currencyGap.observe(activity,
hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
b.transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE);
});
}
+ private void applyFocus(NewTransactionModel.FocusInfo focusInfo) {
+ if (ignoreFocusChanges) {
+ Logger.debug("new-trans", "Ignoring focus change");
+ return;
+ }
+ ignoreFocusChanges = true;
+ try {
+ if (((focusInfo == null) || (focusInfo.element == null) ||
+ focusInfo.position != getAdapterPosition()))
+ return;
+
+ NewTransactionModel.Item item = getItem();
+ if (item instanceof NewTransactionModel.TransactionHead) {
+ NewTransactionModel.TransactionHead head = item.toTransactionHead();
+ // bad idea - double pop-up, and not really necessary.
+ // the user can tap the input to get the calendar
+ //if (!tvDate.hasFocus()) tvDate.requestFocus();
+ switch (focusInfo.element) {
+ case TransactionComment:
+ b.transactionComment.setVisibility(View.VISIBLE);
+ b.transactionComment.requestFocus();
+ break;
+ case Description:
+ boolean focused = b.newTransactionDescription.requestFocus();
+// tvDescription.dismissDropDown();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
+ .getContext());
+ break;
+ }
+ }
+ else if (item instanceof NewTransactionModel.TransactionAccount) {
+ NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
+ switch (focusInfo.element) {
+ case Amount:
+ b.accountRowAccAmounts.requestFocus();
+ break;
+ case Comment:
+ b.comment.setVisibility(View.VISIBLE);
+ b.comment.requestFocus();
+ break;
+ case Account:
+ boolean focused = b.accountRowAccName.requestFocus();
+// b.accountRowAccName.dismissDropDown();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
+ .getContext());
+ break;
+ }
+ }
+ }
+ finally {
+ ignoreFocusChanges = false;
+ }
+ }
public void checkAmountValid(String s) {
boolean valid = true;
try {
head.setDate(String.valueOf(b.newTransactionDate.getText()));
// transaction description is required
- if (!significantChange && TextUtils.isEmpty(head.getDescription()) !=
- TextUtils.isEmpty(b.newTransactionDescription.getText()))
+ if (TextUtils.isEmpty(head.getDescription()) !=
+ TextUtils.isEmpty(b.newTransactionDescription.getText()))
significantChange = true;
head.setDescription(String.valueOf(b.newTransactionDescription.getText()));
NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
// having account name is important
- if (!significantChange && TextUtils.isEmpty(acc.getAccountName()) !=
- TextUtils.isEmpty(b.accountRowAccName.getText()))
+ final Editable incomingAccountName = b.accountRowAccName.getText();
+ if (TextUtils.isEmpty(acc.getAccountName()) !=
+ TextUtils.isEmpty(incomingAccountName))
significantChange = true;
- acc.setAccountName(String.valueOf(b.accountRowAccName.getText()));
+ acc.setAccountName(String.valueOf(incomingAccountName));
+ final int accNameSelEnd = b.accountRowAccName.getSelectionEnd();
+ final int accNameSelStart = b.accountRowAccName.getSelectionStart();
+ acc.setAccountNameCursorPosition(accNameSelEnd);
acc.setComment(String.valueOf(b.comment.getText()));
b.ntrData.setVisibility(View.VISIBLE);
b.ntrAccount.setVisibility(View.GONE);
- b.ntrPadding.setVisibility(View.GONE);
setEditable(true);
}
else if (item instanceof NewTransactionModel.TransactionAccount) {
NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
- // avoid triggering completion pop-up
- AccountAutocompleteAdapter a =
- (AccountAutocompleteAdapter) b.accountRowAccName.getAdapter();
- try {
- b.accountRowAccName.setAdapter(null);
- b.accountRowAccName.setText(acc.getAccountName());
- }
- finally {
- b.accountRowAccName.setAdapter(a);
+ final String incomingAccountName = acc.getAccountName();
+ final String presentAccountName = String.valueOf(b.accountRowAccName.getText());
+ if (!TextUtils.equals(incomingAccountName, presentAccountName)) {
+ Logger.debug("bind",
+ String.format("Setting account name from '%s' to '%s' (| @ %d)",
+ presentAccountName, incomingAccountName,
+ acc.getAccountNameCursorPosition()));
+ // avoid triggering completion pop-up
+ AccountAutocompleteAdapter a =
+ (AccountAutocompleteAdapter) b.accountRowAccName.getAdapter();
+ try {
+ b.accountRowAccName.setAdapter(null);
+ b.accountRowAccName.setText(incomingAccountName);
+ if (b.accountRowAccName.hasFocus())
+ b.accountRowAccName.setSelection(
+ acc.getAccountNameCursorPosition());
+ }
+ finally {
+ b.accountRowAccName.setAdapter(a);
+ }
}
final String amountHint = acc.getAmountHint();
b.ntrData.setVisibility(View.GONE);
b.ntrAccount.setVisibility(View.VISIBLE);
- b.ntrPadding.setVisibility(View.GONE);
setEditable(true);
}
else {
throw new RuntimeException("Don't know how to handle " + item);
}
+
+ applyFocus(mAdapter.model.getFocusInfo()
+ .getValue());
}
finally {
syncingData = false;