Fixes crash

hh
Laurent 6 years ago
parent d8a6de3e94
commit 67caf7a125
  1. 17
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 23
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt

@ -119,7 +119,7 @@ class HandHistoryAdapter(
amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
amountEditText.isFocusableInTouchMode = true amountEditText.isFocusableInTouchMode = true
amountEditText.setOnTouchListener { v, event -> amountEditText.setOnTouchListener { _, event ->
// Timber.d("touch action = ${event.action}") // Timber.d("touch action = ${event.action}")
if (this.amountCanBeEdited) { if (this.amountCanBeEdited) {
@ -128,7 +128,8 @@ class HandHistoryAdapter(
amountEditText.isFocusable = true amountEditText.isFocusable = true
amountEditText.isFocusableInTouchMode = true amountEditText.isFocusableInTouchMode = true
requestFocusAndShowKeyboard(amountEditText) amountEditText.requestFocus()
// requestFocusAndShowKeyboard(amountEditText)
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal)
} }
@ -228,18 +229,18 @@ class HandHistoryAdapter(
} }
private fun requestFocusAndShowKeyboard(editText: EditText) { // private fun requestFocusAndShowKeyboard(editText: EditText) {
//
if (editText.requestFocus()) { // if (editText.requestFocus()) {
// val imm = itemView.context.getSystemService(InputMethodManager::class.java) // val imm = itemView.context.getSystemService(InputMethodManager::class.java)
// imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY) // imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY)
// val imm = itemView.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager // val imm = itemView.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
// imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) // imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0)
// imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) // imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
} // }
//
} // }
} }
/** /**

@ -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.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.fragment.components.RealmFragment 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.KeyboardListener
import net.pokeranalytics.android.ui.modules.handhistory.views.NumericKey import net.pokeranalytics.android.ui.modules.handhistory.views.NumericKey
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardHeader 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 net.pokeranalytics.android.util.extensions.findById
import timber.log.Timber import timber.log.Timber
@ -113,8 +113,21 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
} }
this.model.currentSelection.observeForever { selection -> this.model.currentSelection.observeForever { selection ->
Timber.d("Current selection is ${selection.index} / ${selection.keyboard}") selection?.let {
retrieveEditTextInputConnection(selection.index) 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 this.keyboard.keyboardListener = this
@ -127,6 +140,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
holder?.let { holder?.let {
this.inputConnection = it.itemView.findViewById<EditText>(R.id.amountEditText) this.inputConnection = it.itemView.findViewById<EditText>(R.id.amountEditText)
.onCreateInputConnection(EditorInfo()) .onCreateInputConnection(EditorInfo())
Timber.d("***** inputConnection = $inputConnection")
} ?: run { } ?: run {
Timber.d("no holder, or not RowHandAction") Timber.d("no holder, or not RowHandAction")
} }
@ -284,7 +298,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
} }
else -> { it.commitText(key.value, 1) } else -> { it.commitText(key.value, 1) }
} }
} }
} }

Loading…
Cancel
Save