Code refactoring

feature/top10
Laurent 7 years ago
parent 0de04343ba
commit 6dba82a895
  1. 111
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt

@ -12,6 +12,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.exceptions.ModelException
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.TableSize
@ -19,6 +20,7 @@ import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.interfaces.Savable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
@ -62,7 +64,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
var timeFrame: TimeFrame? = null
set(value) {
field = value
// value?.let { it.notifySessionDateChange(this) }
value?.let { it.notifySessionDateChange(this) }
}
// The time frame sessionGroup, which can contain multiple sessions
@ -137,6 +139,66 @@ open class Session : RealmObject(), SessionInterface, Savable,
return type == Type.CASH_GAME.ordinal
}
@Ignore // SessionInterface value
override var value: Double = 0.0
get() {
return this.result?.net ?: 0.0
}
@Ignore
override var estimatedHands: Double = 25.0 * (this.timeFrame?.hourlyDuration ?: 0.0)
@Ignore
override var bbNetResult: Double = 0.0
get() {
this.cgBigBlind?.let { bb ->
this.result?.let { result ->
return result.net / bb
}
}
return 0.0
}
@Ignore
override var bbPer100Hands: Double = 0.0
get() {
return this.bbNetResult / this.estimatedHands * 100.0
}
@Ignore
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
@Ignore
override var buyin: Double = 0.0
get() {
this.result?.let {
it.buyin?.let {
return it
}
}
return 0.0
}
@Ignore
var netDuration: Long = 0L
get() {
this.timeFrame?.let {
return it.netDuration
}
return 0L
}
@Ignore
var hourlyRate: Double = 0.0
get() {
this.result?.let { result ->
return result.net / this.netDuration.toDouble()
}
throw ModelException("Session should have an existing Result relationship")
}
// States
/**
* Start or continue a session
*/
@ -202,6 +264,8 @@ open class Session : RealmObject(), SessionInterface, Savable,
}
}
// Formatters
/**
* Return the netDuration of the current session
*/
@ -232,6 +296,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
return if (gameTitle.isNotBlank()) gameTitle else NULL_TEXT
}
// LifeCycle
/**
* Delete the object from realm
@ -268,46 +333,6 @@ open class Session : RealmObject(), SessionInterface, Savable,
}
}
@Ignore // SessionInterface value
override var value: Double = 0.0
get() {
return this.result?.net ?: 0.0
}
@Ignore
override var estimatedHands: Double = 25.0 * (this.timeFrame?.hourlyDuration ?: 0.0)
@Ignore
override var bbNetResult: Double = 0.0
get() {
this.cgBigBlind?.let { bb ->
this.result?.let { result ->
return result.net / bb
}
}
return 0.0
}
@Ignore
override var bbPer100Hands: Double = 0.0
get() {
return this.bbNetResult / this.estimatedHands * 100.0
}
@Ignore
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
@Ignore
override var buyin: Double = 0.0
get() {
this.result?.let {
it.buyin?.let {
return it
}
}
return 0.0
}
@Ignore
override val viewType: Int = RowViewType.ROW_SESSION.ordinal
@ -356,7 +381,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.hour_rate_without_pauses,
computedStat = ComputedStat(Stat.NETRESULT, this.sessionSet?.hourlyRate ?: 0.0)
computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate ?: 0.0)
)
)
@ -408,7 +433,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT
else -> NULL_TEXT
else -> throw UnmanagedRowRepresentableException("Unmanaged row = ${row.getDisplayName()}")
}
}

Loading…
Cancel
Save