Disable components when necessary

hh
Laurent 6 years ago
parent 7082ef7c23
commit 808006e074
  1. 37
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt

@ -110,19 +110,11 @@ class HandHistoryAdapter(
inner class RowHandAction(itemView: View) : RowHandHolder(itemView), inner class RowHandAction(itemView: View) : RowHandHolder(itemView),
BindableHolder { BindableHolder {
// private var listener = TextListener()
private var actionCanBeEdited = true
private var amountCanBeEdited = true
init { init {
// Action // Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton -> itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
actionButton.setOnClickListener { actionButton.setOnClickListener {
buttonEdited(actionButton, true, HHKeyboard.ACTION.ordinal)
if (this.actionCanBeEdited) {
buttonEdited(actionButton, true, HHKeyboard.ACTION.ordinal)
}
} }
} }
@ -133,18 +125,15 @@ class HandHistoryAdapter(
amountEditText.isFocusableInTouchMode = true amountEditText.isFocusableInTouchMode = true
amountEditText.setOnTouchListener { _, event -> amountEditText.setOnTouchListener { _, event ->
// Timber.d("touch action = ${event.action}")
if (this.amountCanBeEdited) {
if (event.action == MotionEvent.ACTION_UP) { if (event.action == MotionEvent.ACTION_UP) {
// Both are required, otherwise requestFocus() fails // Both are required, otherwise requestFocus() fails
amountEditText.isFocusable = true amountEditText.isFocusable = true
amountEditText.isFocusableInTouchMode = true amountEditText.isFocusableInTouchMode = true
amountEditText.requestFocus() amountEditText.requestFocus()
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal)
}
} }
return@setOnTouchListener true return@setOnTouchListener true
} }
@ -171,8 +160,6 @@ class HandHistoryAdapter(
this.currentPosition = position this.currentPosition = position
val computedAction = row as ComputedAction val computedAction = row as ComputedAction
this.actionCanBeEdited = computedAction.actionTypeCanBeEdited
this.amountCanBeEdited = computedAction.amountCanBeEdited
// Position // Position
itemView.findViewById<Button>(R.id.positionButton)?.let { button -> itemView.findViewById<Button>(R.id.positionButton)?.let { button ->
@ -181,14 +168,16 @@ class HandHistoryAdapter(
// Action // Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton -> itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
actionButton.isEnabled = computedAction.actionTypeCanBeEdited
val tag = HHKeyboard.ACTION.ordinal val tag = HHKeyboard.ACTION.ordinal
val selected = adapter.dataSource.isSelected(position, row, tag) val selected = adapter.dataSource.isSelected(position, row, tag)
// Timber.d("Action at $position is selected: $selected") // Timber.d("Action at $position is selected: $selected")
actionButton.backgroundTintList = ColorStateList.valueOf(color(selected)) actionButton.backgroundTintList = ColorStateList.valueOf(color(selected))
if (selected) { // if (selected) {
(itemView.context as Activity).hideKeyboard() // (itemView.context as Activity).hideKeyboard()
} // }
computedAction.action.type?.resId?.let { computedAction.action.type?.resId?.let {
actionButton.setText(it) actionButton.setText(it)
@ -200,6 +189,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 = HHKeyboard.AMOUNT.ordinal val tag = HHKeyboard.AMOUNT.ordinal
val selected = adapter.dataSource.isSelected(position, row, tag) val selected = adapter.dataSource.isSelected(position, row, tag)

Loading…
Cancel
Save