Enables number of player selection

hh
Laurent 6 years ago
parent 313b27e16a
commit 64d593df41
  1. 18
      app/src/main/java/net/pokeranalytics/android/model/TableSize.kt
  2. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  3. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  4. 24
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  7. 25
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  8. 0
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt
  10. 1
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/BottomSheetViewModel.kt

@ -6,14 +6,14 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.Parser
class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal) : RowRepresentable {
class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal, var alternativeLabels: Boolean = true) : RowRepresentable {
companion object {
val all: List<TableSize>
get() {
return Array(9, init =
{ index -> TableSize(index + 2) }).toList()
fun all(alternativeLabels: Boolean): List<TableSize> {
return Array(9, init = { index ->
TableSize(index + 2, alternativeLabels = alternativeLabels)
}).toList()
}
fun valueForLabel(label: String) : Int? {
@ -32,6 +32,10 @@ class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITL
}
override fun getDisplayName(context: Context): String {
if (this.alternativeLabels) {
return this.numberOfPlayer.toString()
}
return if (this.numberOfPlayer == 2) {
return "HU"
} else {
@ -49,6 +53,10 @@ class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITL
}
override fun localizedTitle(context: Context): String {
if (this.alternativeLabels) {
return this.numberOfPlayer.toString()
}
this.resId?.let {
return if (this.numberOfPlayer == 2) {
context.getString(it)

@ -60,7 +60,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
/***
* Number of players in the hand
*/
var numberOfPlayers: Int = 10
var numberOfPlayers: Int = 4
/***
* Number of players in the hand
@ -95,26 +95,24 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
fun configure(handSetup: HandSetup) {
// this.board.addAll(listOf(Card.valueOf(2, Card.Suit.SPADES),
// Card.valueOf(14, Card.Suit.HEART),
// Card.valueOf(5, Card.Suit.CLOVER),
// Card.valueOf(10, Card.Suit.DIAMOND),
// Card.valueOf(12, Card.Suit.SPADES)))
this.actions.clear()
handSetup.tableSize?.let { this.numberOfPlayers = it }
handSetup.smallBlind?.let { this.smallBlind = it }
handSetup.bigBlind?.let { this.bigBlind = it }
this.createActions(handSetup.straddlePositions)
}
private fun createActions(straddlePositions: List<Position>) {
this.actions.clear()
this.addAction(0, Action.Type.POST_SB, this.smallBlind)
this.addAction(1, Action.Type.POST_BB, this.bigBlind)
val positions = Position.positionsPerPlayers(this.numberOfPlayers)
var lastStraddler: Int? = null
handSetup.straddlePositions.forEach { position -> // position are sorted here
straddlePositions.forEach { position -> // position are sorted here
val positionIndex = positions.indexOf(position)
this.addAction(positionIndex, Action.Type.STRADDLE)
lastStraddler = positionIndex

@ -33,7 +33,9 @@ class BottomSheetConfig(var row: RowRepresentable,
var isClearable: Boolean? = true,
var currentCurrency: Currency? = null,
var isDeletable: Boolean? = false,
var valueHasPlaceholder: Boolean? = null) {
var valueHasPlaceholder: Boolean? = null,
var alternativeLabels: Boolean = false
) {
}
@ -60,11 +62,12 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
isClearable: Boolean? = true,
currentCurrency: Currency? = null,
isDeletable: Boolean? = false,
valueHasPlaceholder: Boolean? = null
valueHasPlaceholder: Boolean? = null,
alternativeLabels: Boolean = false
): BottomSheetFragment {
val bottomSheetFragment = newInstance(row.bottomSheetType)
bottomSheetFragment.show(fragmentManager, "bottomSheet")
this.config = BottomSheetConfig(row, delegate, rowRepresentableEditDescriptors, isClearable, currentCurrency, isDeletable, valueHasPlaceholder)
this.config = BottomSheetConfig(row, delegate, rowRepresentableEditDescriptors, isClearable, currentCurrency, isDeletable, valueHasPlaceholder, alternativeLabels)
return bottomSheetFragment
}
@ -114,6 +117,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
this.viewModel.currentCurrency = configuration.currentCurrency
this.viewModel.isDeletable = configuration.isDeletable ?: false
this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false
this.viewModel.alternativeLabels = configuration.alternativeLabels
}

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -55,7 +54,7 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese
}
override fun adapterRows(): List<RowRepresentable>? {
return TableSize.all
return TableSize.all(this.viewModel.alternativeLabels)
}
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
@ -64,15 +63,16 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese
dismiss()
}
override fun stringForRow(
row: RowRepresentable,
context: Context,
tag: Int
): String {
this.context?.let {
return row.localizedTitle(it)
}
return "UNKNOWN CONTEXT FOR ROW $row"
}
// override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String {
//
// if (this.viewModel.alternativeLabels) {
// return (row as TableSize).numberOfPlayer.toString()
// }
//
// this.context?.let {
// return row.localizedTitle(it)
// }
// return "UNKNOWN CONTEXT FOR ROW $row"
// }
}

@ -38,6 +38,7 @@ import timber.log.Timber
enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow {
DEFAULT(R.layout.row_title_value),
HEADER(R.layout.row_header_value),
ACTION(R.layout.row_hand_action),
PLAYER_SUMMARY(R.layout.row_hand_player_summary),
@ -45,6 +46,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
BLINDS(R.layout.row_hhsettings_blinds),
STRADDLE(R.layout.row_hhsettings_straddle),
COMMENT(R.layout.row_hhsettings_comments),
PLAYER_NUMBER(R.layout.row_title_value),
PLAYER_SETUP(R.layout.row_hhsettings_player_setup)
;
@ -89,6 +91,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
override val bottomSheetType: BottomSheetType
get() {
return when(this) {
PLAYER_NUMBER -> BottomSheetType.GRID
COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES
else -> BottomSheetType.NONE
}
@ -97,6 +100,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
override val resId: Int?
get() {
return when(this) {
PLAYER_NUMBER -> R.string.number_of_players
COMMENT -> R.string.comment
else -> null
}
@ -129,6 +133,7 @@ class HandHistoryAdapter(
val rowType: HandRowType = HandRowType.values()[viewType]
val layout = LayoutInflater.from(parent.context).inflate(rowType.layoutRes, parent, false)
return when (rowType) {
HandRowType.DEFAULT -> RowViewHolder(layout)
HandRowType.HEADER -> RowViewHolder(layout)
HandRowType.ACTION -> RowHandAction(layout)
HandRowType.STREET -> RowHandStreet(layout)
@ -137,6 +142,7 @@ class HandHistoryAdapter(
HandRowType.STRADDLE -> RowHandStraddle(layout)
HandRowType.PLAYER_SETUP -> RowHandPlayerSetup(layout)
HandRowType.COMMENT -> RowViewHolder(layout)
HandRowType.PLAYER_NUMBER -> RowViewHolder(layout)
}
}

@ -224,7 +224,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
BottomSheetType.NONE -> {}
else -> {
val editDescriptors = listOf(RowRepresentableEditDescriptor(this.model.handHistory.comment, R.string.comment))
BottomSheetFragment.create(this.fragmentManager, row, this, editDescriptors)
BottomSheetFragment.create(this.fragmentManager, row, this, editDescriptors, alternativeLabels = true)
return
}
}
@ -250,6 +250,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.handHistory.comment = value as? String
refreshCells(this.model.indexOfRowRepresentable(row))
}
HandRowType.PLAYER_NUMBER -> {
this.model.setNumberOfPlayers(value as Int)
this.handHistoryAdapter.notifyDataSetChanged()
}
is ComputedAction -> {
this.model.currentAmount = value as String
}

@ -39,7 +39,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
private set
/***
*
* The hand setup
*/
private var handSetup: HandSetup = HandSetup()
/***
* Indicats whether the HH is new or not
*/
private var isNew: Boolean = true
@ -102,11 +107,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
*/
private var firstStraddlePosition: Position? = null
/***
* The hand setup
*/
private var handSetup: HandSetup = HandSetup()
/***
* The board cards sorted by position
*/
@ -161,7 +161,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Pre-computes the potsizes for the video export
*/
private fun load() {
this.setNumberOfPlayers(handHistory.numberOfPlayers)
this.sortedActions.positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers)
this.sortedActions.load(this.handHistory)
this.createRowRepresentation()
}
@ -174,9 +174,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
rows.add(HandRowType.COMMENT)
rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = ""))
rows.add(HandRowType.PLAYER_NUMBER)
rows.add(HandRowType.BLINDS)
if (this.isNew) { // don't allow any straddle changes if not new
@ -243,9 +243,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Sets the number of players playing the hand
* Defines the appropriate positions for this player count
*/
private fun setNumberOfPlayers(playerCount: Int) {
fun setNumberOfPlayers(playerCount: Int) {
if (playerCount != this.handHistory.numberOfPlayers) {
this.handHistory.numberOfPlayers = playerCount
this.sortedActions.positions = Position.positionsPerPlayers(playerCount)
this.handHistory.configure(this.handSetup)
load()
}
}
/***
@ -437,7 +440,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
// Card Centralizer
/***
@ -536,6 +538,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String {
return when (row) {
HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString()
HandRowType.COMMENT -> this.handHistory.comment ?: context.getString(R.string.comment)
HandRowType.BLINDS -> {
when (tag) {

@ -105,7 +105,7 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
// Title
itemView.findViewById<AppCompatTextView?>(R.id.title)?.let {
val title = row.resId?.let { resId ->
itemView.context.getString(resId)
row.localizedTitle(itemView.context)
} ?: run {
row.getDisplayName(itemView.context)
}

@ -58,6 +58,7 @@ class BottomSheetViewModel : ViewModel() {
* Table Size
*/
var defaultSize: Int? = null
var alternativeLabels: Boolean = false
/**
* Multiselection

Loading…
Cancel
Save