Cleanup keyboard display + fix missing positions shortcuts after flop

hh
Laurent 6 years ago
parent 85fdbdaa9d
commit f4acb0f805
  1. 70
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 62
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt

@ -132,41 +132,6 @@ class HandHistoryAdapter(
} }
} }
inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val straddleRow = row as StraddleRowRepresentable
itemView.positionsChipGroup.removeAllViews()
straddleRow.positions.forEach { pos ->
val chip = Chip(itemView.context)
chip.id = View.generateViewId()
// chip.tag = filter.id
chip.text = pos.shortValue
chip.chipStartPadding = 8f.px
chip.chipEndPadding = 8f.px
chip.isChecked = straddleRow.selectedPositions.contains(pos)
chip.setOnClickListener {
if (chip.isChecked) {
val added = straddleRow.add(pos)
chip.isChecked = added
} else {
straddleRow.remove(pos)
}
adapter.delegate?.onRowValueChanged(straddleRow.selectedPositions, row)
}
itemView.positionsChipGroup.addView(chip)
}
}
}
abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
var currentPosition = 0 var currentPosition = 0
@ -239,6 +204,41 @@ class HandHistoryAdapter(
} }
inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val straddleRow = row as StraddleRowRepresentable
itemView.positionsChipGroup.removeAllViews()
straddleRow.positions.forEach { pos ->
val chip = Chip(itemView.context)
chip.id = View.generateViewId()
// chip.tag = filter.id
chip.text = pos.shortValue
chip.chipStartPadding = 4f.px
chip.chipEndPadding = 4f.px
chip.isChecked = straddleRow.selectedPositions.contains(pos)
chip.setOnClickListener {
if (chip.isChecked) {
val added = straddleRow.add(pos)
chip.isChecked = added
} else {
straddleRow.remove(pos)
}
adapter.delegate?.onRowValueChanged(straddleRow.selectedPositions, row)
}
itemView.positionsChipGroup.addView(chip)
}
}
}
/** /**
* Display a hand action * Display a hand action
*/ */

@ -105,16 +105,17 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow
when (row.keyboardForTag(it.tag)) { val keyboard = row.keyboardForTag(it.tag)
when (keyboard) {
HHKeyboard.ACTION -> { HHKeyboard.ACTION -> {
val positions = this.model.positionsToAct() configureActionKeyboard()
this.keyboard.setPositions(positions)
} }
HHKeyboard.AMOUNT -> { HHKeyboard.AMOUNT -> {
retrieveEditTextInputConnection(selection) retrieveEditTextInputConnection(selection)
} }
else -> {} else -> {}
} }
this.keyboard.show(keyboard)
// when (row) { // when (row) {
// is ComputedAction -> { // is ComputedAction -> {
@ -145,7 +146,6 @@ 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 {
when (this.model.currentKeyboard) { when (this.model.currentKeyboard) {
HHKeyboard.AMOUNT -> { HHKeyboard.AMOUNT -> {
val selection = this.model.currentSelection val selection = this.model.currentSelection
@ -153,12 +153,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
else -> {} else -> {}
} }
} }
this.keyboard.keyboardListener = this this.keyboard.keyboardListener = this
this.keyboard.setCardCentralizer(this.model) this.keyboard.setCardCentralizer(this.model)
} }
private fun retrieveEditTextInputConnection(selection: HHSelection) { private fun retrieveEditTextInputConnection(selection: HHSelection) {
@ -188,17 +186,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val startIndex = index ?: this.model.currentSelection.index val startIndex = index ?: this.model.currentSelection.index
this.model.findSelectionForEdition(startIndex)?.let { selection -> this.model.findSelectionForEdition(startIndex)?.let { selection ->
this.recyclerView.smoothScrollToPosition(selection.index) this.scrollToPosition(selection.index)
this.model.currentKeyboard?.let { keyboard -> // this.model.currentKeyboard?.let { keyboard ->
when (keyboard) { // when (keyboard) {
HHKeyboard.ACTION -> { // HHKeyboard.ACTION -> {
val availableActions = this.model.availableActions() // configureActionKeyboard()
this.keyboard.setAvailableAction(availableActions) // } else -> {}
} else -> {} // }
} // this.keyboard.show(keyboard)
this.keyboard.show(keyboard) // }
}
} ?: run { } ?: run {
this.keyboard.hide() this.keyboard.hide()
@ -222,22 +219,27 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
refreshCells(oldIndex) refreshCells(oldIndex)
} }
// scrolls to selected position this.scrollToPosition(position)
this.recyclerView.smoothScrollToPosition(position)
this.model.selectionLiveData.value = HHSelection(position, tag) this.model.selectionLiveData.value = HHSelection(position, tag)
val keyboard = (row as HandHistoryRow).keyboardForTag(tag) // val keyboard = (row as HandHistoryRow).keyboardForTag(tag)
if (keyboard == HHKeyboard.ACTION) { // if (keyboard == HHKeyboard.ACTION) {
val availableActions = this.model.availableActions() // configureActionKeyboard()
this.keyboard.setAvailableAction(availableActions) // }
} // this.keyboard.show(keyboard)
Timber.d("row $position selected, show keyboard = $keyboard") // Timber.d("row $position selected, show keyboard = $keyboard")
this.keyboard.show(keyboard)
} }
private fun configureActionKeyboard() {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
val positions = this.model.positionsToAct()
this.keyboard.setPositions(positions)
}
override fun onRowDeselected(position: Int, row: RowRepresentable) { override fun onRowDeselected(position: Int, row: RowRepresentable) {
this.model.selectionLiveData.value = null this.model.selectionLiveData.value = null
this.model.currentAmount = null this.model.currentAmount = null
@ -321,7 +323,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} ?: throw PAIllegalStateException("Rowrepresentable not fouind at index $rowRepresentableIndex") } ?: throw PAIllegalStateException("Rowrepresentable not fouind at index $rowRepresentableIndex")
} }
// Table refresh // Table
/***
* Scrolls to the [index]
* We subtract 1 to give space and the ability to see the previously entered data
*/
private fun scrollToPosition(index: Int) {
this.recyclerView.smoothScrollToPosition(index - 1)
}
private fun refreshCells(oldIndex: Int) { private fun refreshCells(oldIndex: Int) {
this.handHistoryAdapter.notifyItemChanged(oldIndex) this.handHistoryAdapter.notifyItemChanged(oldIndex)

@ -514,9 +514,8 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
* Returns all positions of the street, identified by the action at the given [index] * Returns all positions of the street, identified by the action at the given [index]
*/ */
fun positionsToActAfterIndex(index: Int): List<Position> { fun positionsToActAfterIndex(index: Int): List<Position> {
val currentStreet = this[index].street val nextActions = this.drop(index + 1)
val streetActions = this.filter { it.street == currentStreet } return nextActions.map { it.position }
return streetActions.drop(index + 1).map { it.position }
} }
/*** /***

Loading…
Cancel
Save