Adds method documentation

hh
Laurent 6 years ago
parent d66a706c07
commit 44d1c5fa03
  1. 35
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/DataSelectionDialogFragment.kt
  3. 11
      app/src/main/res/drawable/circle.xml
  4. 6
      app/src/main/res/layout/fragment_data_selection_dialog.xml

@ -116,6 +116,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
override var year: Int? = null override var year: Int? = null
override var dayOfMonth: Int? = null override var dayOfMonth: Int? = null
/***
* Configures a hand history with a [handSetup]
*/
fun configure(handSetup: HandSetup) { fun configure(handSetup: HandSetup) {
handSetup.tableSize?.let { this.numberOfPlayers = it } handSetup.tableSize?.let { this.numberOfPlayers = it }
@ -125,6 +128,10 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
this.createActions(handSetup.straddlePositions) this.createActions(handSetup.straddlePositions)
} }
/***
* Creates the initial actions of the hand history using the number of players,
* and the optional [straddlePositions]
*/
private fun createActions(straddlePositions: List<Position>) { private fun createActions(straddlePositions: List<Position>) {
this.actions.clear() this.actions.clear()
@ -150,6 +157,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
} }
/***
* Adds an action with the given [position], [type] and [amount] to the actions list
*/
private fun addAction(position: Int, type: Action.Type? = null, amount: Double? = null) { private fun addAction(position: Int, type: Action.Type? = null, amount: Double? = null) {
val action = Action() val action = Action()
action.index = this.actions.size action.index = this.actions.size
@ -159,10 +169,16 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
this.actions.add(action) this.actions.add(action)
} }
/***
* Returns the board cards for a given [street]
*/
fun cardsForStreet(street: Street): MutableList<Card> { fun cardsForStreet(street: Street): MutableList<Card> {
return this.board.sortedBy { it.index }.take(street.totalBoardCards).toMutableList() return this.board.sortedBy { it.index }.take(street.totalBoardCards).toMutableList()
} }
/***
* Returns the optional PlayerSetup object at the [position]
*/
fun playerSetupForPosition(position: Int): PlayerSetup? { fun playerSetupForPosition(position: Int): PlayerSetup? {
return this.playerSetups.firstOrNull { it.position == position } return this.playerSetups.firstOrNull { it.position == position }
} }
@ -170,6 +186,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
override val cards: RealmList<Card> override val cards: RealmList<Card>
get() { return this.board } get() { return this.board }
/***
* Returns the ante sum
*/
val anteSum: Double val anteSum: Double
get() { get() {
return if (bigBlindAnte) { return if (bigBlindAnte) {
@ -179,11 +198,18 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
} }
} }
/***
* Returns the sorted list of actions by index
*/
private val sortedActions: List<Action> private val sortedActions: List<Action>
get() { get() {
return this.actions.sortedBy { it.index } return this.actions.sortedBy { it.index }
} }
/***
* Returns the list of undefined positions,
* meaning the positions where no PlayerSetup has been created
*/
fun undefinedPositions(): List<Position> { fun undefinedPositions(): List<Position> {
val positions = Position.positionsPerPlayers(this.numberOfPlayers) val positions = Position.positionsPerPlayers(this.numberOfPlayers)
val copy = positions.clone() as LinkedHashSet<Position> val copy = positions.clone() as LinkedHashSet<Position>
@ -193,6 +219,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
return copy.toList() return copy.toList()
} }
/***
* Creates and affect a PlayerSetup at the given [positionIndex]
*/
fun createPlayerSetup(positionIndex: Int): PlayerSetup { fun createPlayerSetup(positionIndex: Int): PlayerSetup {
val playerSetup = if (this.realm != null) { val playerSetup = if (this.realm != null) {
@ -283,6 +312,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
return string return string
} }
/***
* Returns a string representation of the [playerSetup]
*/
private fun localizedPlayerSetup(playerSetup: PlayerSetup, positions: LinkedHashSet<Position>, context: Context): String { private fun localizedPlayerSetup(playerSetup: PlayerSetup, positions: LinkedHashSet<Position>, context: Context): String {
val playerItems = mutableListOf(positions.elementAt(playerSetup.position).value) val playerItems = mutableListOf(positions.elementAt(playerSetup.position).value)
playerItems.add("[${playerSetup.cards.formatted(context)}]") playerItems.add("[${playerSetup.cards.formatted(context)}]")
@ -292,6 +324,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
return playerItems.joinToString(" ") return playerItems.joinToString(" ")
} }
/***
* Returns a string representation of the [actionReadRow]
*/
private fun localizedAction(actionReadRow: ActionReadRow, context: Context): String { private fun localizedAction(actionReadRow: ActionReadRow, context: Context): String {
val formattedPositions = actionReadRow.positions.map { it.value }.joinToString(", ") val formattedPositions = actionReadRow.positions.map { it.value }.joinToString(", ")
val actionItems = mutableListOf(formattedPositions) val actionItems = mutableListOf(formattedPositions)

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/green" />
<size
android:width="32dp"
android:height="32dp" />
</shape>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Loading…
Cancel
Save