From aebdc18bd41eae7a34245942e56810310008c284 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 20 Mar 2020 14:31:23 +0100 Subject: [PATCH] Adds ability to remove a player setup --- .../modules/handhistory/HandHistoryAdapter.kt | 15 ++++++--- .../handhistory/HandHistoryFragment.kt | 31 +++++++++++++++++-- .../handhistory/model/HandHistoryViewModel.kt | 6 ++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index 76626312..24476551 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt @@ -246,9 +246,11 @@ class HandHistoryAdapter( } } - protected fun setOnItemClickListener(button: Button) { + protected fun setOnItemClickListener(button: Button, colorChange: Boolean = true) { button.setOnClickListener { - button.backgroundTintList = ColorStateList.valueOf(color(true)) + 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) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index ecd13cc5..6f5f03be 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -378,8 +378,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL when (row) { is PositionalRow -> { - this.model.tappedPlayerPositionIndex = row.positionIndex - DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) + 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( + 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 */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index 91d457f4..827f731b 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -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 + } + } \ No newline at end of file