Adds ability to remove a player setup

hh
Laurent 6 years ago
parent 54163d7307
commit aebdc18bd4
  1. 15
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 31
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -246,9 +246,11 @@ class HandHistoryAdapter(
} }
} }
protected fun setOnItemClickListener(button: Button) { protected fun setOnItemClickListener(button: Button, colorChange: Boolean = true) {
button.setOnClickListener { button.setOnClickListener {
button.backgroundTintList = ColorStateList.valueOf(color(true)) if (colorChange) {
button.backgroundTintList = ColorStateList.valueOf(color(true))
}
val row = dataSource.rowRepresentableForPosition(currentPosition) val row = dataSource.rowRepresentableForPosition(currentPosition)
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") ?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition")
delegate?.onItemClick(currentPosition, row, button.tag as Int) delegate?.onItemClick(currentPosition, row, button.tag as Int)
@ -536,7 +538,7 @@ class HandHistoryAdapter(
} }
} }
abstract inner class AbstractRowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) { abstract inner class AbstractRowPlayerSetup(itemView: View) : RowHandHolder(itemView) {
protected var delegate: RowRepresentableDelegate? = null protected var delegate: RowRepresentableDelegate? = null
@ -552,6 +554,7 @@ class HandHistoryAdapter(
// Position Button // Position Button
itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal) 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) // val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
// itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected)) // itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
@ -564,7 +567,7 @@ class HandHistoryAdapter(
} }
inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) { inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowPlayerSetup(itemView) {
init { init {
itemView.ps_player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal itemView.ps_player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal
@ -582,16 +585,18 @@ class HandHistoryAdapter(
} }
inner class RowPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) { inner class RowPlayerSetupHolder(itemView: View) : AbstractRowPlayerSetup(itemView) {
init { init {
itemView.player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal itemView.player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal
itemView.position_button.tag = PlayerSetupRow.Tag.POSITION.ordinal
itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal
itemView.stack_edit_text.tag = PlayerSetupRow.Tag.STACK.ordinal itemView.stack_edit_text.tag = PlayerSetupRow.Tag.STACK.ordinal
itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(itemView.stack_edit_text) setClickListener(itemView.stack_edit_text)
setOnItemClickListener(itemView.position_button)
} }

@ -378,8 +378,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
when (row) { when (row) {
is PositionalRow -> { is PositionalRow -> {
this.model.tappedPlayerPositionIndex = row.positionIndex when (tag) {
DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) 0 -> {
this.model.tappedPlayerPositionIndex = row.positionIndex
DataListActivity.newDialogInstance(this, LiveData.PLAYER, true)
}
PlayerSetupRow.Tag.POSITION.ordinal -> { // 1
this.showPositionOptions(row.positionIndex)
}
}
} }
} }
@ -588,6 +595,26 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.findNextActionToEdit(0) this.findNextActionToEdit(0)
} }
private fun showPositionOptions(positionIndex: Int) {
val builder: AlertDialog.Builder = AlertDialog.Builder(context)
builder.setTitle(R.string.player)
builder.setItems(arrayOf<CharSequence>(
getString(R.string.remove)
)) { _, index ->
// The 'which' argument contains the index position
// of the selected item
when (index) {
0 -> this.removePlayer(positionIndex)
}
}
builder.create().show()
}
private fun removePlayer(positionIndex: Int) {
this.model.removePlayerSetup(positionIndex)
}
/*** /***
* Shows a popup with the various export options * Shows a popup with the various export options
*/ */

@ -938,4 +938,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
} }
fun removePlayerSetup(positionIndex: Int) {
val ps = this.handHistory.playerSetupForPosition(positionIndex)
this.handHistory.playerSetups.remove(ps)
this.createRowRepresentation() // refresh
}
} }
Loading…
Cancel
Save