Adds documentation

hh
Laurent 6 years ago
parent f775b60f88
commit d743cda1f0
  1. 25
      app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt

@ -3,14 +3,27 @@ package net.pokeranalytics.android.model.handhistory
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.handhistory.Card
/***
* An interface used for board changes notifications
*/
interface BoardChangedListener {
fun boardChanged()
}
/***
* The BoardManager purpose is to manage the cards from a hand history board
* and notify its listener when a change occurs
*/
class BoardManager(cards: List<Card>, var listener: BoardChangedListener) {
/***
* The sorted list of cards
*/
private var sortedBoardCards: MutableList<Card> = mutableListOf()
/***
* All cards
*/
val allCards: List<Card>
get() {
return this.sortedBoardCards
@ -20,6 +33,9 @@ class BoardManager(cards: List<Card>, var listener: BoardChangedListener) {
this.sortedBoardCards = cards.sortedBy { it.index }.toMutableList()
}
/***
* Adds a card to the board, notifies the listener
*/
fun add(card: Card) {
if (this.sortedBoardCards.size == 5) {
@ -32,15 +48,24 @@ class BoardManager(cards: List<Card>, var listener: BoardChangedListener) {
this.listener.boardChanged()
}
/***
* Clears the street's cards, notifies the listener
*/
fun clearStreet(street: Street) {
this.sortedBoardCards.removeAll { it.street == street }
this.listener.boardChanged()
}
/***
* Returns the last card of a given [street]
*/
fun lastCard(street: Street) : Card? {
return this.sortedBoardCards.lastOrNull { it.street == street }
}
/***
* Remove the given [card], notifies the listener
*/
fun remove(card: Card) {
this.sortedBoardCards.remove(card)
this.listener.boardChanged()

@ -17,7 +17,6 @@ enum class HHKeyboard {
ACTION,
AMOUNT,
CARD;
}
class HHSelection(var index: Int, var keyboard: HHKeyboard)
@ -43,13 +42,15 @@ class HHBuilder : BoardChangedListener {
* The board cards sorted by position
*/
private lateinit var boardManager: BoardManager
// private var sortedBoardCards: MutableList<Card> = mutableListOf()
/***
* A LinkedHashSet containing the sorted positions at the table
*/
var positions: LinkedHashSet<Position> = linkedSetOf()
/***
* Creates a builder using a [handSetup]
* Creates a new Hand History and configures it according to the [handSetup]
* Also creates a new Hand History and configures it according to the [handSetup]
*/
constructor(handSetup: HandSetup) {
val handHistory = HandHistory()
@ -69,7 +70,6 @@ class HHBuilder : BoardChangedListener {
*/
private fun actionForIndex(index: Int) : ComputedAction {
return this.sortedActions[index]
// return this.sortedActions.first { it.action.index == index }
}
/***
@ -705,9 +705,13 @@ class HHBuilder : BoardChangedListener {
}
this.rowRepresentables = rows
// return rows
}
/***
* This function evaluates whether the street, identified by an action [index],
* has its action closed, meaning no more player are required to play.
* In case of closing, the function returns the next logical Street
*/
private fun isStreetActionClosed(index: Int) : Street? {
val currentStreet = this.actionForIndex(index).action.street
@ -751,6 +755,9 @@ class HHBuilder : BoardChangedListener {
return null
}
/***
* Adds a [street] header to a [rowRepresentables] list with a given [potSize]
*/
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street, potSize: Double) {
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId)
rowRepresentables.add(headerView)

Loading…
Cancel
Save