From 561bfd8b1c513651e2783413c0c71f3c486ac90e Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 31 Jul 2019 10:33:58 +0200 Subject: [PATCH] Fixes issue with net computation for online tournaments --- .../android/model/realm/Result.kt | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt index 19394fcd..91de43f1 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt @@ -30,7 +30,7 @@ open class Result : RealmObject(), Filterable { set(value) { field = value this.computeNumberOfRebuy() - this.computeNet() + this.computeNet(true) } /** @@ -39,7 +39,7 @@ open class Result : RealmObject(), Filterable { var cashout: Double? = null set(value) { field = value - this.computeNet() + this.computeNet(true) if (value != null) { this.session?.end() } @@ -60,9 +60,9 @@ open class Result : RealmObject(), Filterable { } field = value - this.computeNet() + this.computeNet(false) if (value != null) { - this.session.end() + this.session?.end() } } @@ -103,12 +103,27 @@ open class Result : RealmObject(), Filterable { val isPositive: Int = if (this.net >= 0.0) 1 else 0 // Computes the Net - private fun computeNet() { + private fun computeNet(withBuyin: Boolean? = null) { val transactionsSum = transactions.sumByDouble { it.amount } - val isLive = this.session?.isLive ?: true - if (isLive) { + // choose the method to compute the net + var useBuyin = withBuyin ?: true + if (withBuyin == null) { + if (netResult != null) { + useBuyin = false + } else if (buyin != null || cashout != null) { + useBuyin = true + } else { + this.session?.let { session -> + if (session.isCashGame() && !session.isLive) { + useBuyin = false + } + } + } + } + + if (useBuyin) { val buyin = this.buyin ?: 0.0 val cashOut = this.cashout ?: 0.0 this.net = cashOut - buyin + transactionsSum