NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
// having account name is important
+ final Editable incomingAccountName = b.accountRowAccName.getText();
if (TextUtils.isEmpty(acc.getAccountName()) !=
- TextUtils.isEmpty(b.accountRowAccName.getText()))
+ 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()));
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();
NewTransactionRowBinding.inflate(LayoutInflater.from(parent.getContext()), parent,
false);
- return new NewTransactionItemHolder(b, this);
+ final NewTransactionItemHolder newHolder = new NewTransactionItemHolder(b, this);
+ Logger.debug("new-trans",
+ "Creating new ViewHolder " + Integer.toHexString(newHolder.hashCode()));
+ return newHolder;
}
@Override
public void onBindViewHolder(@NonNull NewTransactionItemHolder holder, int position) {
- Logger.debug("bind", String.format(Locale.US, "Binding item at position %d", position));
+ Logger.debug("bind",
+ String.format(Locale.US, "Binding item at position %d, holder %s", position,
+ Integer.toHexString(holder.hashCode())));
NewTransactionModel.Item item = Objects.requireNonNull(differ.getCurrentList()
.get(position));
holder.bind(item);
return this.isSubmittable;
}
void reset() {
+ Logger.debug("new-trans", "Resetting model");
List<Item> list = new ArrayList<>();
list.add(new TransactionHead(""));
list.add(new TransactionAccount(""));
private FocusedElement focusedElement = FocusedElement.Account;
private boolean amountHintIsSet = true;
private boolean isLast = false;
+ private int accountNameCursorPosition;
public TransactionAccount(TransactionAccount origin) {
id = origin.id;
accountName = origin.accountName;
amountValid = origin.amountValid;
focusedElement = origin.focusedElement;
isLast = origin.isLast;
+ accountNameCursorPosition = origin.accountNameCursorPosition;
}
public TransactionAccount(LedgerTransactionAccount account) {
super();
equal));
return equal;
}
+ public int getAccountNameCursorPosition() {
+ return accountNameCursorPosition;
+ }
+ public void setAccountNameCursorPosition(int position) {
+ this.accountNameCursorPosition = position;
+ }
}
private static class BalanceForCurrency {
android:id="@+id/transaction_comment_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/new_transaction_description"
android:id="@+id/comment_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
app:layout_constraintEnd_toStartOf="@id/amount_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
android:id="@+id/amount_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
>