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

@ -60,7 +60,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
/*** /***
* Number of players in the hand * Number of players in the hand
*/ */
var numberOfPlayers: Int = 10 var numberOfPlayers: Int = 4
/*** /***
* Number of players in the hand * Number of players in the hand
@ -95,26 +95,24 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
fun configure(handSetup: HandSetup) { 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.tableSize?.let { this.numberOfPlayers = it }
handSetup.smallBlind?.let { this.smallBlind = it } handSetup.smallBlind?.let { this.smallBlind = it }
handSetup.bigBlind?.let { this.bigBlind = 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(0, Action.Type.POST_SB, this.smallBlind)
this.addAction(1, Action.Type.POST_BB, this.bigBlind) this.addAction(1, Action.Type.POST_BB, this.bigBlind)
val positions = Position.positionsPerPlayers(this.numberOfPlayers) val positions = Position.positionsPerPlayers(this.numberOfPlayers)
var lastStraddler: Int? = null var lastStraddler: Int? = null
handSetup.straddlePositions.forEach { position -> // position are sorted here straddlePositions.forEach { position -> // position are sorted here
val positionIndex = positions.indexOf(position) val positionIndex = positions.indexOf(position)
this.addAction(positionIndex, Action.Type.STRADDLE) this.addAction(positionIndex, Action.Type.STRADDLE)
lastStraddler = positionIndex lastStraddler = positionIndex

@ -33,7 +33,9 @@ class BottomSheetConfig(var row: RowRepresentable,
var isClearable: Boolean? = true, var isClearable: Boolean? = true,
var currentCurrency: Currency? = null, var currentCurrency: Currency? = null,
var isDeletable: Boolean? = false, 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, isClearable: Boolean? = true,
currentCurrency: Currency? = null, currentCurrency: Currency? = null,
isDeletable: Boolean? = false, isDeletable: Boolean? = false,
valueHasPlaceholder: Boolean? = null valueHasPlaceholder: Boolean? = null,
alternativeLabels: Boolean = false
): BottomSheetFragment { ): BottomSheetFragment {
val bottomSheetFragment = newInstance(row.bottomSheetType) val bottomSheetFragment = newInstance(row.bottomSheetType)
bottomSheetFragment.show(fragmentManager, "bottomSheet") 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 return bottomSheetFragment
} }
@ -114,6 +117,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
this.viewModel.currentCurrency = configuration.currentCurrency this.viewModel.currentCurrency = configuration.currentCurrency
this.viewModel.isDeletable = configuration.isDeletable ?: false this.viewModel.isDeletable = configuration.isDeletable ?: false
this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false
this.viewModel.alternativeLabels = configuration.alternativeLabels
} }

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

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

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

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

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

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

Loading…
Cancel
Save