@ -8,12 +8,12 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup
import android.widget.Button
import android.widget.Button
import android.widget.EditText
import android.widget.EditText
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
import com.google.android.material.chip.Chip
import kotlinx.android.synthetic.main.row_hand_action.view.*
import kotlinx.android.synthetic.main.row_hand_action.view.*
import kotlinx.android.synthetic.main.row_hand_cards.view.*
import kotlinx.android.synthetic.main.row_hand_cards.view.*
import kotlinx.android.synthetic.main.row_hand_player_summary.view.*
import kotlinx.android.synthetic.main.row_hhsettings_blinds.view.*
import kotlinx.android.synthetic.main.row_hhsettings_blinds.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
@ -33,7 +33,6 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.PositionAdapter
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.holder.RowViewHolder
import net.pokeranalytics.android.ui.view.holder.RowViewHolder
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier
import timber.log.Timber
enum class HandRowType ( var layoutRes : Int ) : ViewIdentifier , RowRepresentable , HandHistoryRow {
enum class HandRowType ( var layoutRes : Int ) : ViewIdentifier , RowRepresentable , HandHistoryRow {
@ -54,19 +53,42 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
override val identifier : Int
override val identifier : Int
get ( ) { return this . ordinal }
get ( ) { return this . ordinal }
override fun tagForCompletion ( handHistory : HandHistory ) : Int ? {
override fun tagsForCompletion ( ) : List < Int > {
return when ( this ) {
BLINDS -> listOf ( 0 , 1 )
else -> listOf ( )
}
}
override fun isFieldEmpty ( tag : Int , handHistory : HandHistory ) : Boolean {
return when ( this ) {
return when ( this ) {
BLINDS -> {
BLINDS -> {
when {
when ( tag ) {
handHistory . smallBlind == null -> 0
0 -> ( handHistory . smallBlind == null )
handHistory . bigBlind == null -> 1
1 -> ( handHistory . bigBlind == null )
else -> null
else -> false
}
}
}
}
else -> null
else -> false
}
}
}
}
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return when (this) {
// BLINDS -> {
// when {
// handHistory.smallBlind == null -> 0
// handHistory.bigBlind == null -> 1
// else -> null
// }
// }
// else -> null
// }
// }
override fun keyboardForTag ( tag : Int ) : HHKeyboard ? {
override fun keyboardForTag ( tag : Int ) : HHKeyboard ? {
return when ( this ) {
return when ( this ) {
BLINDS -> HHKeyboard . AMOUNT
BLINDS -> HHKeyboard . AMOUNT
@ -168,7 +190,7 @@ class HandHistoryAdapter(
abstract inner class RowHandHolder ( itemView : View ) : RecyclerView . ViewHolder ( itemView ) , BindableHolder {
abstract inner class RowHandHolder ( itemView : View ) : RecyclerView . ViewHolder ( itemView ) , BindableHolder {
var currentPosition = 0
protected var currentPosition = 0
fun color ( isFocused : Boolean ) : Int {
fun color ( isFocused : Boolean ) : Int {
val color = if ( isFocused ) R . color . kaki _medium else R . color . kaki
val color = if ( isFocused ) R . color . kaki _medium else R . color . kaki
@ -194,21 +216,27 @@ class HandHistoryAdapter(
this . configureEditTexts ( index .. index , position , row , adapter )
this . configureEditTexts ( index .. index , position , row , adapter )
}
}
protected fun configureEditTexts ( r ange: IntRange , position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
protected fun configureEditTexts ( tagR ange: IntRange , position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
range . forEach { tag ->
tagRange . forEach { tag ->
val string = adapter . dataSource . charSequenceForRow ( row , itemView . context , tag )
val editText = itemView . findViewWithTag < EditText > ( tag ) ?: throw PAIllegalStateException ( " Edit Text not found for tag: $tag , class: $this " )
// Enabled
editText . isEnabled = adapter . dataSource . isEnabled ( row , tag )
// Text
// Text
val editText = itemView . findViewWithTag < EditText > ( tag ) ?: throw PAIllegalStateException ( " Edit Text not found for tag: $tag , class: $this " )
val string = adapter . dataSource . charSequenceForRow ( row , itemView . context , tag )
editText . setText ( string )
editText . setText ( string )
// Focus
// Focus
val selected = adapter . dataSource . isSelected ( position , row , tag )
val selected = adapter . dataSource . isSelected ( position , row , tag )
toggleFocus ( editText , selected )
toggleFocus ( editText , selected )
editText . isFocusable = adapter . dataSource . isFocusable ( position , row , tag )
editText . isFocusableInTouchMode = adapter . dataSource . isFocusable ( position , row , tag )
// Background
// Background
editText . setBackgroundColor ( color ( selected ) )
editText . setBackgroundColor ( color ( selected ) )
}
}
}
}
@ -223,7 +251,6 @@ class HandHistoryAdapter(
open fun editTextForTag ( tag : Int ) : EditText {
open fun editTextForTag ( tag : Int ) : EditText {
return itemView . findViewWithTag ( tag )
return itemView . findViewWithTag ( tag )
// throw PAIllegalStateException("Field at tag: $tag requires to return an EditText in order to connect the keyboard to it. Should be overridden by class : $this")
}
}
}
}
@ -242,21 +269,6 @@ class HandHistoryAdapter(
super . onBind ( position , row , adapter )
super . onBind ( position , row , adapter )
configureEditTexts ( 0. . 2 , position , row , adapter )
configureEditTexts ( 0. . 2 , position , row , adapter )
// itemView.smallBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.bigBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
// itemView.anteEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 2))
// itemView.bbAnteSwitch.isChecked = adapter.dataSource.isSelected(position, row, 0)
//
// val sbSelected = adapter.dataSource.isSelected(position, row, 0)
// toggleFocus(itemView.smallBlindEditText, sbSelected)
//
// val bbSelected = adapter.dataSource.isSelected(position, row, 1)
// toggleFocus(itemView.bigBlindEditText, bbSelected)
//
// val anteSelected = adapter.dataSource.isSelected(position, row, 2)
// toggleFocus(itemView.anteEditText, anteSelected)
}
}
}
}
@ -337,10 +349,6 @@ class HandHistoryAdapter(
}
}
}
}
// override fun editTextForTag(tag: Int): EditText {
// return itemView.amountEditText
// }
override fun onBind ( position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
override fun onBind ( position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
super . onBind ( position , row , adapter )
super . onBind ( position , row , adapter )
@ -353,7 +361,8 @@ class HandHistoryAdapter(
// Action
// Action
itemView . findViewById < Button > ( R . id . actionButton ) ?. let { actionButton ->
itemView . findViewById < Button > ( R . id . actionButton ) ?. let { actionButton ->
actionButton . isEnabled = computedAction . actionTypeCanBeEdited
// actionButton.isEnabled = computedAction.actionTypeCanBeEdited
actionButton . isEnabled = adapter . dataSource . isEnabled ( row , actionButton . tag as Int )
val selected = adapter . dataSource . isSelected ( position , row , actionButton . tag as Int )
val selected = adapter . dataSource . isSelected ( position , row , actionButton . tag as Int )
actionButton . backgroundTintList = ColorStateList . valueOf ( color ( selected ) )
actionButton . backgroundTintList = ColorStateList . valueOf ( color ( selected ) )
@ -368,18 +377,17 @@ class HandHistoryAdapter(
// Amount
// Amount
itemView . findViewById < EditText > ( R . id . amountEditText ) ?. let { amountEditText ->
itemView . findViewById < EditText > ( R . id . amountEditText ) ?. let { amountEditText ->
amountEditText . isEnabled = computedAction . amountCanBeEdited
// amountEditText.isEnabled = computedAction. amountCanBeEdited
val tag = amountEditText . tag as Int
val tag = amountEditText . tag as Int
val selected = adapter . dataSource . isSelected ( position , row , tag )
configureEditTexts ( tag , position , row , adapter )
// val selected = adapter.dataSource.isSelected(position, row, tag)
// amountEditText.setBackgroundColor(color(selected))
// amountEditText.setBackgroundColor(color(selected))
// Useful to have the cursor disappear when the keyboard is closed
// Useful to have the cursor disappear when the keyboard is closed
amountEditText . isFocusable = selected && computedAction . amountCanBeEdited
// amountEditText.isFocusable = selected && computedAction.amountCanBeEdited
amountEditText . isFocusableInTouchMode = selected && computedAction . amountCanBeEdited
// amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited
configureEditTexts ( tag , position , row , adapter )
// amountEditText.setText(computedAction.action.formattedAmount)
// amountEditText.setText(computedAction.action.formattedAmount)
//
//
@ -388,7 +396,7 @@ class HandHistoryAdapter(
// } else {
// } else {
// amountEditText.clearFocus()
// amountEditText.clearFocus()
// }
// }
Timber . d ( " Amount at $position is selected: $selected , focusable = ${amountEditText.isFocusable} , isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode} , hasFocus = ${amountEditText.hasFocus()} , enabled = ${amountEditText.isEnabled} " )
// Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}" )
}
}
@ -430,77 +438,24 @@ class HandHistoryAdapter(
}
}
override fun onBind ( position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
override fun onBind ( position : Int , row : RowRepresentable , adapter : RecyclerAdapter ) {
super . onBind ( position , row , adapter )
super . onBind ( position , row , adapter )
val streetCardView = row as StreetCardsRow
val street = streetCardView . street
configureEditTexts ( Street . FLOP . ordinal .. Street . RIVER . ordinal , position , row , adapter )
configureEditTexts ( Street . FLOP . ordinal .. Street . RIVER . ordinal , position , row , adapter )
itemView . findViewById < EditText > ( R . id . flopEditText ) ?. let { flopEditText ->
flopEditText . isFocusable = ( street == Street . FLOP )
flopEditText . isVisible = true
// val flop = streetCardView.cardHolder?.cards?.take(3)
// val text = flop?.formatted(itemView.context)
// flopEditText.setText(text)
//
// val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
// toggleFocus(flopEditText, selected)
}
}
itemView . findViewById < EditText > ( R . id . turnEditText ) ?. let { turnEditText ->
// turnEditText.isVisible = streetCardView.street.ordinal >= Street.TURN.ordinal
turnEditText . isFocusable = ( street == Street . TURN )
// if (streetCardView.cardCount > 3) {
// val text = streetCardView.cardAtIndex(3)?.formatted(itemView.context)
// turnEditText.setText(text)
// } else {
// turnEditText.text = null
// }
//
// val selected = adapter.dataSource.isSelected(position, row, Street.TURN.ordinal)
// toggleFocus(turnEditText, selected)
}
}
itemView . findViewById < EditText > ( R . id . riverEditText ) ?. let { riverEditText ->
// riverEditText.isVisible = streetCardView.street.ordinal >= Street.RIVER.ordinal
riverEditText . isFocusable = ( street == Street . RIVER )
// if (streetCardView.cardCount > 4) {
// val text = streetCardView.cardAtIndex(4)?.formatted(itemView.context)
// riverEditText.setText(text)
// } else {
// riverEditText.text = null
// }
//
// val selected = adapter.dataSource.isSelected(position, row, Street.RIVER.ordinal)
// toggleFocus(riverEditText, selected)
}
}
}
/ * *
/ * *
* Display a hand action
* Display a hand action
* /
* /
inner class RowHandPlayerSummary ( itemView : View ) : RowHandHolder ( itemView ) {
inner class RowHandPlayerSummary ( itemView : View ) : RowHandHolder ( itemView ) {
init {
init {
itemView . cardsEditText . tag = PlayerCardsRow . Tag . CARDS . ordinal
// Cards
// Cards
itemView . findViewById < EditText > ( R . id . cardsEditText ) ?. let { cardsEditText ->
itemView . findViewById < EditText > ( R . id . cardsEditText ) ?. let { cardsEditText ->
cardsEditText . tag = PlayerCardsRow . Tag . CARDS . ordinal
cardsEditText . isFocusableInTouchMode = true
cardsEditText . isFocusableInTouchMode = true
cardsEditText . setOnTouchListener { _ , event ->
cardsEditText . setOnTouchListener { _ , event ->
if ( event . action == MotionEvent . ACTION _UP ) {
if ( event . action == MotionEvent . ACTION _UP ) {
@ -529,23 +484,8 @@ class HandHistoryAdapter(
positionButton . text = playerCardView . position ?. value ?: throw PAIllegalStateException ( " Should not happen " )
positionButton . text = playerCardView . position ?. value ?: throw PAIllegalStateException ( " Should not happen " )
}
}
// Amount
itemView . findViewById < EditText > ( R . id . cardsEditText ) ?. let { cardsEditText ->
val selected = adapter . dataSource . isSelected ( position , row , PlayerCardsRow . Tag . CARDS . ordinal )
// Both are required, otherwise requestFocus() fails
cardsEditText . isFocusable = selected
cardsEditText . isFocusableInTouchMode = selected
configureEditTexts ( PlayerCardsRow . Tag . CARDS . ordinal , position , row , adapter )
configureEditTexts ( PlayerCardsRow . Tag . CARDS . ordinal , position , row , adapter )
// Timber.d("cardsEditText at $position is selected: $selected, focusable = ${cardsEditText.isFocusable}, isFocusableInTouchMode = ${cardsEditText.isFocusableInTouchMode}, hasFocus = ${cardsEditText.hasFocus()}, enabled = ${cardsEditText.isEnabled}")
// cardsEditText.setBackgroundColor(color(selected))
//
// cardsEditText.setText(playerCardView.cardHolder?.cards?.formatted(itemView.context))
// toggleFocus(cardsEditText, selected)
}
}
}
}
}
@ -556,7 +496,7 @@ class HandHistoryAdapter(
init {
init {
itemView . handEditText . tag = PlayerSetupRow . Tag . CARDS . ordinal
itemView . handEditText . tag = PlayerSetupRow . Tag . HAND . ordinal
itemView . stackEditText . tag = PlayerSetupRow . Tag . STACK . ordinal
itemView . stackEditText . tag = PlayerSetupRow . Tag . STACK . ordinal
// Position Recycler
// Position Recycler
@ -612,44 +552,22 @@ class HandHistoryAdapter(
// Position Button
// Position Button
itemView . posButton . text = adapter . dataSource . charSequenceForRow ( row , itemView . context , PlayerSetupRow . Tag . POSITION . ordinal )
itemView . posButton . text = adapter . dataSource . charSequenceForRow ( row , itemView . context , PlayerSetupRow . Tag . POSITION . ordinal )
itemView . posButton . setOnClickListener {
// itemView.posButton.setOnClickListener {
setupRow . showPosition ( )
// setupRow.showPosition( )
itemView . positionRecyclerView . visibility = View . VISIBLE
// itemView.positionRecyclerView.visibility = View. VISIBLE
itemView . posButton . backgroundTintList = ColorStateList . valueOf ( color ( true ) )
// itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true) )
}
// }
val positionSelected = adapter . dataSource . isSelected ( position , row , PlayerSetupRow . Tag . POSITION . ordinal )
val positionSelected = adapter . dataSource . isSelected ( position , row , PlayerSetupRow . Tag . POSITION . ordinal )
itemView . posButton . backgroundTintList = ColorStateList . valueOf ( color ( positionSelected ) )
itemView . posButton . backgroundTintList = ColorStateList . valueOf ( color ( positionSelected ) )
// Settings
// Settings
itemView . settings _container . visibility = if ( state == PlayerSetupRow . State . POSITIONS _ONLY ) View . GONE else View . VISIBLE
itemView . settings _container . visibility = if ( state == PlayerSetupRow . State . POSITIONS _ONLY ) View . GONE else View . VISIBLE
configureEditTexts ( 1. . 2 , position , row , adapter )
configureEditTexts ( PlayerSetupRow . Tag . HAND . ordinal , position , row , adapter )
configureEditTexts ( PlayerSetupRow . Tag . STACK . ordinal , position , row , adapter )
// Hand
// itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context))
// val handSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.CARDS.ordinal)
// itemView.handEditText.setBackgroundColor(color(handSelected))
// toggleFocus(itemView.handEditText, handSelected)
//
// // Stack
// itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted())
// val stackSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.STACK.ordinal)
// itemView.stackEditText.setBackgroundColor(color(stackSelected))
// toggleFocus(itemView.stackEditText, stackSelected)
// itemView.handEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.stackEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
}
}
// override fun editTextForTag(tag: Int): EditText {
// return when (tag) {
// PlayerSetupRow.Tag.STACK.ordinal -> itemView.stackEditText
// else -> throw PAIllegalStateException("unmanaged tag $tag")
// }
// }
}
}
}
}