X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionItemHolder.java;h=507055ff0eda9eac0dcc9e74d824a06c3db2d8cd;hb=7cb9091315c4adf9bb278995469c0bb401c33939;hp=e515690a0ef8586cab11550c8fc6fd35a1573be9;hpb=58206e7dc27c7b7aee008a7f1ac21b5a9e6658a9;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index e515690a..507055ff 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -30,7 +30,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.appcompat.widget.LinearLayoutCompat; import androidx.lifecycle.Observer; import androidx.recyclerview.widget.RecyclerView; @@ -59,7 +59,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private AutoCompleteTextView tvDescription; private AutoCompleteTextView tvAccount; private TextView tvAmount; - private ConstraintLayout lHead; + private LinearLayoutCompat lHead; private LinearLayout lAccount; private FrameLayout lPadding; private MobileLedgerProfile mProfile; @@ -86,16 +86,29 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvAccount.setNextFocusForwardId(View.NO_ID); tvAmount.setNextFocusForwardId(View.NO_ID); // magic! - tvDate.setOnFocusChangeListener((v, hasFocus) -> { - if (hasFocus) - pickTransactionDate(); - }); tvDate.setOnClickListener(v -> pickTransactionDate()); mProfile = Data.profile.getValue(); if (mProfile == null) throw new AssertionError(); + View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> { + if (hasFocus) { + boolean wasSyncing = syncingData; + syncingData = true; + try { + adapter.updateFocusedItem(getAdapterPosition()); + } + finally { + syncingData = wasSyncing; + } + } + }; + + tvDescription.setOnFocusChangeListener(focusMonitor); + tvAccount.setOnFocusChangeListener(focusMonitor); + tvAmount.setOnFocusChangeListener(focusMonitor); + MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile); MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE, @@ -219,10 +232,13 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder (NewTransactionActivity) tvDescription.getContext()); break; case transactionRow: - focused = tvAccount.requestFocus(); - tvAccount.dismissDropDown(); - if (focused) - Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext()); + // do nothing if a row element already has the focus + if (!itemView.hasFocus()) { + focused = tvAccount.requestFocus(); + tvAccount.dismissDropDown(); + if (focused) + Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext()); + } break; }