Fixes cursor placement

hh
Laurent 6 years ago
parent eaa5b87c13
commit 12495533b3
  1. 83
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 8
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  3. 17
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardAmountView.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/CustomizableRowRepresentable.kt

@ -216,38 +216,6 @@ class HandHistoryAdapter(
this.configureEditTexts(index..index, position, row, adapter) this.configureEditTexts(index..index, position, row, adapter)
} }
protected fun setClickListener(editText: EditText) {
editText.isFocusableInTouchMode = true
// editText.setOnClickListener {
//
// itemView.context.hideKeyboard(it)
//
// editText.isFocusable = true
// editText.isFocusableInTouchMode = true
//
// editText.requestFocus()
//
// editTextSelected(editText, true, editText.tag as Int)
// }
editText.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
// Both are required, otherwise requestFocus() fails
editText.isFocusable = true
editText.isFocusableInTouchMode = true
editText.requestFocus()
editTextSelected(editText, true, editText.tag as Int)
}
return@setOnTouchListener true
}
}
protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
tagRange.forEach { tag -> tagRange.forEach { tag ->
@ -270,6 +238,11 @@ class HandHistoryAdapter(
editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag)
editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag)
// Put cursor at the end
if (focused) {
editText.setSelection(editText.text.length)
}
// Background // Background
editText.setBackgroundColor(color(focused)) editText.setBackgroundColor(color(focused))
@ -277,6 +250,26 @@ class HandHistoryAdapter(
} }
protected fun setClickListener(editText: EditText) {
editText.isFocusableInTouchMode = true
editText.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
// Both are required, otherwise requestFocus() fails
editText.isFocusable = true
editText.isFocusableInTouchMode = true
editText.requestFocus()
editTextSelected(editText, true, editText.tag as Int)
}
return@setOnTouchListener true
}
}
private fun toggleFocus(editText: EditText, focused: Boolean) { private fun toggleFocus(editText: EditText, focused: Boolean) {
if (focused) { if (focused) {
editText.requestFocus() editText.requestFocus()
@ -326,7 +319,6 @@ class HandHistoryAdapter(
val chip = Chip(itemView.context) val chip = Chip(itemView.context)
chip.id = View.generateViewId() chip.id = View.generateViewId()
// chip.tag = filter.id
chip.text = pos.shortValue chip.text = pos.shortValue
chip.chipStartPadding = 4f.px chip.chipStartPadding = 4f.px
chip.chipEndPadding = 4f.px chip.chipEndPadding = 4f.px
@ -402,7 +394,6 @@ class HandHistoryAdapter(
// Action // Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton -> itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
// actionButton.isEnabled = computedAction.actionTypeCanBeEdited
actionButton.isEnabled = adapter.dataSource.isEnabled(row, actionButton.tag as Int) actionButton.isEnabled = adapter.dataSource.isEnabled(row, actionButton.tag as Int)
val selected = adapter.dataSource.isSelected(position, row, actionButton.tag as Int) val selected = adapter.dataSource.isSelected(position, row, actionButton.tag as Int)
@ -418,27 +409,8 @@ class HandHistoryAdapter(
// Amount // Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
// amountEditText.isEnabled = computedAction.amountCanBeEdited
val tag = amountEditText.tag as Int val tag = amountEditText.tag as Int
configureEditTexts(tag, position, row, adapter) configureEditTexts(tag, position, row, adapter)
// val selected = adapter.dataSource.isSelected(position, row, tag)
// amountEditText.setBackgroundColor(color(selected))
// Useful to have the cursor disappear when the keyboard is closed
// amountEditText.isFocusable = selected && computedAction.amountCanBeEdited
// amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited
// amountEditText.setText(computedAction.action.formattedAmount)
//
// if (selected) {
// amountEditText.requestFocus()
// } else {
// amountEditText.clearFocus()
// }
// Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
} }
} }
@ -456,11 +428,6 @@ class HandHistoryAdapter(
itemView.turnEditText.tag = Street.TURN.ordinal itemView.turnEditText.tag = Street.TURN.ordinal
itemView.riverEditText.tag = Street.RIVER.ordinal itemView.riverEditText.tag = Street.RIVER.ordinal
// hides soft input view
// itemView.flopEditText.setTextIsSelectable(true)
// itemView.turnEditText.setTextIsSelectable(true)
// itemView.riverEditText.setTextIsSelectable(true)
setClickListener(itemView.flopEditText) setClickListener(itemView.flopEditText)
setClickListener(itemView.turnEditText) setClickListener(itemView.turnEditText)
setClickListener(itemView.riverEditText) setClickListener(itemView.riverEditText)

@ -3,9 +3,9 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm import io.realm.Realm
import io.realm.RealmList import io.realm.RealmList
import io.realm.RealmModel import io.realm.RealmModel
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import timber.log.Timber
interface CardHolder : RealmModel { interface CardHolder : RealmModel {
val cards: RealmList<Card> val cards: RealmList<Card>
@ -88,8 +88,10 @@ abstract class CardsRow : HandHistoryRow {
} }
} }
if (this.cardCount == 5) { if (this.cardCount >= 5) {
throw PAIllegalStateException("Can't add anymore cards") Timber.w("The card holder currently have ${this.cardCount} cards")
return
// throw PAIllegalStateException("Can't add anymore cards")
} }
card.index = this.cardCount card.index = this.cardCount

@ -99,6 +99,15 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
this.keyboardListener?.amountValidated() this.keyboardListener?.amountValidated()
} }
this.kiloButton.text = "x1K" // TODO
this.kiloButton.setOnClickListener {
this.addZeros(3)
}
this.millionButton.text = "x1M"
this.millionButton.setOnClickListener {
this.addZeros(6)
}
this.clearButton.setOnClickListener { this.clearButton.setOnClickListener {
this.editText.text = null this.editText.text = null
this.keyboardListener?.amountCleared() this.keyboardListener?.amountCleared()
@ -109,6 +118,14 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
} }
} }
private fun addZeros(n: Int) {
this.inputConnection?.let {
val string = "0".repeat(n)
it.commitText(string, 0)
this.keyboardListener?.amountChanged(this.editText.text.toString())
}
}
fun setEditText(editText: EditText, amount: Double?) { fun setEditText(editText: EditText, amount: Double?) {
Timber.d("edit text = $editText") Timber.d("edit text = $editText")

@ -38,7 +38,7 @@ class CustomizableRowRepresentable(
return it return it
} }
this.resId?.let { this.resId?.let {
return context.getString(it) return context.getString(it).capitalize()
} }
return "LOCALISATION NOT FOUND" return "LOCALISATION NOT FOUND"
} }

Loading…
Cancel
Save