read mode for player setups

hh
Laurent 6 years ago
parent 111b7a7489
commit dbe325e6e7
  1. 197
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt
  5. 29
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  6. 34
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt
  7. 23
      app/src/main/res/layout/row_hand_action_read.xml
  8. 11
      app/src/main/res/layout/row_hhsettings_player_setup.xml
  9. 45
      app/src/main/res/layout/row_hhsettings_player_setup_read.xml

@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
@ -17,12 +18,15 @@ import kotlinx.android.synthetic.main.row_hand_action_read.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_player_setup.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.posButton
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.psHandLayout
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.settings_container
import kotlinx.android.synthetic.main.row_hhsettings_player_setup_read.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
@ -37,7 +41,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier
import net.pokeranalytics.android.util.extensions.formatted
enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow {
enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable {
DEFAULT(R.layout.row_title),
HEADER(R.layout.row_header_value),
ACTION(R.layout.row_hand_action),
@ -47,6 +51,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
COMMENT(R.layout.row_hhsettings_comments),
PLAYER_NUMBER(R.layout.row_title_value),
PLAYER_SETUP(R.layout.row_hhsettings_player_setup),
PLAYER_SETUP_READ(R.layout.row_hhsettings_player_setup_read),
ANTE(R.layout.row_title_value),
BIG_BLIND_ANTE(R.layout.row_title_switch),
ACTION_READ(R.layout.row_hand_action_read)
@ -57,50 +62,6 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
override val identifier: Int
get() { return this.ordinal }
override fun tagsForCompletion(): List<Int> {
// return when (this) {
// BLINDS -> listOf(0, 1)
// else -> listOf()
// }
return listOf()
}
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
// return when (this) {
// BLINDS -> {
// when (tag) {
// 0 -> (handHistory.smallBlind == null)
// 1 -> (handHistory.bigBlind == null)
// else -> false
// }
// }
// else -> false
// }
return false
}
override fun keyboardForTag(tag: Int): HHKeyboard? {
// return when (this) {
// BLINDS -> HHKeyboard.AMOUNT
// else -> throw PAIllegalStateException("unmanaged tag $tag")
// }
throw PAIllegalStateException("unmanaged tag $tag")
}
override fun amountForTag(handHistory: HandHistory, tag: Int): Double? {
// return when (this) {
// BLINDS -> {
// when (tag) {
// 0 -> handHistory.smallBlind
// 1 -> handHistory.bigBlind
// else -> null
// }
// }
// else -> null
// }
return null
}
override val bottomSheetType: BottomSheetType
get() {
return when(this) {
@ -154,9 +115,9 @@ class HandHistoryAdapter(
HandRowType.ACTION -> RowHandAction(layout)
HandRowType.STREET -> RowHandStreet(layout)
HandRowType.PLAYER_SUMMARY -> RowHandPlayerSummary(layout)
// HandRowType.BLINDS -> RowHandBlinds(layout)
HandRowType.STRADDLE -> RowHandStraddle(layout)
HandRowType.PLAYER_SETUP -> RowHandPlayerSetup(layout)
HandRowType.PLAYER_SETUP_READ -> RowHandReadOnlyPlayerSetup(layout)
HandRowType.COMMENT -> RowViewHolder(layout)
HandRowType.ACTION_READ -> RowActionRead(layout)
HandRowType.PLAYER_NUMBER, HandRowType.ANTE, HandRowType.BIG_BLIND_ANTE -> RowViewHolder(layout)
@ -211,7 +172,7 @@ class HandHistoryAdapter(
this.configureEditTexts(index..index, position, row, adapter)
}
protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
private fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
tagRange.forEach { tag ->
@ -245,6 +206,11 @@ class HandHistoryAdapter(
}
protected fun configureTextView(tag: Int, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
val textView = itemView.findViewWithTag<TextView>(tag) ?: throw PAIllegalStateException("TextView not found for tag: $tag, class: $this")
textView.text = adapter.dataSource.charSequenceForRow(row, itemView.context, tag)
}
protected fun setClickListener(editText: EditText) {
editText.isFocusableInTouchMode = true
@ -302,29 +268,6 @@ class HandHistoryAdapter(
}
// inner class RowHandBlinds(itemView: View) : RowHandHolder(itemView) {
//
// init {
//// itemView.smallBlindEditText.tag = 0
//// itemView.bigBlindEditText.tag = 1
// itemView.anteEditText.tag = 0
//
//// setClickListener(itemView.smallBlindEditText)
//// setClickListener(itemView.bigBlindEditText)
// setClickListener(itemView.anteEditText)
//
// }
//
// // sb, bb, ante, bb ante
//
// override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
// super.onBind(position, row, adapter)
//
// configureEditTexts(0, position, row, adapter)
// }
//
// }
inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -453,10 +396,6 @@ class HandHistoryAdapter(
*/
inner class RowHandStreet(itemView: View) : RowHandHolder(itemView) {
init {
// itemView.cardsLayout.tag = 0
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
@ -464,19 +403,6 @@ class HandHistoryAdapter(
itemView.cardsLayout.tag = streetCardsRow.street.ordinal
configureCardsLayout(itemView.cardsLayout)
// itemView.cardsLayout.removeAllViews()
//
// val inflater = LayoutInflater.from(itemView.context)
// adapter.dataSource.contentForRow(row, itemView.context, Card::class).forEach { card ->
// val cardView = card.view(itemView.context, inflater, itemView.cardsLayout)
// itemView.cardsLayout.addView(cardView)
// }
//
// itemView.cardsLayout.setOnClickListener {
// adapter.delegate?.onRowSelected(position, row)
// }
}
}
@ -487,30 +413,7 @@ class HandHistoryAdapter(
inner class RowHandPlayerSummary(itemView: View) : RowHandHolder(itemView) {
init {
itemView.handLayout.tag = PlayerCardsRow.Tag.CARDS.ordinal
// itemView.cardsEditText.tag = PlayerCardsRow.Tag.CARDS.ordinal
// Cards
// itemView.findViewById<EditText>(R.id.cardsEditText)?.let { cardsEditText ->
//
// cardsEditText.isFocusableInTouchMode = true
// cardsEditText.setOnTouchListener { _, event ->
//
// if (event.action == MotionEvent.ACTION_UP) {
// // Both are required, otherwise requestFocus() fails
// cardsEditText.isFocusable = true
// cardsEditText.isFocusableInTouchMode = true
//
// cardsEditText.requestFocus()
//
// editTextSelected(cardsEditText, true, PlayerCardsRow.Tag.CARDS.ordinal)
// }
// return@setOnTouchListener true
// }
//
// }
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -525,52 +428,41 @@ class HandHistoryAdapter(
}
configureCardsLayout(itemView.handLayout)
}
}
// configureEditTexts(PlayerCardsRow.Tag.CARDS.ordinal, position, row, adapter)
inner class RowHandReadOnlyPlayerSetup(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
init {
itemView.stackTextView.tag = PlayerSetupRow.Tag.STACK.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
configureTextView(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
}
}
inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) {
inner class RowHandPlayerSetup(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
private var positionAdapter: PositionAdapter = PositionAdapter()
private var delegate: RowRepresentableDelegate? = null
private var positionViewManager: LinearLayoutManager
init {
itemView.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal
itemView.stackEditText.tag = PlayerSetupRow.Tag.STACK.ordinal
itemView.stackEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(itemView.stackEditText)
// Position Recycler
val positionViewManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false)
this.positionViewManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false)
itemView.positionRecyclerView.apply {
setHasFixedSize(true)
layoutManager = positionViewManager
adapter = positionAdapter
}
itemView.findViewById<EditText>(R.id.stackEditText)?.let { stackEditText ->
stackEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
stackEditText.isFocusableInTouchMode = true
stackEditText.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
// Both are required, otherwise requestFocus() fails
stackEditText.isFocusable = true
stackEditText.isFocusableInTouchMode = true
stackEditText.requestFocus()
editTextSelected(stackEditText, true, stackEditText.tag as Int)
}
return@setOnTouchListener true
}
}
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -578,7 +470,6 @@ class HandHistoryAdapter(
val setupRow = row as PlayerSetupRow
val state = setupRow.state
this.delegate = adapter.delegate
// Title
itemView.title.text = setupRow.title(itemView.context)
@ -595,13 +486,29 @@ class HandHistoryAdapter(
this.delegate?.onRowValueChanged(pos, row)
}
configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
}
}
abstract inner class AbstractRowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) {
protected var delegate: RowRepresentableDelegate? = null
init {
itemView.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val setupRow = row as PlayerSetupRow
val state = setupRow.state
this.delegate = adapter.delegate
// Position Button
itemView.posButton.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
// itemView.posButton.setOnClickListener {
// setupRow.showPosition()
// itemView.positionRecyclerView.visibility = View.VISIBLE
// itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true))
// }
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
@ -609,8 +516,6 @@ class HandHistoryAdapter(
itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE
configureCardsLayout(itemView.psHandLayout)
// configureEditTexts(PlayerSetupRow.Tag.HAND.ordinal, position, row, adapter)
configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
}

@ -169,6 +169,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
menu?.clear()
this.menu = menu
inflater?.inflate(R.menu.toolbar_hand_history, menu)
updateMenuUI()
super.onCreateOptionsMenu(menu, inflater)
@ -196,7 +197,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun retrieveEditTextInputConnection(selection: HHSelection) {
val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandRowType
// throw PAIllegalStateException("I believe this should not happen any more")
val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandHistoryRow
val holder = recyclerView.findViewHolderForAdapterPosition(selection.index) as? HandHistoryAdapter.RowHandHolder
holder?.let {
@ -210,6 +213,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun saveOrEdit() {
this.model.isEdited = !this.model.isEdited
updateMenuUI()
if (this.model.isEdited) {
this.findNextActionToEdit(0)

@ -133,6 +133,8 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
*/
override fun minimumBetAmount(index: Int): Double {
if (this[index].action.type?.isBlind == true) return 0.0 // no min for blinds
val street = this[index].street
// Verify that the amount is correct, at least the amount of the previous raise difference

@ -7,6 +7,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
class ActionReadRow(var positions: MutableList<Position>, var action: Action.Type?, var amount: Double?) : RowRepresentable {
override val viewType: Int = HandRowType.STREET.ordinal
override val viewType: Int = HandRowType.ACTION_READ.ordinal
}

@ -215,8 +215,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
rows.add(HandRowType.BIG_BLIND_ANTE)
}
this.playerSetups().forEach {
this.readPlayerSetups().forEach {
rows.add(it)
}
@ -797,6 +796,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
private fun readPlayerSetups(): List<PlayerSetupRow> {
val hh = this.handHistory
return hh.playerSetups.sortedBy { it.position }.map {
val position = this.positionForIndex(it.position)
createPlayerSetupRow(it, position, hero = false, readMode = true)
}
}
/***
* Returns the list of PlayerSetupRowRepresentable for the hand
* Will show rows for existing PlayerSetup, as well as a row for the hero if not set,
@ -808,7 +816,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val arrangedSetups = hh.playerSetups.sortedBy { it.position }.map {
val position = this.positionForIndex(it.position)
createPlayerSetupRow(false, position, it)
createPlayerSetupRow(it, position, false)
}.toMutableList()
val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex }
@ -817,11 +825,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
arrangedSetups.remove(it)
arrangedSetups.add(0, it)
} ?: run {
arrangedSetups.add(0, createPlayerSetupRow(true))
arrangedSetups.add(0, createPlayerSetupRow(hero = true))
}
if (arrangedSetups.size < hh.numberOfPlayers) {
arrangedSetups.add(createPlayerSetupRow(false))
arrangedSetups.add(createPlayerSetupRow(hero = false))
}
return arrangedSetups
@ -830,8 +838,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/***
* Convenience method to create a PlayerSetupRow
*/
private fun createPlayerSetupRow(hero: Boolean, position: Position? = null, playerSetup: PlayerSetup? = null): PlayerSetupRow {
return PlayerSetupRow(hero, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards)
private fun createPlayerSetupRow(
playerSetup: PlayerSetup? = null,
position: Position? = null,
hero: Boolean,
readMode: Boolean = false
): PlayerSetupRow {
return PlayerSetupRow(hero, readMode, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards)
}
/***
@ -853,7 +866,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
if (!playerSetupRow.hero && setupCreated) {
if (this.handHistory.undefinedPositions().isNotEmpty()) {
val newPlayerRow = createPlayerSetupRow(false)
val newPlayerRow = createPlayerSetupRow(hero = false)
val index = this.indexOfRowRepresentable(playerSetupRow)
this.rowsLiveData.value?.add(index + 1, newPlayerRow)
}

@ -9,6 +9,7 @@ import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
class PlayerSetupRow(var hero: Boolean = false,
var readMode: Boolean = false,
position: Position?,
positionIndex: Int?,
handHistory: HandHistory,
@ -38,10 +39,6 @@ class PlayerSetupRow(var hero: Boolean = false,
return if (this.playerSetup != null) State.SETUP_ONLY else State.POSITIONS_ONLY
}
fun showPosition() {
this._state = State.BOTH
}
fun closePosition() {
this._state = null
}
@ -63,27 +60,14 @@ class PlayerSetupRow(var hero: Boolean = false,
}
override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
//
// // if the PlayerSetup exists
// this.playerSetup?.let {
// super.tagForCompletion(handHistory, minTag)?.let { tag ->
// return Tag.HAND.ordinal
// }
//
// // stack
// if (it.stack == null) {
// return Tag.STACK.ordinal
// }
// }
//
// return null
// }
override val viewType: Int
get() {
return if (this.readMode) {
HandRowType.PLAYER_SETUP_READ.ordinal
} else {
HandRowType.PLAYER_SETUP.ordinal
}
}
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return when(tag) {

@ -1,28 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="@+id/playerButton"
style="@style/PokerAnalyticsTheme.HHButton"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/playersText"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginStart="8dp" />
android:layout_marginStart="8dp"
tools:text="BB"
/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/actionText"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp" />
android:layout_marginStart="8dp"
tools:text="raises"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/amountText"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp" />
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:gravity="end"
tools:text="120" />
</LinearLayout>

@ -49,17 +49,6 @@
android:paddingEnd="0dp"
android:gravity="center"/>
<!-- <androidx.appcompat.widget.AppCompatEditText-->
<!-- android:id="@+id/handEditText"-->
<!-- style="@style/PokerAnalyticsTheme.EditText"-->
<!-- android:layout_width="0dp"-->
<!-- android:hint="@string/hand"-->
<!-- android:layout_weight="1"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="center"-->
<!-- android:inputType="none"-->
<!-- android:maxLines="1" />-->
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/stackEditText"
style="@style/PokerAnalyticsTheme.EditText"

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/playerButton"
style="@style/PokerAnalyticsTheme.HHButton"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/posButton"
style="@style/PokerAnalyticsTheme.HHButton"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginStart="8dp" />
<LinearLayout
android:id="@+id/psHandLayout"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:background="@drawable/rounded_board_background"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="4dp"
android:paddingEnd="0dp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/stackTextView"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end|center"
android:maxLines="1"
tools:text="120" />
</LinearLayout>
Loading…
Cancel
Save