|
|
|
|
@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model |
|
|
|
|
import android.content.Context |
|
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.handhistory.HandSetup |
|
|
|
|
@ -133,15 +134,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
/*** |
|
|
|
|
* Creates and configures a new HandHistory object using a [handSetup] |
|
|
|
|
*/ |
|
|
|
|
fun createNewHandHistory(handSetup: HandSetup) { |
|
|
|
|
|
|
|
|
|
fun createNewHandHistory(realm: Realm, handSetup: HandSetup) { |
|
|
|
|
this.handSetup = handSetup |
|
|
|
|
val handHistory = HandHistory() |
|
|
|
|
handHistory.configure(handSetup) |
|
|
|
|
this.playerHandMaxCards = handSetup.game?.playerHandMaxCards |
|
|
|
|
|
|
|
|
|
this.loadHandHistory(handHistory) |
|
|
|
|
|
|
|
|
|
this.loadHandHistory(realm.copyToRealm(handHistory)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
@ -586,6 +584,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the list of PlayerSetupRowRepresentable for the hand |
|
|
|
|
* Will show rows for existing PlayerSetup, as well as a row for the hero if not set, |
|
|
|
|
* and a row for a new player if necessary |
|
|
|
|
*/ |
|
|
|
|
private fun playerSetups(): List<PlayerSetupRowRepresentable> { |
|
|
|
|
|
|
|
|
|
val hh = this.handHistory |
|
|
|
|
@ -608,4 +611,32 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Sets the both [positionIndex] and position for a PlayerSetup inside a [psRowRepresentable] |
|
|
|
|
*/ |
|
|
|
|
fun setPlayerSetupPosition(psRowRepresentable: PlayerSetupRowRepresentable, positionIndex: Int) { |
|
|
|
|
|
|
|
|
|
var setupCreated = false |
|
|
|
|
psRowRepresentable.playerSetup?.let { |
|
|
|
|
it.position = positionIndex |
|
|
|
|
} ?: run { |
|
|
|
|
psRowRepresentable.playerSetup = this.handHistory.createPlayerSetup(positionIndex) |
|
|
|
|
setupCreated = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val position = this.sortedActions.positions.elementAt(positionIndex) |
|
|
|
|
psRowRepresentable.position = position |
|
|
|
|
|
|
|
|
|
if (!psRowRepresentable.hero && setupCreated) { |
|
|
|
|
|
|
|
|
|
if (this.handHistory.undefinedPositions().isNotEmpty()) { |
|
|
|
|
val newPlayerRow = PlayerSetupRowRepresentable(false, null) |
|
|
|
|
val index = this.indexOfRowRepresentable(psRowRepresentable) |
|
|
|
|
this.rowsLiveData.value?.add(index + 1, newPlayerRow) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |