Progression in Player Setups

hh
Laurent 6 years ago
parent 40e84c8a96
commit 7411aa460b
  1. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  3. 32
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  4. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  5. 41
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  6. 66
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt
  7. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/CardsRow.kt
  8. 5
      app/src/main/res/layout/row_hhsettings_player_setup.xml
  9. 2
      app/src/main/res/values/strings.xml

@ -32,14 +32,10 @@ open class Card : RealmObject() {
companion object { companion object {
fun newInstance(realm: Realm, value: Int? = null, suit: Suit? = null, index: Int = 0) : Card { fun newInstance(realm: Realm, value: Int? = null, suit: Suit? = null, index: Int = 0) : Card {
val card = realm.createObject(Card::class.java)
val card = Card()
value?.let { card.value = it } value?.let { card.value = it }
suit?.let { card.suit = it} suit?.let { card.suit = it}
card.index = index card.index = index
realm.copyToRealm(card)
return card return card
} }
} }

@ -175,4 +175,11 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
return copy.toList() return copy.toList()
} }
fun createPlayerSetup(positionIndex: Int): PlayerSetup {
val playerSetup = this.realm.createObject(PlayerSetup::class.java)
playerSetup.position = positionIndex
this.playerSetups.add(playerSetup)
return playerSetup
}
} }

@ -545,22 +545,42 @@ class HandHistoryAdapter(
val state = setup.state val state = setup.state
this.delegate = adapter.delegate this.delegate = adapter.delegate
// Title
itemView.title.text = setup.title(itemView.context) itemView.title.text = setup.title(itemView.context)
val visibility = if (state == PlayerSetupRowRepresentable.State.SHOW_POSITION) View.VISIBLE else View.GONE // Position recycler
val visibility = if (state == PlayerSetupRowRepresentable.State.SETUP_ONLY) View.GONE else View.VISIBLE
itemView.positionRecyclerView.visibility = visibility itemView.positionRecyclerView.visibility = visibility
this.positionAdapter.positions = adapter.dataSource.contentForRow(row, itemView.context, Position::class)
this.positionAdapter.setOnClickListener { pos ->
setup.closePosition()
this.delegate?.onRowValueChanged(pos, row)
}
// Position Button
itemView.posButton.text = setup.position?.value itemView.posButton.text = setup.position?.value
itemView.posButton.setOnClickListener {
setup.showPosition()
itemView.positionRecyclerView.visibility = View.VISIBLE
itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true))
}
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRowRepresentable.Tag.POSITION.ordinal)
itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
itemView.settings_container.visibility = if (state == PlayerSetupRowRepresentable.State.POSITION_ONLY) View.GONE else View.VISIBLE // Settings
itemView.settings_container.visibility = if (state == PlayerSetupRowRepresentable.State.POSITIONS_ONLY) View.GONE else View.VISIBLE
// Hand
itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context)) itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context))
val handSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRowRepresentable.Tag.CARDS.ordinal)
itemView.handEditText.setBackgroundColor(color(handSelected))
// Stack
itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted()) itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted())
val stackSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRowRepresentable.Tag.STACK.ordinal)
itemView.stackEditText.setBackgroundColor(color(stackSelected))
this.positionAdapter.positions = adapter.dataSource.contentForRow(row, itemView.context, Position::class)
this.positionAdapter.setOnClickListener { pos ->
this.delegate?.onRowValueChanged(pos, row)
}
// itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) // itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0))
// itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1)) // itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1))

@ -83,7 +83,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
?: throw PAIllegalStateException("HandHistory not found") ?: throw PAIllegalStateException("HandHistory not found")
this.model.setHandHistory(handHistory) this.model.setHandHistory(handHistory)
} ?: run { } ?: run {
this.model.createNewHandHistory(HandSetup()) getRealm().executeTransaction {
this.model.createNewHandHistory(it, HandSetup())
}
} }
} }
@ -250,8 +252,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
is PlayerSetupRowRepresentable -> { is PlayerSetupRowRepresentable -> {
when (value) { when (value) {
is Int -> { is Int -> {
row.playerSetup?.position = value this.model.setPlayerSetupPosition(row, value)
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) val index = this.indexOfRowRepresentable(row)
this.handHistoryAdapter.notifyItemChanged(index)
this.findNextActionToEdit(index)
} }
} }
} }

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import android.content.Context import android.content.Context
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import io.realm.Realm
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.HandSetup import net.pokeranalytics.android.model.handhistory.HandSetup
@ -133,15 +134,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/*** /***
* Creates and configures a new HandHistory object using a [handSetup] * Creates and configures a new HandHistory object using a [handSetup]
*/ */
fun createNewHandHistory(handSetup: HandSetup) { fun createNewHandHistory(realm: Realm, handSetup: HandSetup) {
this.handSetup = handSetup this.handSetup = handSetup
val handHistory = HandHistory() val handHistory = HandHistory()
handHistory.configure(handSetup) handHistory.configure(handSetup)
this.playerHandMaxCards = handSetup.game?.playerHandMaxCards this.playerHandMaxCards = handSetup.game?.playerHandMaxCards
this.loadHandHistory(realm.copyToRealm(handHistory))
this.loadHandHistory(handHistory)
} }
/*** /***
@ -586,6 +584,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
/***
* 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,
* and a row for a new player if necessary
*/
private fun playerSetups(): List<PlayerSetupRowRepresentable> { private fun playerSetups(): List<PlayerSetupRowRepresentable> {
val hh = this.handHistory val hh = this.handHistory
@ -608,4 +611,32 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
/***
* Sets the both [positionIndex] and position for a PlayerSetup inside a [psRowRepresentable]
*/
fun setPlayerSetupPosition(psRowRepresentable: PlayerSetupRowRepresentable, positionIndex: Int) {
var setupCreated = false
psRowRepresentable.playerSetup?.let {
it.position = positionIndex
} ?: run {
psRowRepresentable.playerSetup = this.handHistory.createPlayerSetup(positionIndex)
setupCreated = true
}
val position = this.sortedActions.positions.elementAt(positionIndex)
psRowRepresentable.position = position
if (!psRowRepresentable.hero && setupCreated) {
if (this.handHistory.undefinedPositions().isNotEmpty()) {
val newPlayerRow = PlayerSetupRowRepresentable(false, null)
val index = this.indexOfRowRepresentable(psRowRepresentable)
this.rowsLiveData.value?.add(index + 1, newPlayerRow)
}
}
}
} }

@ -2,45 +2,81 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import android.content.Context import android.content.Context
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType 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) : class PlayerSetupRowRepresentable(var hero: Boolean = false, var playerSetup: PlayerSetup? = null) :
RowRepresentable { HandHistoryRow {
var positionEdited: Boolean = false
var position: Position? = null var position: Position? = null
enum class State { enum class State {
POSITION_ONLY, POSITIONS_ONLY,
SHOW_POSITION, SETUP_ONLY,
DEFAULT, BOTH,
} }
val state: State enum class Tag {
get() { POSITION,
return when { CARDS,
this.positionEdited -> State.SHOW_POSITION STACK
(this.playerSetup == null) -> State.POSITION_ONLY
else -> State.DEFAULT
}
} }
var state: State = State.POSITIONS_ONLY
fun title(context: Context): String { fun title(context: Context): String {
return if (this.hero) { return if (this.hero) {
context.getString(R.string.hero) context.getString(R.string.hero)
} else { } else {
this.playerSetup?.player?.name?.let { this.playerSetup?.let { setup ->
setup.player?.name?.let {
it it
} ?: run { } ?: run {
context.getString(R.string.vilain) this.position?.value
}
} ?: run {
context.getString(R.string.add_vilain)
} }
} }
} }
fun showPosition() {
this.state = State.BOTH
}
fun closePosition() {
this.state = State.SETUP_ONLY
}
override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal
override fun tagForCompletion(handHistory: HandHistory): Int? {
this.playerSetup?.let {
if (it.cards.isEmpty()) {
return Tag.CARDS.ordinal
} else if (it.stack == null) {
return Tag.STACK.ordinal
}
}
return null
}
override fun keyboardForTag(tag: Int): HHKeyboard {
return when (tag) {
Tag.CARDS.ordinal -> HHKeyboard.CARD
Tag.STACK.ordinal -> HHKeyboard.AMOUNT
else -> throw PAIllegalStateException("unmanaged tag: $tag")
}
}
override fun amountForTag(handHistory: HandHistory, tag: Int): Double? {
return when (tag) {
Tag.STACK.ordinal -> this.playerSetup?.stack
else -> throw PAIllegalStateException("unmanaged tag: $tag")
}
}
} }

@ -8,7 +8,6 @@ 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.Card import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard 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.HandHistoryRow
@ -175,13 +174,13 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo
} }
class PlayerCardsRow(var position: Position, var handHistory: HandHistory, cardHolder: CardHolder?, var maxCards: Int? = null) : CardsRow(cardHolder) { class PlayerCardsRow(var position: Position, var positionIndex: Int, var handHistory: HandHistory, cardHolder: CardHolder?, var maxCards: Int? = null) : CardsRow(cardHolder) {
companion object { companion object {
fun newInstance(position: Position, handHistory: HandHistory, positionIndex: Int, maxCards: Int? = null): PlayerCardsRow { fun newInstance(position: Position, handHistory: HandHistory, positionIndex: Int, maxCards: Int? = null): PlayerCardsRow {
val playerSetup = handHistory.playerSetupForPosition(positionIndex) val playerSetup = handHistory.playerSetupForPosition(positionIndex)
return PlayerCardsRow(position, handHistory, playerSetup, maxCards) return PlayerCardsRow(position, positionIndex, handHistory, playerSetup, maxCards)
} }
} }
@ -189,10 +188,7 @@ class PlayerCardsRow(var position: Position, var handHistory: HandHistory, cardH
override val viewType: Int = HandRowType.PLAYER_SUMMARY.ordinal override val viewType: Int = HandRowType.PLAYER_SUMMARY.ordinal
override fun createHolder(): CardHolder { override fun createHolder(): CardHolder {
val playerSetup = PlayerSetup() return this.handHistory.createPlayerSetup(this.positionIndex)
realmInstance.copyToRealm(playerSetup)
this.handHistory.playerSetups.add(playerSetup)
return playerSetup
} }
override fun cardLimit() : Int? { override fun cardLimit() : Int? {

@ -2,13 +2,14 @@
<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"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title" android:id="@+id/title"
style="@style/PokerAnalyticsTheme.TextView.RowTitle" style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp" /> android:layout_marginStart="8dp" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -44,6 +45,7 @@
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:inputType="none"
android:maxLines="1" /> android:maxLines="1" />
<androidx.appcompat.widget.AppCompatEditText <androidx.appcompat.widget.AppCompatEditText
@ -54,6 +56,7 @@
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end" android:gravity="end"
android:inputType="none"
android:maxLines="1" /> android:maxLines="1" />
</LinearLayout> </LinearLayout>

@ -792,6 +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> <string name="add_vilain">vilain</string>
</resources> </resources>

Loading…
Cancel
Save