Prepare Player Setup rows

hh
Laurent 6 years ago
parent 64d593df41
commit e7b820dc33
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt
  2. 49
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  3. 26
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  4. 46
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt
  5. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt
  7. 31
      app/src/main/res/layout/row_hhsettings_player_setup.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -13,7 +13,7 @@ open class PlayerSetup : RealmObject(), CardHolder {
var player: Player? = null var player: Player? = null
/*** /***
* The position at the table: SB..BUTTON * The position at the table
*/ */
var position: Int = 0 var position: Int = 0

@ -14,8 +14,10 @@ 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_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 net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.formatted import net.pokeranalytics.android.model.realm.handhistory.formatted
@ -25,15 +27,15 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.px import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction import net.pokeranalytics.android.ui.modules.handhistory.model.*
import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard
import net.pokeranalytics.android.ui.modules.handhistory.model.HandHistoryRow
import net.pokeranalytics.android.ui.modules.handhistory.model.StraddleRowRepresentable
import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow
import net.pokeranalytics.android.ui.modules.handhistory.views.PositionAdapter
import net.pokeranalytics.android.ui.modules.handhistory.views.PositionSelectionListener
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow
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 net.pokeranalytics.android.util.extensions.formatted
import timber.log.Timber import timber.log.Timber
@ -518,15 +520,46 @@ class HandHistoryAdapter(
} }
} }
inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) { inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView), PositionSelectionListener {
private var positionAdapter: PositionAdapter = PositionAdapter(this)
init {
// TODO configure recycler view
// itemView.positionRecyclerView
}
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)
// itemView.positionsChipGroup val setup = row as PlayerSetupRowRepresentable
val state = setup.state
itemView.title.text = setup.title(itemView.context)
val visibility = if (state == PlayerSetupRowRepresentable.State.SHOW_POSITION) View.VISIBLE else View.GONE
itemView.positionRecyclerView.visibility = visibility
itemView.posButton.text = setup.position?.value
itemView.settings_container.visibility = if (state == PlayerSetupRowRepresentable.State.POSITION_ONLY) View.GONE else View.VISIBLE
itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context))
itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted())
this.positionAdapter.positions = listOf() // TODO
// itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0))
// itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1))
}
override fun positionSelected(position: Position) {
itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) // TODO sets position for PlayerSetup
itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1))
} }

@ -187,6 +187,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) rows.add(StraddleRowRepresentable(positions, this.straddlePositions))
} }
this.playerSetups().forEach {
rows.add(it)
}
Street.values().forEach { street -> Street.values().forEach { street ->
val actions = this.sortedActions.filter { it.street == street } val actions = this.sortedActions.filter { it.street == street }
@ -572,4 +576,26 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
private fun playerSetups(): List<PlayerSetupRowRepresentable> {
val hh = this.handHistory
val arrangedSetups = hh.playerSetups.sortedBy { it.position }.map { PlayerSetupRowRepresentable(playerSetup = it) }.toMutableList()
val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex }
heroSetup?.let {
it.hero = true
arrangedSetups.remove(it)
arrangedSetups.add(0, it)
} ?: run {
arrangedSetups.add(PlayerSetupRowRepresentable(true, null))
}
if (arrangedSetups.size < hh.numberOfPlayers) {
arrangedSetups.add(PlayerSetupRowRepresentable(false, null))
}
return arrangedSetups
}
} }

@ -0,0 +1,46 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import android.content.Context
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable
class PlayerSetupRowRepresentable(var hero: Boolean = false, var playerSetup: PlayerSetup? = null) :
RowRepresentable {
var positionEdited: Boolean = false
var position: Position? = null
enum class State {
POSITION_ONLY,
SHOW_POSITION,
DEFAULT,
}
val state: State
get() {
return when {
this.positionEdited -> State.SHOW_POSITION
(this.playerSetup == null) -> State.POSITION_ONLY
else -> State.DEFAULT
}
}
fun title(context: Context): String {
return if (this.hero) {
context.getString(R.string.hero)
} else {
this.playerSetup?.player?.name?.let {
it
} ?: run {
context.getString(R.string.vilain)
}
}
}
override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal
}

@ -14,7 +14,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard
interface KeyboardListener { interface KeyboardListener : PositionSelectionListener {
fun actionSelected(action: Action.Type) fun actionSelected(action: Action.Type)
fun amountChanged(amount: String?) fun amountChanged(amount: String?)
fun amountValidated() fun amountValidated()
@ -25,6 +25,9 @@ interface KeyboardListener {
fun cardBackSpaceSelected() fun cardBackSpaceSelected()
fun cardSelectionEnded() fun cardSelectionEnded()
fun closeKeyboard() fun closeKeyboard()
}
interface PositionSelectionListener {
fun positionSelected(position: Position) fun positionSelected(position: Position)
} }

@ -14,7 +14,7 @@ import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.holder.RowViewHolder import net.pokeranalytics.android.ui.view.holder.RowViewHolder
import timber.log.Timber import timber.log.Timber
class PositionAdapter(var keyboardListener: KeyboardListener) : class PositionAdapter(var listener: PositionSelectionListener) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(), RecyclerView.Adapter<RecyclerView.ViewHolder>(),
RowRepresentableDataSource, RowRepresentableDelegate, RecyclerAdapter { RowRepresentableDataSource, RowRepresentableDelegate, RecyclerAdapter {
@ -61,7 +61,7 @@ class PositionAdapter(var keyboardListener: KeyboardListener) :
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
Timber.d("/////onRowSelected") Timber.d("/////onRowSelected")
keyboardListener.positionSelected(this.positions[position]) this.listener.positionSelected(this.positions[position])
} }
} }

@ -1,20 +1,41 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.chip.ChipGroup <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/positionsChipGroup" android:id="@+id/title"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="44dp" android:layout_height="wrap_content"
app:chipSpacing="8dp" /> android:layout_marginStart="8dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/positionRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout <LinearLayout
android:id="@+id/settings_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> 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"/>
<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"/>
<androidx.appcompat.widget.AppCompatEditText <androidx.appcompat.widget.AppCompatEditText
android:id="@+id/handEditText" android:id="@+id/handEditText"
style="@style/PokerAnalyticsTheme.EditText" style="@style/PokerAnalyticsTheme.EditText"

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

Loading…
Cancel
Save