From d9e52e865f13e0106ea9d8ded028ea12be14bfd0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 14 Feb 2020 12:11:35 +0100 Subject: [PATCH] Fixes issue with positions selection --- .../modules/handhistory/HandHistoryAdapter.kt | 47 ++++++++++--------- .../handhistory/HandHistoryFragment.kt | 2 +- .../handhistory/model/HandHistoryViewModel.kt | 30 +++++------- .../handhistory/views/PositionAdapter.kt | 6 +-- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 42 insertions(+), 45 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 5fdade46..772badcb 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 @@ -27,7 +27,6 @@ import net.pokeranalytics.android.ui.adapter.BindableHolder import net.pokeranalytics.android.ui.adapter.RecyclerAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate -import net.pokeranalytics.android.ui.extensions.hideKeyboard import net.pokeranalytics.android.ui.extensions.px import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.modules.handhistory.model.* @@ -222,32 +221,32 @@ class HandHistoryAdapter( editText.isFocusableInTouchMode = true - editText.setOnClickListener { +// editText.setOnClickListener { +// +// itemView.context.hideKeyboard(it) +// +// editText.isFocusable = true +// editText.isFocusableInTouchMode = true +// +// editText.requestFocus() +// +// editTextSelected(editText, true, editText.tag as Int) +// } - itemView.context.hideKeyboard(it) + editText.setOnTouchListener { _, event -> - editText.isFocusable = true - editText.isFocusableInTouchMode = true + if (event.action == MotionEvent.ACTION_UP) { + // Both are required, otherwise requestFocus() fails + editText.isFocusable = true + editText.isFocusableInTouchMode = true - editText.requestFocus() + editText.requestFocus() - editTextSelected(editText, true, editText.tag as Int) + editTextSelected(editText, true, editText.tag as Int) + } + return@setOnTouchListener true } -// editText.setOnTouchListener { _, event -> -// -// if (event.action == MotionEvent.ACTION_UP) { -// // Both are required, otherwise requestFocus() fails -// editText.isFocusable = true -// editText.isFocusableInTouchMode = true -// -// editText.requestFocus() -// -// editTextSelected(editText, true, tag) -// } -// return@setOnTouchListener true -// } - } protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -579,10 +578,12 @@ class HandHistoryAdapter( // Title itemView.title.text = setupRow.title(itemView.context) + val visibility = if (state == PlayerSetupRow.State.SETUP_ONLY && !setupRow.hero) View.GONE else View.VISIBLE + itemView.title.visibility = visibility // Position recycler - val visibility = if (state == PlayerSetupRow.State.SETUP_ONLY) View.GONE else View.VISIBLE - itemView.positionRecyclerView.visibility = visibility + val posVisibility = if (state == PlayerSetupRow.State.SETUP_ONLY) View.GONE else View.VISIBLE + itemView.positionRecyclerView.visibility = posVisibility this.positionAdapter.positions = adapter.dataSource.contentForRow(row, itemView.context, Position::class) this.positionAdapter.setOnClickListener { pos -> 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 447f2072..f3114f6f 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 @@ -259,7 +259,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } is PlayerSetupRow -> { when (value) { - is Int -> { + is Position -> { this.model.setPlayerSetupPosition(row, value) val index = this.indexOfRowRepresentable(row) this.handHistoryAdapter.notifyItemChanged(index) 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 bc939164..d89cd778 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 @@ -542,24 +542,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } override fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean { - val currentSelection = this.selectionLiveData val isSelectedIndex = (position == currentSelection.value?.index) val isSelectedTag = (tag == currentSelection.value?.tag) return isSelectedIndex && isSelectedTag - -// return when (row) { -// HandRowType.BLINDS -> { -// false -// } -// is ComputedAction -> { -// val currentSelection = this.selectionLiveData -// val isSelectedIndex = (position == currentSelection.value?.index) -// val isSelectedTag = (tag == currentSelection.value?.tag) -// isSelectedIndex && isSelectedTag -// } -// else -> false -// } } override fun isEnabled(row: RowRepresentable, tag: Int): Boolean { @@ -650,10 +636,17 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra return listOf() } + /*** + * Ends the card selection + */ fun cardSelectionEnded() { this.cardSelectionEnded(this.currentSelection.index) } + /*** + * Defines the positions having straddled and + * changes the player's actions accordingly + */ fun changeStraddleSelection(positions: LinkedHashSet) { if (positions.isEmpty()) { @@ -711,10 +704,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } /*** - * Sets the both [positionIndex] and position for a PlayerSetup inside a [playerSetupRow] + * Sets both positionIndex and [position] for a PlayerSetup inside a [playerSetupRow] */ - fun setPlayerSetupPosition(playerSetupRow: PlayerSetupRow, positionIndex: Int) { + fun setPlayerSetupPosition(playerSetupRow: PlayerSetupRow, position: Position) { + val positionIndex = this.sortedActions.positions.indexOf(position) var setupCreated = false playerSetupRow.playerSetup?.let { playerSetup -> playerSetup.position = positionIndex @@ -723,7 +717,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra setupCreated = true } - val position = this.positionForIndex(positionIndex) playerSetupRow.position = position if (!playerSetupRow.hero && setupCreated) { @@ -741,6 +734,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } + /*** + * Returns a Position enum value for a [positionIndex] + */ private fun positionForIndex(positionIndex: Int): Position { return this.sortedActions.positions.elementAt(positionIndex) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt index deb3b29f..09cdaa25 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt @@ -21,7 +21,7 @@ class PositionAdapter(var listener: PositionSelectionListener? = null) : override var dataSource: RowRepresentableDataSource = this override var delegate: RowRepresentableDelegate? = this - private var rawListener: ((Int) -> (Unit))? = null + private var rawListener: ((Position) -> (Unit))? = null var positions: List = listOf() set(value) { @@ -63,10 +63,10 @@ class PositionAdapter(var listener: PositionSelectionListener? = null) : override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { this.listener?.positionSelected(this.positions[position]) - this.rawListener?.invoke(position) + this.rawListener?.invoke(this.positions[position]) } - fun setOnClickListener(listener: (Int) -> (Unit)) { + fun setOnClickListener(listener: (Position) -> (Unit)) { this.rawListener = listener } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d85c4bcd..b7d43541 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -792,6 +792,6 @@ r_allin mississipi - vilain + Add vilain