More HH progress

hh
Laurent 6 years ago
parent d743cda1f0
commit 9ba73dc7c1
  1. 6
      app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt
  2. 21
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  3. 8
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  5. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  6. 21
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  7. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt
  8. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/StreetCardView.kt
  9. 66
      app/src/main/res/layout/row_header_value.xml

@ -38,6 +38,12 @@ class BoardManager(cards: List<Card>, var listener: BoardChangedListener) {
*/ */
fun add(card: Card) { fun add(card: Card) {
this.sortedBoardCards.lastOrNull()?.let {
if (it.suit == null) {
it.suit = Card.Suit.UNDEFINED
}
}
if (this.sortedBoardCards.size == 5) { if (this.sortedBoardCards.size == 5) {
throw PAIllegalStateException("Can't add anymore cards") throw PAIllegalStateException("Can't add anymore cards")
} }

@ -10,6 +10,7 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.util.extensions.formatted
import timber.log.Timber import timber.log.Timber
import kotlin.math.max import kotlin.math.max
@ -546,16 +547,12 @@ class HHBuilder : BoardChangedListener {
fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHSelection? { fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHSelection? {
this.rowRepresentables.forEachIndexed { index, rowRepresentable -> this.rowRepresentables.forEachIndexed { index, rowRepresentable ->
if (index >= startIndex && rowRepresentable is HandHistoryRow) { if (index >= startIndex && rowRepresentable is HandHistoryRow) {
// Timber.d("Check keyboard for index = $index")
val foundKeyboard = rowRepresentable.keyboardForCompletion() val foundKeyboard = rowRepresentable.keyboardForCompletion()
if (foundKeyboard != null && !(index == startIndex && keyboard == foundKeyboard)) { if (foundKeyboard != null) {
return HHSelection(index, foundKeyboard) return HHSelection(index, foundKeyboard)
} }
// rowRepresentable.keyboardForCompletion()?.let { keyboard ->
// return HHSelection(index, keyboard)
// }
} }
} }
return null return null
@ -701,7 +698,6 @@ class HHBuilder : BoardChangedListener {
} }
} }
} }
this.rowRepresentables = rows this.rowRepresentables = rows
@ -743,8 +739,11 @@ class HHBuilder : BoardChangedListener {
} }
val allCheck = this.sortedActions.filter { it.action.street == currentStreet }.all { it.action.type == Action.Type.CHECK } val allPassive = this.sortedActions
if (allCheck) { .filter { it.action.street == currentStreet }
.all { it.action.type?.isPassive ?: false }
if (allPassive) {
return if (currentStreet != Street.RIVER) { return if (currentStreet != Street.RIVER) {
currentStreet.next currentStreet.next
} else { } else {
@ -759,11 +758,11 @@ class HHBuilder : BoardChangedListener {
* Adds a [street] header to a [rowRepresentables] list with a given [potSize] * Adds a [street] header to a [rowRepresentables] list with a given [potSize]
*/ */
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) { private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) {
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId) val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potSize.formatted())
rowRepresentables.add(headerView) rowRepresentables.add(headerView)
if (street.totalBoardCards > 0) { if (street.totalBoardCards > 0) {
val boardView = StreetCardView(street, this.handHistory.cardsForStreet(street), potSize) val boardView = StreetCardView(street, this.handHistory.cardsForStreet(street))
rowRepresentables.add(boardView) rowRepresentables.add(boardView)
} }

@ -45,6 +45,14 @@ open class Action : RealmObject() {
} }
} }
val isPassive: Boolean
get() {
return when (this) {
FOLD, CHECK -> true
else -> false
}
}
val requiresOpponentDecision: Boolean val requiresOpponentDecision: Boolean
get() { get() {
return when(this) { return when(this) {

@ -75,6 +75,7 @@ open class Card : RealmObject() {
} }
enum class Suit(val value: String) : CardProperty, RowRepresentable { enum class Suit(val value: String) : CardProperty, RowRepresentable {
UNDEFINED("x"),
SPADES(""), SPADES(""),
HEART(""), HEART(""),
DIAMOND(""), DIAMOND(""),
@ -82,7 +83,7 @@ open class Card : RealmObject() {
companion object { companion object {
fun format(suit: Suit?) : String { fun format(suit: Suit?) : String {
return suit?.value ?: "x" return suit?.value ?: ""
} }
fun color(suit: Suit?) : Int { fun color(suit: Suit?) : Int {
return suit?.color ?: R.color.white return suit?.color ?: R.color.white
@ -92,6 +93,7 @@ open class Card : RealmObject() {
val color: Int val color: Int
get() { get() {
return when (this) { return when (this) {
UNDEFINED -> R.color.white
SPADES -> R.color.white_dark SPADES -> R.color.white_dark
HEART -> R.color.red HEART -> R.color.red
DIAMOND -> R.color.diamond DIAMOND -> R.color.diamond

@ -31,7 +31,7 @@ import timber.log.Timber
enum class HandRowType(var layoutRes: Int) : ViewIdentifier { enum class HandRowType(var layoutRes: Int) : ViewIdentifier {
HEADER(R.layout.row_header_title), HEADER(R.layout.row_header_value),
ACTION(R.layout.row_hand_action), ACTION(R.layout.row_hand_action),
PLAYER_SUMMARY(R.layout.row_hand_player_summary), PLAYER_SUMMARY(R.layout.row_hand_player_summary),
STREET(R.layout.row_hand_cards); STREET(R.layout.row_hand_cards);

@ -157,14 +157,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.isEdited = false this.model.isEdited = false
} }
private fun findNextActionToEdit() { // private fun findNextActionToEdit() {
val selection = this.model.selectionLiveData.value // val selection = this.model.selectionLiveData.value
val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection") // val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection")
this.findNextActionToEdit(index, selection.keyboard) // this.findNextActionToEdit(index, selection.keyboard)
} // }
private fun findNextActionToEdit(startIndex: Int, keyboard: HHKeyboard? = null) { private fun findNextActionToEdit(index: Int? = null) {
this.model.findIndexForEdition(startIndex, keyboard)?.let { val startIndex = index ?: this.model.currentSelection.index
this.model.findIndexForEdition(startIndex)?.let {
this.keyboard.show(it) this.keyboard.show(it)
} ?: run { } ?: run {
this.keyboard.hide() this.keyboard.hide()
@ -241,7 +242,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
// TODO add test about number of cards before selecting next action? // TODO add test about number of cards before selecting next action?
// this.findNextActionToEdit() this.findNextActionToEdit()
} }
override fun cardSuitSelected(suit: Card.Suit) { override fun cardSuitSelected(suit: Card.Suit) {
@ -249,7 +250,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
// TODO add test about number of cards? // TODO add test about number of cards?
// this.findNextActionToEdit() this.findNextActionToEdit()
} }
override fun clearCards() { override fun clearCards() {

@ -82,9 +82,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
this.builder.deleteLastCardProperty(this.currentSelection) this.builder.deleteLastCardProperty(this.currentSelection)
} }
fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHKeyboard? { fun findIndexForEdition(index: Int): HHKeyboard? {
this.selectionLiveData.value = this.builder.findIndexForEdition(startIndex, keyboard) val selection = this.builder.findIndexForEdition(index, this.selectionLiveData.value?.keyboard)
return selectionLiveData.value?.keyboard this.selectionLiveData.value = selection
return selection?.keyboard
} }
fun amountChanged(amount: String?) { fun amountChanged(amount: String?) {

@ -6,12 +6,14 @@ 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.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
class StreetCardView(var street: Street, var cards: List<Card>, var potSize: Double) : HandHistoryRow { class StreetCardView(var street: Street, var cards: List<Card>) : HandHistoryRow {
override val viewType: Int = HandRowType.STREET.ordinal override val viewType: Int = HandRowType.STREET.ordinal
override fun keyboardForCompletion(): HHKeyboard? { override fun keyboardForCompletion(): HHKeyboard? {
return if (cards.size != street.totalBoardCards) { return if (cards.size < street.totalBoardCards) {
HHKeyboard.CARD
} else if (cards.last().suit == null) {
HHKeyboard.CARD HHKeyboard.CARD
} else { } else {
null null

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rowHeaderTitleValue.container"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green_header">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
style="@style/PokerAnalyticsTheme.TextView.Header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guidelineStart"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/guidelineEnd"
app:layout_constraintStart_toEndOf="@+id/title"
app:layout_constraintTop_toTopOf="parent"
tools:text="Value" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:id="@+id/rowHeaderTitleValue.separator"
android:layout_width="match_parent"
android:layout_height="16dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
</androidx.appcompat.widget.LinearLayoutCompat>
Loading…
Cancel
Save