|
|
|
|
@ -11,10 +11,7 @@ import io.realm.annotations.LinkingObjects |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.ComputedStat |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.calculus.StatFormattingException |
|
|
|
|
import net.pokeranalytics.android.calculus.TextFormat |
|
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
|
import net.pokeranalytics.android.exceptions.ModelException |
|
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
@ -35,8 +32,8 @@ import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow |
|
|
|
|
import net.pokeranalytics.android.util.CurrencyUtils |
|
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
import net.pokeranalytics.android.util.UserDefaults |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import java.util.* |
|
|
|
|
import java.util.Currency |
|
|
|
|
@ -47,7 +44,6 @@ typealias BB = Double |
|
|
|
|
open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDataSource, RowRepresentable, Timed, |
|
|
|
|
TimeFilterable, Filterable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class Type { |
|
|
|
|
CASH_GAME, |
|
|
|
|
TOURNAMENT |
|
|
|
|
@ -78,10 +74,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
LIMIT -> "limit" |
|
|
|
|
TABLE_SIZE -> "tableSize" |
|
|
|
|
TOURNAMENT_TYPE -> "tournamentType" |
|
|
|
|
CURRENCY -> "bankroll.currency" |
|
|
|
|
CURRENCY_CODE -> "bankroll.currency.code" |
|
|
|
|
BIG_BLIND -> "cgBigBlind" |
|
|
|
|
SMALL_BLIND -> "cgSmallBlind" |
|
|
|
|
BLIND -> "blind" |
|
|
|
|
COMMENT -> "comment" |
|
|
|
|
BETWEEN_NUMBER_OF_TABLE, MORE_NUMBER_OF_TABLE, LESS_NUMBER_OF_TABLE -> "numberOfTable" |
|
|
|
|
MORE_THAN_NET_RESULT, LESS_THAN_NET_RESULT -> "computableResults.ratedNet" |
|
|
|
|
@ -220,14 +213,22 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
|
|
|
|
|
// The small blind value |
|
|
|
|
var cgSmallBlind: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
formatBlinds() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The big blind value |
|
|
|
|
var cgBigBlind: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
formatBlinds() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var blinds: String? = null |
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
// Tournament |
|
|
|
|
|
|
|
|
|
// The entry fee of the tournament |
|
|
|
|
@ -245,6 +246,10 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
// The features of the tournament, like Knockout, Shootout, Turbo... |
|
|
|
|
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() |
|
|
|
|
|
|
|
|
|
fun bankrollHasBeenUpdated() { |
|
|
|
|
formatBlinds() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Manages impacts on SessionSets |
|
|
|
|
* Should be called when the start / end date are changed |
|
|
|
|
@ -482,13 +487,18 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
return NULL_TEXT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the formatted blinds |
|
|
|
|
*/ |
|
|
|
|
fun getBlinds(): String { |
|
|
|
|
val currencyCode = bankroll?.currency?.code ?: CurrencyUtils.getLocaleCurrency().currencyCode |
|
|
|
|
val currencySymbol = Currency.getInstance(currencyCode).symbol |
|
|
|
|
return if (cgSmallBlind == null) NULL_TEXT else "$currencySymbol ${cgSmallBlind?.formatted()}/${cgBigBlind?.round()}" |
|
|
|
|
val hasDefaultCurrency: Boolean |
|
|
|
|
get() { |
|
|
|
|
return bankroll?.currency?.code == null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val currency : Currency |
|
|
|
|
get() { |
|
|
|
|
return bankroll?.currency?.code?.let { |
|
|
|
|
Currency.getInstance(it) |
|
|
|
|
} ?: run { |
|
|
|
|
UserDefaults.currency |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -508,6 +518,19 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
return if (gameTitle.isNotBlank()) gameTitle else NULL_TEXT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getFormattedBlinds(): String { |
|
|
|
|
return blinds ?: NULL_TEXT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun formatBlinds() { |
|
|
|
|
blinds = null |
|
|
|
|
if (cgBigBlind == null) return |
|
|
|
|
cgBigBlind?.let { bb -> |
|
|
|
|
val sb = cgSmallBlind ?: bb / 2.0 |
|
|
|
|
blinds = "${currency.symbol} ${sb.formatted()}/${bb.round()}" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LifeCycle |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -558,7 +581,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
title = getFormattedDuration(), |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll)) |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, currency) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
rows.add(SeparatorRowRepresentable()) |
|
|
|
|
@ -568,7 +591,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
resId = R.string.pause, |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll)) |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, currency) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
rows.add(SeparatorRowRepresentable()) |
|
|
|
|
@ -578,14 +601,14 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
title = getFormattedDuration(), |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll)) |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, currency) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
rows.add( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT, |
|
|
|
|
resId = R.string.hour_rate_without_pauses, |
|
|
|
|
computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate, CurrencyUtils.getCurrency(bankroll)) |
|
|
|
|
computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate, currency) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
@ -624,20 +647,20 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
override fun stringForRow(row: RowRepresentable, context: Context): String { |
|
|
|
|
return when (row) { |
|
|
|
|
SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT |
|
|
|
|
SessionRow.BLINDS -> getBlinds() |
|
|
|
|
SessionRow.BLINDS -> getFormattedBlinds() |
|
|
|
|
SessionRow.BREAK_TIME -> if (this.breakDuration > 0.0) this.breakDuration.toMinutes() else NULL_TEXT |
|
|
|
|
SessionRow.BUY_IN -> this.result?.buyin?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT |
|
|
|
|
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT |
|
|
|
|
SessionRow.BUY_IN -> this.result?.buyin?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT |
|
|
|
|
SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
|
SessionRow.GAME -> getFormattedGame() |
|
|
|
|
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT |
|
|
|
|
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionRow.LOCATION -> location?.name ?: NULL_TEXT |
|
|
|
|
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT |
|
|
|
|
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT |
|
|
|
|
SessionRow.START_DATE -> this.startDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
|
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT |
|
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT |
|
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionRow.TOURNAMENT_TYPE -> this.tournamentType?.let { |
|
|
|
|
TournamentType.values()[it].localizedTitle(context) |
|
|
|
|
} ?: run { |
|
|
|
|
@ -860,7 +883,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
value?.let { |
|
|
|
|
return stat.format(it, CurrencyUtils.getCurrency(this.bankroll), context) |
|
|
|
|
return stat.format(it, currency, context) |
|
|
|
|
} ?: run { |
|
|
|
|
return TextFormat(NULL_TEXT) |
|
|
|
|
} |
|
|
|
|
@ -871,6 +894,11 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Timed |
|
|
|
|
|
|
|
|
|
override val objectIdentifier: ObjectIdentifier |
|
|
|
|
get() = ObjectIdentifier(this.id, Session::class.java) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|