From 67caf7a12576e87143fc72555328311ae7c61adb Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 23 Jan 2020 17:30:36 +0100 Subject: [PATCH] Fixes crash --- .../modules/handhistory/HandHistoryAdapter.kt | 17 +++++++------- .../handhistory/HandHistoryFragment.kt | 23 +++++++++++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index 06125d7b..be205e3e 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt @@ -119,7 +119,7 @@ class HandHistoryAdapter( amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL amountEditText.isFocusableInTouchMode = true - amountEditText.setOnTouchListener { v, event -> + amountEditText.setOnTouchListener { _, event -> // Timber.d("touch action = ${event.action}") if (this.amountCanBeEdited) { @@ -128,7 +128,8 @@ class HandHistoryAdapter( amountEditText.isFocusable = true amountEditText.isFocusableInTouchMode = true - requestFocusAndShowKeyboard(amountEditText) + amountEditText.requestFocus() +// requestFocusAndShowKeyboard(amountEditText) editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) } @@ -228,18 +229,18 @@ class HandHistoryAdapter( } - private fun requestFocusAndShowKeyboard(editText: EditText) { - - if (editText.requestFocus()) { +// private fun requestFocusAndShowKeyboard(editText: EditText) { +// +// if (editText.requestFocus()) { // val imm = itemView.context.getSystemService(InputMethodManager::class.java) // imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY) // val imm = itemView.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager // imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) // imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) - } - - } +// } +// +// } } /** diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index 9cd65fd9..726b6c5d 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -19,11 +19,11 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.fragment.components.RealmFragment -import net.pokeranalytics.android.ui.view.RowRepresentable -import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.modules.handhistory.views.KeyboardListener import net.pokeranalytics.android.ui.modules.handhistory.views.NumericKey import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardHeader +import net.pokeranalytics.android.ui.view.RowRepresentable +import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.util.extensions.findById import timber.log.Timber @@ -113,8 +113,21 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr } this.model.currentSelection.observeForever { selection -> - Timber.d("Current selection is ${selection.index} / ${selection.keyboard}") - retrieveEditTextInputConnection(selection.index) + selection?.let { + Timber.d("Current selection is ${selection.index} / ${selection.keyboard}") + retrieveEditTextInputConnection(selection.index) + } ?: run { + this.inputConnection = null + } + + } + + // At first, the selection is defined before the holder is bound, + // so we retrieve the editText inputConnection once the recycler view has been rendered + this.recyclerView.viewTreeObserver.addOnGlobalLayoutListener { + this.model.currentSelection.value?.index?.let { + retrieveEditTextInputConnection(it) + } } this.keyboard.keyboardListener = this @@ -127,6 +140,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr holder?.let { this.inputConnection = it.itemView.findViewById(R.id.amountEditText) .onCreateInputConnection(EditorInfo()) + Timber.d("***** inputConnection = $inputConnection") } ?: run { Timber.d("no holder, or not RowHandAction") } @@ -284,7 +298,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr } else -> { it.commitText(key.value, 1) } } - } }