X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionItemHolder.java;h=d051fe006a085da605433fc6302ab1bd4d2bef6d;hb=e44eba70988ae0a19b14319fcb3d20459ecfd999;hp=2e4c0e6ceaa360b56df4ceb97b4b2d96840ac882;hpb=865334093695e52f99d93ad9a255252b9d575053;p=mobile-ledger-staging.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 2e4c0e6c..d051fe00 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 @@ -17,12 +17,10 @@ package net.ktnx.mobileledger.ui.activity; -import android.content.Context; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; import android.widget.AutoCompleteTextView; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -35,11 +33,13 @@ import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.async.DescriptionSelectedCallback; +import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.LedgerTransactionAccount; import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.DatePickerFragment; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.MLDB; +import net.ktnx.mobileledger.utils.Misc; import java.util.Calendar; import java.util.Date; @@ -84,6 +84,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder }); tvDate.setOnClickListener(v -> pickTransactionDate()); + mProfile = Data.profile.getValue(); + if (mProfile == null) throw new AssertionError(); + MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile); MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE, @@ -117,32 +120,77 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder dateObserver = date -> { if (syncingData) return; - tvDate.setText(item.getFormattedDate()); + syncingData = true; + try { + tvDate.setText(item.getFormattedDate()); + } + finally { + syncingData = false; + } }; descriptionObserver = description -> { if (syncingData) return; - tvDescription.setText(description); + syncingData = true; + try { + tvDescription.setText(description); + } + finally { + syncingData = false; + } }; hintObserver = hint -> { if (syncingData) return; - tvAmount.setHint(hint); + syncingData = true; + try { + tvAmount.setHint(hint); + } + finally { + syncingData = false; + } }; focusedAccountObserver = index -> { if ((index != null) && index.equals(getAdapterPosition())) { switch (item.getType()) { case generalData: - tvDate.requestFocus(); + // bad idea - double pop-up, and not really necessary. + // the user can tap the input to get the calendar + //if (!tvDate.hasFocus()) tvDate.requestFocus(); + boolean focused = tvDescription.requestFocus(); + tvDescription.dismissDropDown(); + if (focused) Misc.showSoftKeyboard( + (NewTransactionActivity) tvDescription.getContext()); break; case transactionRow: - tvAccount.requestFocus(); + focused = tvAccount.requestFocus(); tvAccount.dismissDropDown(); - tvAccount.selectAll(); + if (focused) + Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext()); + break; } } }; accountCountObserver = count -> { - if (getAdapterPosition() == count) tvAmount.setImeOptions(EditorInfo.IME_ACTION_DONE); + final int adapterPosition = getAdapterPosition(); + final int layoutPosition = getLayoutPosition(); + Logger.debug("holder", + String.format(Locale.US, "count=%d; pos=%d, layoutPos=%d [%s]", count, + adapterPosition, layoutPosition, item.getType() + .toString() + .concat(item.getType() == + NewTransactionModel.ItemType.transactionRow + ? String.format(Locale.US, + "'%s'=%s", + item.getAccount() + .getAccountName(), + item.getAccount() + .isAmountSet() + ? String.format(Locale.US, + "%.2f", + item.getAccount() + .getAmount()) + : "unset") : ""))); + if (adapterPosition == count) tvAmount.setImeOptions(EditorInfo.IME_ACTION_DONE); else tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT); }; } @@ -270,14 +318,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder final Calendar c = GregorianCalendar.getInstance(); c.set(year, month, day); item.setDate(c.getTime()); - boolean tookFocus = tvDescription.requestFocus(); - if (tookFocus) { - // make the keyboard appear - InputMethodManager imm = (InputMethodManager) tvDate.getContext() - .getSystemService( - Context.INPUT_METHOD_SERVICE); - imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); - } + boolean focused = tvDescription.requestFocus(); + if (focused) Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext()); + } @Override public void descriptionSelected(String description) {