Adds onItemClick for RowRepresentableDelegate

hh
Laurent 6 years ago
parent e6d1160e35
commit d66a706c07
  1. 2
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RecyclerAdapter.kt
  2. 68
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  3. 40
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt

@ -14,7 +14,7 @@ interface RowRepresentableDelegate {
fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
fun onRowDeleted(row: RowRepresentable) {}
fun onRowLongClick(itemView: View, row: RowRepresentable, position: Int) {}
fun onItemClick(position: Int, row: RowRepresentable, tag: Int = 0) {}
}
/**

@ -240,6 +240,15 @@ class HandHistoryAdapter(
}
}
protected fun setOnItemClickListener(button: Button) {
button.setOnClickListener {
button.backgroundTintList = ColorStateList.valueOf(color(true))
val row = dataSource.rowRepresentableForPosition(currentPosition)
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition")
delegate?.onItemClick(currentPosition, row, button.tag as Int)
}
}
private fun toggleFocus(editText: EditText, focused: Boolean) {
if (focused) {
editText.requestFocus()
@ -444,6 +453,35 @@ class HandHistoryAdapter(
}
}
abstract inner class AbstractRowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) {
protected var delegate: RowRepresentableDelegate? = null
init {
itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val setupRow = row as PlayerSetupRow
val state = setupRow.state
this.delegate = adapter.delegate
// Position Button
itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
// Settings
itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE
configureCardsLayout(itemView.ps_hand_layout)
}
}
inner class RowHandReadOnlyPlayerSetup(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
init {
@ -466,7 +504,6 @@ class HandHistoryAdapter(
init {
itemView.ps_player_button.tag = PlayerSetupRow.Tag.PLAYER.ordinal
setOnClickListener(itemView.ps_player_button)
itemView.stack_edit_text.tag = PlayerSetupRow.Tag.STACK.ordinal
@ -509,33 +546,4 @@ class HandHistoryAdapter(
}
abstract inner class AbstractRowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) {
protected var delegate: RowRepresentableDelegate? = null
init {
itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val setupRow = row as PlayerSetupRow
val state = setupRow.state
this.delegate = adapter.delegate
// Position Button
itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
// Settings
itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE
configureCardsLayout(itemView.ps_hand_layout)
}
}
}

@ -210,6 +210,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.updateMenuUI()
}
/***
* Retrieves the edit text corresponding to the provided [selection]
*/
private fun retrieveEditTextInputConnection(selection: HHSelection) {
// throw PAIllegalStateException("I believe this should not happen any more")
@ -226,6 +229,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
/***
* Saves or edit the hand history
*/
private fun saveOrEdit() {
this.setEditing(!this.model.isEdited)
@ -239,10 +245,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.handHistoryAdapter.notifyDataSetChanged()
}
/***
* Saves the model to Realm
*/
private fun save() {
this.model.save(getRealm())
}
/***
* Looks for a field to edit
*/
private fun findNextActionToEdit(index: Int? = null, userInitiated: Boolean = false) {
val startIndex = index ?: this.model.currentSelection.index
@ -271,7 +283,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
return
}
when (row.bottomSheetType) { // Comment, number of players
when (row.bottomSheetType) { // Comment, number of players...
BottomSheetType.NONE -> {}
else -> {
val editDescriptors = this.model.editDescriptors(row)
@ -338,6 +350,32 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
}
}
override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) {
when (row) {
is PlayerSetupRow -> {
when (tag) {
PlayerSetupRow.Tag.PLAYER.ordinal -> {
showPlayerSelectionFragment()
}
else -> {
Timber.d("onItemClick not configured for row: $row, position: $position, tag: $tag")
}
}
}
}
}
/***
* Shows a window allowing a player selection
*/
private fun showPlayerSelectionFragment() {
}
/***

Loading…
Cancel
Save