|
|
|
|
@ -4,8 +4,10 @@ import android.content.Context |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import io.realm.annotations.Ignore |
|
|
|
|
import io.realm.annotations.Index |
|
|
|
|
import io.realm.annotations.LinkingObjects |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
@ -61,7 +63,10 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource |
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null): Session { |
|
|
|
|
val session = Session() |
|
|
|
|
session.result = Result() |
|
|
|
|
session.computableResult = ComputableResult() |
|
|
|
|
|
|
|
|
|
val computableResult = ComputableResult() |
|
|
|
|
computableResult.session = session |
|
|
|
|
|
|
|
|
|
if (bankroll != null) { |
|
|
|
|
session.bankroll = bankroll |
|
|
|
|
} else { |
|
|
|
|
@ -78,6 +83,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource |
|
|
|
|
/** |
|
|
|
|
* Indicates the type of session, cash game or tournament |
|
|
|
|
*/ |
|
|
|
|
@Index |
|
|
|
|
var type: Int = Type.CASH_GAME.ordinal |
|
|
|
|
|
|
|
|
|
// The result of the main user |
|
|
|
|
@ -86,7 +92,13 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource |
|
|
|
|
/** |
|
|
|
|
* Optimized result for faster stats |
|
|
|
|
*/ |
|
|
|
|
var computableResult: ComputableResult? = null |
|
|
|
|
// var computableResult: ComputableResult? = null |
|
|
|
|
|
|
|
|
|
@LinkingObjects("session") |
|
|
|
|
private val computableResults: RealmResults<ComputableResult>? = null |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
val computableResult: ComputableResult? = this.computableResults?.firstOrNull() |
|
|
|
|
|
|
|
|
|
// Timed interface |
|
|
|
|
|
|
|
|
|
@ -293,10 +305,11 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateComputableResult() { |
|
|
|
|
this.computableResult?.let { |
|
|
|
|
|
|
|
|
|
this.computableResults?.forEach { |
|
|
|
|
it.updateWith(this) |
|
|
|
|
} ?: run { |
|
|
|
|
throw IllegalStateException("Session should always have a Light Result") |
|
|
|
|
throw IllegalStateException("Session should always have a computable results") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -497,6 +510,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource |
|
|
|
|
// cleanup unnecessary related objects |
|
|
|
|
set.deleteFromRealm() |
|
|
|
|
this.result?.deleteFromRealm() |
|
|
|
|
this.computableResults?.deleteAllFromRealm() |
|
|
|
|
|
|
|
|
|
// Updates the timeline |
|
|
|
|
SessionSetManager.removeFromTimeline(this) |
|
|
|
|
|