Fixes the nasty hiding EditText content

hh
Laurent 6 years ago
parent 3c304f3cd5
commit 0ab62bfedb
  1. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 25
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardAmountView.kt

@ -101,6 +101,26 @@ class HandHistoryAdapter(
} }
inner class RowHandActionTest(itemView: View) : RowHandHolder(itemView), BindableHolder {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
val computedAction = row as ComputedAction
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
// amountEditText.setText(computedAction.action.formattedAmount)
val selected = adapter.dataSource.isSelected(position, row, 0)
if (selected) {
amountEditText.requestFocus()
} else {
amountEditText.clearFocus()
}
}
}
}
/** /**
* Display a hand action * Display a hand action
*/ */

@ -68,11 +68,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
initUI() initUI()
this.edit() this.edit()
// this.model.selectionLiveData.value?.index?.let {
// Timber.d(">>>> attempt to retrieveEditTextInputConnection")
// this.retrieveEditTextInputConnection(it)
// }
} }
private fun initData() { private fun initData() {
@ -127,8 +122,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
// At first, the selection is defined before the holder is bound, // At first, the selection is defined before the holder is bound,
// so we retrieve the editText inputConnection once the recycler view has been rendered // so we retrieve the editText inputConnection once the recycler view has been rendered
this.recyclerView.viewTreeObserver.addOnGlobalLayoutListener { this.recyclerView.viewTreeObserver.addOnGlobalLayoutListener {
this.model.selectionLiveData.value?.index?.let { this.model.selectionLiveData.value?.let { selection ->
retrieveEditTextInputConnection(it) if (selection.keyboard == HHKeyboard.AMOUNT) {
retrieveEditTextInputConnection(selection.index)
}
} }
} }
@ -140,7 +137,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val computedAction = this.model.rowRepresentableForPosition(position) as? ComputedAction val computedAction = this.model.rowRepresentableForPosition(position) as? ComputedAction
val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction val holder = recyclerView.findViewHolderForAdapterPosition(position)
holder?.let { holder?.let {
val amountEditText = it.itemView.findViewById<EditText>(R.id.amountEditText) val amountEditText = it.itemView.findViewById<EditText>(R.id.amountEditText)
this.keyboard.setAmountEditText(amountEditText, computedAction?.action?.amount) this.keyboard.setAmountEditText(amountEditText, computedAction?.action?.amount)
@ -173,7 +170,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} ?: run { } ?: run {
this.keyboard.hide() this.keyboard.hide()
} }
this.refreshCells(startIndex) this.handHistoryAdapter.notifyDataSetChanged()
// this.refreshCells(startIndex)
} }
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
@ -283,9 +281,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.findNextActionToEdit() this.findNextActionToEdit()
} }
override fun amountChanged(amount: String?) {
this.model.amountChanged(amount)
}
override fun amountCleared() { override fun amountCleared() {
this.model.clearAmount() this.model.clearAmount()
// this.refreshCurrentRow()
} }
override fun closeKeyboard() { override fun closeKeyboard() {
@ -296,10 +297,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.keyboard?.hide() this.keyboard?.hide()
} }
override fun amountChanged(amount: String?) {
this.model.amountChanged(amount)
}
override fun positionSelected(position: Position) { override fun positionSelected(position: Position) {
val rowRepresentableIndex = this.model.nextActionIndexForPosition(position) val rowRepresentableIndex = this.model.nextActionIndexForPosition(position)
this.model.rowRepresentableForPosition(rowRepresentableIndex)?.let { this.model.rowRepresentableForPosition(rowRepresentableIndex)?.let {

@ -116,7 +116,7 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
this.editText = editText this.editText = editText
editText.setText(amount?.noGroupingFormatted) editText.setText(amount?.noGroupingFormatted)
// editText.requestFocus() editText.requestFocus()
editText.isEnabled = true // avoid crashes due to input connection null editText.isEnabled = true // avoid crashes due to input connection null
editText.onCreateInputConnection(EditorInfo())?.let { editText.onCreateInputConnection(EditorInfo())?.let {
@ -158,11 +158,6 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
else -> { it.commitText(key.value, 1) } else -> { it.commitText(key.value, 1) }
} }
// Timber.d(">>> text = ${this.editText.text.toString()}")
// this.editText?.setText(this.editText?.text)
// this.editText?.forceLayout()
this.keyboardListener?.amountChanged(this.editText.text.toString()) this.keyboardListener?.amountChanged(this.editText.text.toString())
} ?: run { } ?: run {

Loading…
Cancel
Save