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 {
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
*/

@ -105,16 +105,17 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow
when (row.keyboardForTag(it.tag)) {
val keyboard = row.keyboardForTag(it.tag)
when (keyboard) {
HHKeyboard.ACTION -> {
val positions = this.model.positionsToAct()
this.keyboard.setPositions(positions)
configureActionKeyboard()
}
HHKeyboard.AMOUNT -> {
retrieveEditTextInputConnection(selection)
}
else -> {}
}
this.keyboard.show(keyboard)
// when (row) {
// is ComputedAction -> {
@ -145,7 +146,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
// 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 {
when (this.model.currentKeyboard) {
HHKeyboard.AMOUNT -> {
val selection = this.model.currentSelection
@ -153,12 +153,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
else -> {}
}
}
this.keyboard.keyboardListener = this
this.keyboard.setCardCentralizer(this.model)
}
private fun retrieveEditTextInputConnection(selection: HHSelection) {
@ -188,17 +186,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val startIndex = index ?: this.model.currentSelection.index
this.model.findSelectionForEdition(startIndex)?.let { selection ->
this.recyclerView.smoothScrollToPosition(selection.index)
this.scrollToPosition(selection.index)
this.model.currentKeyboard?.let { keyboard ->
when (keyboard) {
HHKeyboard.ACTION -> {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
} else -> {}
}
this.keyboard.show(keyboard)
}
// this.model.currentKeyboard?.let { keyboard ->
// when (keyboard) {
// HHKeyboard.ACTION -> {
// configureActionKeyboard()
// } else -> {}
// }
// this.keyboard.show(keyboard)
// }
} ?: run {
this.keyboard.hide()
@ -222,20 +219,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
refreshCells(oldIndex)
}
// scrolls to selected position
this.recyclerView.smoothScrollToPosition(position)
this.scrollToPosition(position)
this.model.selectionLiveData.value = HHSelection(position, tag)
val keyboard = (row as HandHistoryRow).keyboardForTag(tag)
if (keyboard == HHKeyboard.ACTION) {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
}
// val keyboard = (row as HandHistoryRow).keyboardForTag(tag)
// if (keyboard == HHKeyboard.ACTION) {
// configureActionKeyboard()
// }
// this.keyboard.show(keyboard)
Timber.d("row $position selected, show keyboard = $keyboard")
this.keyboard.show(keyboard)
// Timber.d("row $position selected, show keyboard = $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) {
@ -321,7 +323,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} ?: 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) {
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]
*/
fun positionsToActAfterIndex(index: Int): List<Position> {
val currentStreet = this[index].street
val streetActions = this.filter { it.street == currentStreet }
return streetActions.drop(index + 1).map { it.position }
val nextActions = this.drop(index + 1)
return nextActions.map { it.position }
}
/***

Loading…
Cancel
Save