@ -35,6 +35,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.UserDefaults
import net.pokeranalytics.android.util.extensions.*
import java.text.DateFormat
import java.util.*
import java.util.Currency
import kotlin.collections.ArrayList
@ -42,7 +43,7 @@ import kotlin.collections.ArrayList
typealias BB = Double
open class Session : RealmObject ( ) , Savable , Editable , StaticRowRepresentableDataSource , RowRepresentable , Timed ,
TimeFilterable , Filterable {
TimeFilterable , Filterable {
enum class Type {
CASH _GAME ,
@ -88,7 +89,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
DAY _OF _WEEK :: class , WEEK _END :: class , WEEK _DAY :: class - > " dayOfWeek "
MONTH :: class - > " month "
YEAR :: class - > " year "
TODAY :: class , YESTERDAY :: class , TODAY _AND _YESTERDAY :: class , THIS _YEAR :: class , THIS _MONTH :: class , THIS _WEEK :: class - > " startDate "
TODAY :: class , YESTERDAY :: class , TODAY _AND _YESTERDAY :: class , THIS _YEAR :: class , THIS _MONTH :: class , THIS _WEEK :: class - > " startDate "
else -> null
}
}
@ -114,7 +115,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
// Timed interface
override var dayOfWeek : Int ? = null
override var dayOfWeek : Int ? = null
override var month : Int ? = null
override var year : Int ? = null
override var dayOfMonth : Int ? = null
@ -213,21 +214,21 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
// The small blind value
var cgSmallBlind : Double ? = null
set ( value ) {
field = value
formatBlinds ( )
}
set ( value ) {
field = value
formatBlinds ( )
}
// The big blind value
var cgBigBlind : Double ? = null
set ( value ) {
field = value
this . computeStats ( )
formatBlinds ( )
formatBlinds ( )
}
var blinds : String ? = null
private set
var blinds : String ? = null
private set
// Tournament
@ -246,9 +247,9 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
// The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures : RealmList < TournamentFeature > = RealmList ( )
fun bankrollHasBeenUpdated ( ) {
formatBlinds ( )
}
fun bankrollHasBeenUpdated ( ) {
formatBlinds ( )
}
/ * *
* Manages impacts on SessionSets
@ -303,7 +304,8 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
* /
val bbNet : BB
get ( ) {
val bb = this . cgBigBlind ; val result = this . result
val bb = this . cgBigBlind ;
val result = this . result
if ( bb != null && result != null ) {
return result . net / bb
} else {
@ -487,19 +489,19 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
return NULL _TEXT
}
val hasDefaultCurrency : Boolean
get ( ) {
return bankroll ?. currency ?. code == null
}
val hasDefaultCurrency : Boolean
get ( ) {
return bankroll ?. currency ?. code == null
}
val currency : Currency
get ( ) {
return bankroll ?. currency ?. code ?. let {
Currency . getInstance ( it )
} ?: run {
UserDefaults . currency
}
}
val currency : Currency
get ( ) {
return bankroll ?. currency ?. code ?. let {
Currency . getInstance ( it )
} ?: run {
UserDefaults . currency
}
}
/ * *
* Return the game title
@ -518,18 +520,18 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
return if ( gameTitle . isNotBlank ( ) ) gameTitle else NULL _TEXT
}
fun getFormattedBlinds ( ) : String {
return blinds ?: 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()} "
}
}
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
@ -569,7 +571,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
@Ignore
private var rowRepresentationForCurrentState : List < RowRepresentable > = mutableListOf ( )
private var rowRepresentationForCurrentState : List < RowRepresentable > = mutableListOf ( )
private fun updatedRowRepresentationForCurrentState ( ) : List < RowRepresentable > {
val rows = ArrayList < RowRepresentable > ( )
@ -669,7 +671,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
SessionRow . TOURNAMENT _FEATURE -> {
if ( tournamentFeatures . size > 2 ) {
" $ {tournamentFeatures.subList(0,2).joinToString {
" $ {tournamentFeatures.subList(0, 2).joinToString {
it . name
} } , .. . "
} else if ( tournamentFeatures . size > 0 ) {
@ -696,56 +698,98 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
override fun editDescriptors ( row : RowRepresentable ) : ArrayList < RowRepresentableEditDescriptor > ? {
return when ( row ) {
SessionRow . BANKROLL -> row . editingDescriptors ( mapOf (
" defaultValue " to this . bankroll ,
" data " to LiveData . BANKROLL . items ( realm ) ) )
SessionRow . GAME -> row . editingDescriptors ( mapOf (
" limit " to this . limit ,
" defaultValue " to this . game ,
" data " to LiveData . GAME . items ( realm ) ) )
SessionRow . LOCATION -> row . editingDescriptors ( mapOf (
" defaultValue " to this . location ,
" data " to LiveData . LOCATION . items ( realm ) ) )
SessionRow . TOURNAMENT _FEATURE -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tournamentFeatures ,
" data " to LiveData . TOURNAMENT _FEATURE . items ( realm ) ) )
SessionRow . TOURNAMENT _NAME -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tournamentName ,
" data " to LiveData . TOURNAMENT _NAME . items ( realm ) ) )
SessionRow . TOURNAMENT _TYPE -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tournamentType ) )
SessionRow . TABLE _SIZE -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tableSize ) )
SessionRow . BLINDS -> row . editingDescriptors ( mapOf (
" sb " to cgSmallBlind ?. round ( ) ,
" bb " to cgBigBlind ?. round ( )
) )
SessionRow . BUY _IN -> row . editingDescriptors ( mapOf (
" bb " to cgBigBlind ,
" fee " to this . tournamentEntryFee ,
" ratedBuyin " to result ?. buyin
) )
SessionRow . BANKROLL -> row . editingDescriptors (
mapOf (
" defaultValue " to this . bankroll ,
" data " to LiveData . BANKROLL . items ( realm )
)
)
SessionRow . GAME -> row . editingDescriptors (
mapOf (
" limit " to this . limit ,
" defaultValue " to this . game ,
" data " to LiveData . GAME . items ( realm )
)
)
SessionRow . LOCATION -> row . editingDescriptors (
mapOf (
" defaultValue " to this . location ,
" data " to LiveData . LOCATION . items ( realm )
)
)
SessionRow . TOURNAMENT _FEATURE -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tournamentFeatures ,
" data " to LiveData . TOURNAMENT _FEATURE . items ( realm )
)
)
SessionRow . TOURNAMENT _NAME -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tournamentName ,
" data " to LiveData . TOURNAMENT _NAME . items ( realm )
)
)
SessionRow . TOURNAMENT _TYPE -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tournamentType
)
)
SessionRow . TABLE _SIZE -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tableSize
)
)
SessionRow . BLINDS -> row . editingDescriptors (
mapOf (
" sb " to cgSmallBlind ?. round ( ) ,
" bb " to cgBigBlind ?. round ( )
)
)
SessionRow . BUY _IN -> row . editingDescriptors (
mapOf (
" bb " to cgBigBlind ,
" fee " to this . tournamentEntryFee ,
" ratedBuyin " to result ?. buyin
)
)
SessionRow . BREAK _TIME -> row . editingDescriptors ( mapOf ( ) )
SessionRow . CASHED _OUT , SessionRow . PRIZE -> row . editingDescriptors ( mapOf (
" defaultValue " to result ?. cashout
) )
SessionRow . NET _RESULT -> row . editingDescriptors ( mapOf (
" defaultValue " to result ?. netResult
) )
SessionRow . COMMENT -> row . editingDescriptors ( mapOf (
" defaultValue " to this . comment ) )
SessionRow . INITIAL _BUY _IN -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tournamentEntryFee
) )
SessionRow . PLAYERS -> row . editingDescriptors ( mapOf (
" defaultValue " to this . tournamentNumberOfPlayers ) )
SessionRow . POSITION -> row . editingDescriptors ( mapOf (
" defaultValue " to this . result ?. tournamentFinalPosition ) )
SessionRow . TIPS -> row . editingDescriptors ( mapOf (
" sb " to cgSmallBlind ?. round ( ) ,
" bb " to cgBigBlind ?. round ( ) ,
" tips " to result ?. tips
) )
SessionRow . CASHED _OUT , SessionRow . PRIZE -> row . editingDescriptors (
mapOf (
" defaultValue " to result ?. cashout
)
)
SessionRow . NET _RESULT -> row . editingDescriptors (
mapOf (
" defaultValue " to result ?. netResult
)
)
SessionRow . COMMENT -> row . editingDescriptors (
mapOf (
" defaultValue " to this . comment
)
)
SessionRow . INITIAL _BUY _IN -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tournamentEntryFee
)
)
SessionRow . PLAYERS -> row . editingDescriptors (
mapOf (
" defaultValue " to this . tournamentNumberOfPlayers
)
)
SessionRow . POSITION -> row . editingDescriptors (
mapOf (
" defaultValue " to this . result ?. tournamentFinalPosition
)
)
SessionRow . TIPS -> row . editingDescriptors (
mapOf (
" sb " to cgSmallBlind ?. round ( ) ,
" bb " to cgBigBlind ?. round ( ) ,
" tips " to result ?. tips
)
)
else -> null
}
}
@ -782,13 +826,15 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
this . breakDuration = ( value as Double ? ?: 0.0 ) . toLong ( ) * 60 * 1000
}
SessionRow . BUY _IN -> {
val localResult = if ( this . result != null ) this . result as Result else realm . createObject ( Result :: class . java )
val localResult =
if ( this . result != null ) this . result as Result else realm . createObject ( Result :: class . java )
localResult . buyin = value as Double ?
this . result = localResult
this . updateRowRepresentation ( )
}
SessionRow . CASHED _OUT , SessionRow . PRIZE -> {
val localResult = if ( this . result != null ) this . result as Result else realm . createObject ( Result :: class . java )
val localResult =
if ( this . result != null ) this . result as Result else realm . createObject ( Result :: class . java )
localResult . cashout = value as Double ?
@ -870,7 +916,12 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
// Stat Base
override fun formattedValue ( stat : Stat , context : Context ) : TextFormat {
override val entryTitle : String
get ( ) {
return DateFormat . getDateInstance ( DateFormat . SHORT ) . format ( this . startDate )
}
override fun formattedValue ( stat : Stat , context : Context ) : TextFormat {
this . result ?. let { result ->
@ -886,7 +937,10 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
}
Stat . HOURLY _RATE _BB -> this . bbHourlyRate
Stat . NET _BB _PER _100 _HANDS , Stat . STANDARD _DEVIATION _BB _PER _100 _HANDS -> Stat . netBBPer100Hands ( this . bbNet , this . estimatedHands )
Stat . NET _BB _PER _100 _HANDS , Stat . STANDARD _DEVIATION _BB _PER _100 _HANDS -> Stat . netBBPer100Hands (
this . bbNet ,
this . estimatedHands
)
Stat . AVERAGE _NET _BB -> this . bbNet
Stat . DURATION , Stat . AVERAGE _DURATION -> this . netDuration . toDouble ( )
Stat . HOURLY _RATE , Stat . STANDARD _DEVIATION _HOURLY -> this . hourlyRate
@ -914,4 +968,3 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}