Fixes issue with positions selection

hh
Laurent 6 years ago
parent 71b633c259
commit d9e52e865f
  1. 47
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 30
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt
  5. 2
      app/src/main/res/values/strings.xml

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

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

@ -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<Position>) {
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)
}

@ -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<Position> = 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
}

@ -792,6 +792,6 @@
<string name="rallin">r_allin</string>
<string name="backspace"></string>
<string name="mississipi">mississipi</string>
<string name="add_vilain">vilain</string>
<string name="add_vilain">Add vilain</string>
</resources>

Loading…
Cancel
Save