|
|
|
|
@ -67,24 +67,32 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null, managed: Boolean = true): Session { |
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null): Session { |
|
|
|
|
val session = Session() |
|
|
|
|
session.result = Result() |
|
|
|
|
|
|
|
|
|
if (bankroll != null) { |
|
|
|
|
session.bankroll = bankroll |
|
|
|
|
session.bankroll = realm.copyFromRealm(bankroll) |
|
|
|
|
} else { |
|
|
|
|
session.bankroll = realm.where<Bankroll>().findFirst() |
|
|
|
|
realm.where<Bankroll>().findFirst()?.let { br -> |
|
|
|
|
session.bankroll = realm.copyFromRealm(br) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
session.type = if (isTournament) Type.TOURNAMENT.ordinal else Type.CASH_GAME.ordinal |
|
|
|
|
|
|
|
|
|
session.limit = Limit.NO.ordinal |
|
|
|
|
session.game = realm.where(Game::class.java).equalTo("shortName", "HE").findFirst() |
|
|
|
|
|
|
|
|
|
return if (managed) { |
|
|
|
|
realm.copyToRealm(session) |
|
|
|
|
} else { |
|
|
|
|
session |
|
|
|
|
realm.where(Game::class.java) |
|
|
|
|
.equalTo("shortName", "HE").findFirst()?.let { |
|
|
|
|
session.game = realm.copyFromRealm(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return session |
|
|
|
|
// return if (managed) { |
|
|
|
|
// realm.copyToRealm(session) |
|
|
|
|
// } else { |
|
|
|
|
// session |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun fieldNameForQueryType(queryCondition: Class < out QueryCondition >): String? { |
|
|
|
|
@ -157,6 +165,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
@Ignore |
|
|
|
|
val computableResult: ComputableResult? = this.computableResults?.firstOrNull() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Timed interface |
|
|
|
|
|
|
|
|
|
override var dayOfWeek: Int? = null |
|
|
|
|
@ -204,12 +213,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
this.updateTimeParameter(field) |
|
|
|
|
this.computeNetDuration() |
|
|
|
|
// nullifies enddate when setting the start date after the end date |
|
|
|
|
// nullifies the endDate when setting the start date after the end date |
|
|
|
|
if (value != null && this.endDate != null && value.after(this.endDate)) { |
|
|
|
|
this.endDate = null |
|
|
|
|
} |
|
|
|
|
this.dateChanged() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -230,7 +239,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
this.computeNetDuration() |
|
|
|
|
this.dateChanged() |
|
|
|
|
this.defineDefaultTournamentBuyinIfNecessary() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -240,7 +249,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeNetDuration() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -252,10 +261,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
* The start date of the break |
|
|
|
|
*/ |
|
|
|
|
override var pauseDate: Date? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The session set containing the sessions, which can contain multiple endedSessions |
|
|
|
|
var sessionSet: SessionSet? = null |
|
|
|
|
@ -268,7 +273,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -296,7 +301,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
if (value > 0) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -314,16 +319,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
// The small blind value |
|
|
|
|
var cgOldSmallBlind: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The big blind value |
|
|
|
|
var cgOldBigBlind: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// var blinds: String? = null |
|
|
|
|
@ -334,8 +336,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
field = value |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.defineHighestBet() |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cgBlinds: String? = null |
|
|
|
|
@ -343,8 +345,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
field = cleanupBlinds(value) |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.defineHighestBet() |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cgBiggestBet: Double? = null |
|
|
|
|
@ -355,10 +357,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
// The entry fee of the tournament |
|
|
|
|
var tournamentEntryFee: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The total number of players who participated in the tournament |
|
|
|
|
var tournamentNumberOfPlayers: Int? = null |
|
|
|
|
@ -377,27 +375,28 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
// The number of hands played during the sessions |
|
|
|
|
var handsCount: Int? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun bankrollHasBeenUpdated() { |
|
|
|
|
this.generateStakes() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Manages impacts on SessionSets |
|
|
|
|
* Should be called when the start / end date are changed |
|
|
|
|
*/ |
|
|
|
|
private fun dateChanged() { |
|
|
|
|
if (this.endDate != null) { |
|
|
|
|
SessionSetManager.updateTimeline(this) |
|
|
|
|
} else if (this.sessionSet != null) { |
|
|
|
|
SessionSetManager.removeFromTimeline(this) |
|
|
|
|
} |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
SessionSetManager.sessionDateChanged(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// /** |
|
|
|
|
// * Manages impacts on SessionSets |
|
|
|
|
// * Should be called when the start / end date are changed |
|
|
|
|
// */ |
|
|
|
|
// private fun dateChanged() { |
|
|
|
|
// SessionSetManager.updatedSession(this) |
|
|
|
|
//// if (this.endDate != null) { |
|
|
|
|
//// SessionSetManager.updateTimeline(this) |
|
|
|
|
//// } else if (this.sessionSet != null) { |
|
|
|
|
//// SessionSetManager.removeFromTimeline(this) |
|
|
|
|
//// } |
|
|
|
|
//// this.updateRowRepresentation() |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a non-null date for the session |
|
|
|
|
@ -436,7 +435,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
get() { |
|
|
|
|
val bb = this.cgBiggestBet |
|
|
|
|
val result = this.result |
|
|
|
|
return if (bb != null && result != null) { |
|
|
|
|
return if (bb != null && bb > 0.0 && result != null) { |
|
|
|
|
result.net / bb |
|
|
|
|
} else { |
|
|
|
|
0.0 |
|
|
|
|
@ -471,6 +470,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
return this.result?.net ?: 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun preCompute() { |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Pre-compute various statIds |
|
|
|
|
*/ |
|
|
|
|
@ -493,16 +497,21 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.sessionSet?.computeStats() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Approximates the number of hands played per hour at the table |
|
|
|
|
*/ |
|
|
|
|
val numberOfHandsPerHour: Double |
|
|
|
|
private val numberOfHandsPerHour: Double |
|
|
|
|
get() { |
|
|
|
|
val tableSize = this.tableSize ?: 9 // 9 is the default table size if null |
|
|
|
|
val config = UserConfig.getConfiguration(this.realm) |
|
|
|
|
val playerHandsPerHour = if (this.isLive) config.liveDealtHandsPerHour else config.onlineDealtHandsPerHour |
|
|
|
|
|
|
|
|
|
var playerHandsPerHour = 0 |
|
|
|
|
UserConfig.getConfiguration(this.realm) { config -> |
|
|
|
|
playerHandsPerHour = if (this.isLive) config.liveDealtHandsPerHour else config.onlineDealtHandsPerHour |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.numberOfTables * playerHandsPerHour / tableSize.toDouble() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -557,7 +566,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
* Start or continue a session |
|
|
|
|
*/ |
|
|
|
|
fun startOrContinue() { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
when (val state = getState()) { |
|
|
|
|
SessionState.PENDING, SessionState.PLANNED -> { |
|
|
|
|
this.startDate = Date() |
|
|
|
|
@ -576,7 +585,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
throw PAIllegalStateException("unmanaged session state: $state") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun defineDefaultTournamentBuyinIfNecessary() { |
|
|
|
|
@ -589,28 +598,28 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
* Pause a session |
|
|
|
|
*/ |
|
|
|
|
fun pause() { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
when (val state = getState()) { |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
this.pauseDate = Date() |
|
|
|
|
} |
|
|
|
|
else -> throw PAIllegalStateException("Pausing a session in an unmanaged state: $state") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Stop a session |
|
|
|
|
*/ |
|
|
|
|
fun stop(context: Context) { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
when (val state = getState()) { |
|
|
|
|
SessionState.STARTED, SessionState.PAUSED -> { |
|
|
|
|
this.end() |
|
|
|
|
} |
|
|
|
|
else -> throw Exception("Stopping session in unmanaged state: $state") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// } |
|
|
|
|
cancelStopNotification(context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -618,12 +627,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
* Restart a session |
|
|
|
|
*/ |
|
|
|
|
fun restart() { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
this.pauseDate = null |
|
|
|
|
this.startDate = Date() |
|
|
|
|
this.endDate = null |
|
|
|
|
this.breakDuration = 0L |
|
|
|
|
} |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -660,7 +669,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the game titleResId |
|
|
|
|
* Example: NL Holdem |
|
|
|
|
* Example: NL Hold'em |
|
|
|
|
*/ |
|
|
|
|
fun getFormattedGame(): String { |
|
|
|
|
var gameTitle = "" |
|
|
|
|
@ -672,46 +681,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
if (game != null) { |
|
|
|
|
gameTitle += game?.name |
|
|
|
|
} |
|
|
|
|
return if (gameTitle.isNotBlank()) gameTitle else NULL_TEXT |
|
|
|
|
return gameTitle.ifBlank { NULL_TEXT } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getFormattedStakes(): String { |
|
|
|
|
|
|
|
|
|
return this.cgStakes?.let { StakesHolder.readableStakes(it) } ?: run { NULL_TEXT } |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// val formattedBlinds = StakesHolder.formattedBlinds(this.cgBlinds, this.currency) |
|
|
|
|
// val formattedAntes = StakesHolder.formattedAnte(this.cgAnte, this.currency) |
|
|
|
|
// |
|
|
|
|
// return StakesHolder.formattedStakes(formattedBlinds, formattedAntes) |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// val components = arrayListOf<String>() |
|
|
|
|
// this.formattedBlinds?.let { components.add(it) } |
|
|
|
|
// this.formattedAnte?.let { components.add("($it)") } |
|
|
|
|
// |
|
|
|
|
// return if (components.isNotEmpty()) { |
|
|
|
|
// components.joinToString(" ") |
|
|
|
|
// } else { |
|
|
|
|
// NULL_TEXT |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fun formatBlinds() { |
|
|
|
|
// blinds = null |
|
|
|
|
// if (cgBigBlind == null) return |
|
|
|
|
// cgBigBlind?.let { bb -> |
|
|
|
|
// val sb = cgSmallBlind ?: bb / 2.0 |
|
|
|
|
// val preFormattedBlinds = "${sb.formatted}/${bb.round()}" |
|
|
|
|
// println("<<<<<< bb.toCurrency(currency) : ${bb.toCurrency(currency)}") |
|
|
|
|
// println("<<<<<< preFormattedBlinds : $preFormattedBlinds") |
|
|
|
|
// val regex = Regex("-?\\d+(\\.\\d+)?") |
|
|
|
|
// blinds = bb.toCurrency(currency).replace(regex, preFormattedBlinds) |
|
|
|
|
// println("<<<<<< blinds = $blinds") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// LifeCycle |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -721,10 +697,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
|
|
|
|
|
CrashLogging.log("Deletes session. Id = ${this.id}") |
|
|
|
|
if (isValid) { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
// realm.executeTransaction { |
|
|
|
|
cleanup() |
|
|
|
|
deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
// } |
|
|
|
|
} else { |
|
|
|
|
CrashLogging.log("Attempt to delete an invalid session") |
|
|
|
|
} |
|
|
|
|
@ -741,7 +717,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
// cleanup unnecessary related objects |
|
|
|
|
this.result?.deleteFromRealm() |
|
|
|
|
this.computableResults?.deleteAllFromRealm() |
|
|
|
|
this.computableResult?.deleteFromRealm() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -776,32 +752,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
when (row) { |
|
|
|
|
SessionPropertiesRow.BANKROLL -> bankroll = value as Bankroll? |
|
|
|
|
SessionPropertiesRow.STAKES -> if (value is Stakes) { |
|
|
|
|
|
|
|
|
|
if (value.ante != null) { |
|
|
|
|
this.cgAnte = value.ante |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (value.blinds != null) { |
|
|
|
|
this.cgBlinds = value.blinds |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// cgSmallBlind = try { |
|
|
|
|
// (value[0] as String? ?: "0").toDouble() |
|
|
|
|
// } catch (e: Exception) { |
|
|
|
|
// null |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// cgBigBlind = try { |
|
|
|
|
// (value[1] as String? ?: "0").toDouble() |
|
|
|
|
// } catch (e: Exception) { |
|
|
|
|
// null |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// cgBigBlind?.let { |
|
|
|
|
// if (cgSmallBlind == null || cgSmallBlind == 0.0) { |
|
|
|
|
// cgSmallBlind = it / 2.0 |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
} else if (value == null) { |
|
|
|
|
this.cgBlinds = null |
|
|
|
|
this.cgAnte = null |
|
|
|
|
@ -812,15 +768,20 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.BUY_IN -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.buyin = value as Double? |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.CASHED_OUT, SessionPropertiesRow.PRIZE -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.cashout = value as Double? |
|
|
|
|
if (value != null) { |
|
|
|
|
this.end() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.NET_RESULT -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.netResult = value as Double? |
|
|
|
|
if (value != null) { |
|
|
|
|
this.end() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.COMMENT -> comment = value as String? ?: "" |
|
|
|
|
SessionPropertiesRow.END_DATE -> if (value is Date?) { |
|
|
|
|
@ -876,20 +837,23 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName? |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_TYPE -> tournamentType = (value as TournamentType?)?.ordinal |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_FEATURE -> { |
|
|
|
|
|
|
|
|
|
this.tournamentFeatures.clear() |
|
|
|
|
value?.let { |
|
|
|
|
tournamentFeatures = RealmList() |
|
|
|
|
tournamentFeatures.addAll((it as ArrayList<TournamentFeature>)) |
|
|
|
|
} ?: run { |
|
|
|
|
tournamentFeatures.removeAll(this.tournamentFeatures) |
|
|
|
|
tournamentFeatures.addAll((it as List<TournamentFeature>)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.HANDS_COUNT -> handsCount = (value as Double?)?.toInt() |
|
|
|
|
SessionPropertiesRow.NUMBER_OF_TABLES -> this.numberOfTables = (value as Double?)?.toInt() ?: 1 |
|
|
|
|
is CustomField -> { |
|
|
|
|
customFieldEntries.filter { it.customField?.id == row.id }.let { |
|
|
|
|
customFieldEntries.removeAll(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val entryIds = row.entries.map { it.id } |
|
|
|
|
val entries = this.customFieldEntries.intersectBy(entryIds) { it.id } |
|
|
|
|
this.customFieldEntries.removeAll(entries) |
|
|
|
|
|
|
|
|
|
// customFieldEntries.filter { it.customField?.id == row.id }.let { |
|
|
|
|
// customFieldEntries.removeAll(it.toSet()) |
|
|
|
|
// } |
|
|
|
|
when (row.type) { |
|
|
|
|
CustomField.Type.AMOUNT.uniqueIdentifier, |
|
|
|
|
CustomField.Type.NUMBER.uniqueIdentifier -> { |
|
|
|
|
@ -914,7 +878,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
private fun getOrCreateResult(): Result { |
|
|
|
|
return this.result |
|
|
|
|
?: run { |
|
|
|
|
val result = realm.createObject(Result::class.java) |
|
|
|
|
val result = Result() |
|
|
|
|
// result.inverseSession = WeakReference(this) |
|
|
|
|
this.result = result |
|
|
|
|
result |
|
|
|
|
} |
|
|
|
|
@ -1028,7 +993,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.BUY_IN -> this.result?.buyin?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.CASHED_OUT, SessionPropertiesRow.PRIZE -> this.result?.cashout?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.NET_RESULT -> this.result?.netResult?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT |
|
|
|
|
SessionPropertiesRow.COMMENT -> this.comment.ifEmpty { NULL_TEXT } |
|
|
|
|
SessionPropertiesRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.GAME -> getFormattedGame() |
|
|
|
|
SessionPropertiesRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
@ -1063,8 +1028,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.HANDS_COUNT -> this.handsCountFormatted(context) |
|
|
|
|
SessionPropertiesRow.NUMBER_OF_TABLES -> this.numberOfTables.toString() |
|
|
|
|
is CustomField -> { |
|
|
|
|
customFieldEntries.find { it.customField?.id == row.id }?.let { customFieldEntry -> |
|
|
|
|
return customFieldEntry.getFormattedValue(currency) |
|
|
|
|
val entryIds = this.customFieldEntries.map { it.id } |
|
|
|
|
val entries = row.entries.intersectBy(entryIds) { it.id } |
|
|
|
|
entries.firstOrNull()?.let { customFieldEntry -> |
|
|
|
|
return customFieldEntry.getFormattedValue(row, currency) |
|
|
|
|
} |
|
|
|
|
return NULL_TEXT |
|
|
|
|
} |
|
|
|
|
@ -1086,33 +1053,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
this.result?.netResult = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Stakes |
|
|
|
|
|
|
|
|
|
// fun generateStakes() { |
|
|
|
|
// |
|
|
|
|
// if (this.cgAnte == null && this.cgAnte == null) { |
|
|
|
|
// this.cgStakes = null |
|
|
|
|
// return |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// val components = arrayListOf<String>() |
|
|
|
|
// |
|
|
|
|
// this.cgBlinds?.let { components.add("${cbBlinds}${it}") } |
|
|
|
|
// this.cgAnte?.let { components.add("${cbAnte}${it.formatted}") } |
|
|
|
|
// |
|
|
|
|
// val code = this.bankroll?.currency?.code ?: UserDefaults.currency.currencyCode |
|
|
|
|
// components.add("${cbCode}${code}") |
|
|
|
|
// |
|
|
|
|
// this.cgStakes = components.joinToString(cbSeparator) |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// fun defineHighestBet() { |
|
|
|
|
// val bets = arrayListOf<Double>() |
|
|
|
|
// this.cgAnte?.let { bets.add(it) } |
|
|
|
|
// bets.addAll(this.blindValues) |
|
|
|
|
// this.cgBiggestBet = bets.maxOrNull() |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
private fun cleanupBlinds(blinds: String?): String? { |
|
|
|
|
|
|
|
|
|
if (blinds == null) { |
|
|
|
|
|