Adds ability to remove a player setup

hh
Laurent 6 years ago
parent 54163d7307
commit aebdc18bd4
  1. 13
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 27
      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 {
if (colorChange) {
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)
@ -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
@ -552,6 +554,7 @@ class HandHistoryAdapter(
// 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))
@ -564,7 +567,7 @@ class HandHistoryAdapter(
}
inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowPlayerSetup(itemView) {
init {
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 {
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.stack_edit_text.tag = PlayerSetupRow.Tag.STACK.ordinal
itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(itemView.stack_edit_text)
setOnItemClickListener(itemView.position_button)
}

@ -378,9 +378,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
when (row) {
is PositionalRow -> {
when (tag) {
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)
}
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
*/

@ -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