Adds HH settings initial stuff

hh
Laurent 6 years ago
parent 2a78b7e386
commit 08012fc88e
  1. 70
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistorySettings.kt
  4. 126
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  5. 46
      app/src/main/res/layout/row_hhsettings_blinds.xml
  6. 41
      app/src/main/res/layout/row_hhsettings_player_setup.xml
  7. 71
      app/src/main/res/layout/row_hhsettings_straddle.xml
  8. 1
      app/src/main/res/values/strings.xml
  9. 7
      app/src/main/res/values/styles.xml

@ -10,6 +10,9 @@ import android.widget.Button
import android.widget.EditText
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
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_straddle.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
@ -32,7 +35,12 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier {
HEADER(R.layout.row_header_value),
ACTION(R.layout.row_hand_action),
PLAYER_SUMMARY(R.layout.row_hand_player_summary),
STREET(R.layout.row_hand_cards);
STREET(R.layout.row_hand_cards),
BLINDS(R.layout.row_hhsettings_blinds),
STRADDLE(R.layout.row_hhsettings_straddle),
// COMMENT(R.layout.row_hhsettings_comment),
PLAYER_SETUP(R.layout.row_hhsettings_player_setup)
;
override val identifier: Int
get() { return this.ordinal }
@ -56,6 +64,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)
}
}
@ -350,4 +361,61 @@ class HandHistoryAdapter(
}
}
inner class RowHandBlinds(itemView: View) : RowHandHolder(itemView) {
// sb, bb, ante, bb ante
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
itemView.smallBlindEditText.setText(adapter.dataSource.stringForRow(row))
itemView.bigBlindEditText.setText(adapter.dataSource.stringForRow(row))
itemView.anteEditText.setText(adapter.dataSource.stringForRow(row))
itemView.bbAnteSwitch.isChecked = adapter.dataSource.isSelected(position, row, 0)
}
}
inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
// itemView.typeChipGroup.clearCheck()
itemView.typeChipGroup.setOnCheckedChangeListener { chipGroup, i ->
}
val hadStraddle = adapter.dataSource.isSelectable(row)
val countVisibility = if (hadStraddle) View.VISIBLE else View.GONE
itemView.countTextView.visibility = countVisibility
itemView.minusButton.visibility = countVisibility
itemView.plusButton.visibility = countVisibility
itemView.countTextView.text = adapter.dataSource.stringForRow(row)
}
// type: none, std, mississipi
// number
}
inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
// itemView.positionsChipGroup
itemView.handEditText.setText(adapter.dataSource.stringForRow(row))
itemView.stackEditText.setText(adapter.dataSource.stringForRow(row))
}
// position, stack, hand
}
}

@ -53,7 +53,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
model = activity?.run {
this.model = activity?.run {
ViewModelProviders.of(this)[HandHistoryViewModel::class.java]
} ?: throw Exception("Invalid Activity")
@ -237,7 +237,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.currentAmount = value as String
}
// Keyboard Listener
override fun actionSelected(action: Action.Type) {

@ -0,0 +1,12 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.ui.view.RowRepresentable
enum class HandHistorySettings : RowRepresentable {
BASE,
STRADDLE,
COMMENT,
PLAYER_SETUP;
}

@ -126,6 +126,71 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
this.createRowRepresentation()
}
/***
* Uses the action list to create the list of RowRepresentables, displayed to the user
*/
private fun createRowRepresentation() {
val rows: MutableList<RowRepresentable> = mutableListOf()
rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = ""))
Street.values().forEach { street ->
val actions = this.sortedActions.filter { it.street == street }
when (street) {
Street.SUMMARY -> {
val lastActionIndex = this.sortedActions.size - 1
if (this.sortedActions.activePositions(lastActionIndex).size < 2 || this.sortedActions.isStreetActionClosed(lastActionIndex) == Street.SUMMARY) {
addStreetHeader(rows, street)
val positions = this.sortedActions.activePositions(lastActionIndex, true)
positions.forEach {
val positionIndex = this.sortedActions.positions.indexOf(it)
val playerCardsRow = PlayerCardsRow(it, this.handHistory.playerSetupForPosition(positionIndex), this.playerHandMaxCards)
rows.add(playerCardsRow)
}
}
}
else -> {
if (actions.isNotEmpty()) {
addStreetHeader(rows, street)
rows.addAll(actions)
}
}
}
}
this.rowsLiveData.value = rows
}
/***
* Adds a [street] header to a [rowRepresentables]
*/
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street) {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size
val potSize = this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount }
val potString = if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potString)
rowRepresentables.add(headerView)
if (street.totalBoardCards > 0) {
// create new StreetCardsRow
val boardView = StreetCardsRow(street, this.handHistory)
rowRepresentables.add(boardView)
}
}
/***
* Sets the number of players playing the hand
* Defines the appropriate positions for this player count
@ -150,7 +215,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
/***
* Returns a list of positions that needs to act [index]
* Returns a list of positions that needs to act
*/
fun positionsToAct(): List<Position> {
return this.sortedActions.positionsToActAfterIndex(this.actionIndexForSelection)
@ -305,65 +370,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
/***
* Uses the action list to create the list of RowRepresentables, displayed to the user
*/
private fun createRowRepresentation() {
val rows: MutableList<RowRepresentable> = mutableListOf()
rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = ""))
Street.values().forEach { street ->
val actions = this.sortedActions.filter { it.street == street }
when (street) {
Street.SUMMARY -> {
val lastActionIndex = this.sortedActions.size - 1
if (this.sortedActions.activePositions(lastActionIndex).size < 2 || this.sortedActions.isStreetActionClosed(lastActionIndex) == Street.SUMMARY) {
addStreetHeader(rows, street)
val positions = this.sortedActions.activePositions(lastActionIndex, true)
positions.forEach {
val positionIndex = this.sortedActions.positions.indexOf(it)
val playerCardsRow = PlayerCardsRow(it, this.handHistory.playerSetupForPosition(positionIndex), this.playerHandMaxCards)
rows.add(playerCardsRow)
}
}
}
else -> {
if (actions.isNotEmpty()) {
addStreetHeader(rows, street)
rows.addAll(actions)
}
}
}
}
this.rowsLiveData.value = rows
}
/***
* Adds a [street] header to a [rowRepresentables]
*/
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street) {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size
val potSize = this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount }
val potString = if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potString)
rowRepresentables.add(headerView)
if (street.totalBoardCards > 0) {
// create new StreetCardsRow
val boardView = StreetCardsRow(street, this.handHistory)
rowRepresentables.add(boardView)
}
}
// Card Centralizer

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/smallBlindEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:layout_width="0dp"
android:hint="@string/smallblind"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/bigBlindEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:layout_width="0dp"
android:hint="@string/bigblind"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/anteEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:layout_width="0dp"
android:hint="@string/ante"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/bbAnteSwitch"
android:layout_width="0dp"
android:hint="@string/ante"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1" />
</LinearLayout>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/positionsChipGroup"
android:layout_width="match_parent"
android:layout_height="44dp"
app:chipSpacing="8dp"
app:singleSelection="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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:maxLines="1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/stackEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:hint="@string/stack"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="end"
android:maxLines="1" />
</LinearLayout>
</LinearLayout>

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/typeChipGroup"
android:layout_width="match_parent"
android:layout_height="44dp"
app:chipSpacing="8dp"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="@+id/noneChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/none" />
<com.google.android.material.chip.Chip
android:id="@+id/standardChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/standard" />
<com.google.android.material.chip.Chip
android:id="@+id/mississipiChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mississipi" />
</com.google.android.material.chip.ChipGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginEnd="80dp"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/minusButton"
android:text="-"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/PokerAnalyticsTheme.SingleCharacterButton"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/countTextView"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guidelineStart"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/plusButton"
android:text="+"
style="@style/PokerAnalyticsTheme.SingleCharacterButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

@ -791,5 +791,6 @@
<string name="callin">c_allin</string>
<string name="rallin">r_allin</string>
<string name="backspace"></string>
<string name="mississipi">mississipi</string>
</resources>

@ -344,7 +344,6 @@
<style name="PokerAnalyticsTheme.HHButton" parent="Widget.MaterialComponents.Button">
<item name="iconPadding">0dp</item>
<item name="android:height">48dp</item>
<!-- <item name="iconTint">@color/white</item>-->
<item name="android:letterSpacing">0</item>
<item name="android:fontFamily">@font/roboto_medium</item>
<item name="android:textColor">@color/white</item>
@ -354,6 +353,12 @@
<item name="backgroundTint">@color/kaki</item>
</style>
<style name="PokerAnalyticsTheme.SingleCharacterButton">
<item name="android:fontFamily">@font/roboto_medium</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">36sp</item>
</style>
<style name="PokerAnalyticsTheme.CardButton" parent="Widget.MaterialComponents.Button">
</style>

Loading…
Cancel
Save