|
|
|
|
@ -28,7 +28,7 @@ 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 |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable |
|
|
|
|
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.* |
|
|
|
|
@ -36,6 +36,8 @@ import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import java.util.* |
|
|
|
|
import java.util.Currency |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
import kotlin.properties.Delegates |
|
|
|
|
import kotlin.reflect.KProperty |
|
|
|
|
|
|
|
|
|
open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepresentableDataSource, RowRepresentable, |
|
|
|
|
Timed { |
|
|
|
|
@ -46,17 +48,21 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean): Session { |
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null): Session { |
|
|
|
|
val session = Session() |
|
|
|
|
session.result = Result() |
|
|
|
|
session.bankroll = realm.where<Bankroll>().findFirst() |
|
|
|
|
if (bankroll != null) { |
|
|
|
|
session.bankroll = bankroll |
|
|
|
|
} else { |
|
|
|
|
session.bankroll = realm.where<Bankroll>().findFirst() |
|
|
|
|
} |
|
|
|
|
session.type = if (isTournament) Session.Type.TOURNAMENT.ordinal else Session.Type.CASH_GAME.ordinal |
|
|
|
|
return realm.copyToRealm(session) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
|
var id = UUID.randomUUID().toString() |
|
|
|
|
override var id = UUID.randomUUID().toString() |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates the type of session, cash game or tournament |
|
|
|
|
@ -110,6 +116,11 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
* The start date of the break |
|
|
|
|
*/ |
|
|
|
|
override var pauseDate: Date? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The time frame of the Session, i.e. the start & end date |
|
|
|
|
// var timeFrame: TimeFrame? = null |
|
|
|
|
@ -186,6 +197,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
} else if (this.sessionSet != null) { |
|
|
|
|
SessionSetManager.removeFromTimeline(this) |
|
|
|
|
} |
|
|
|
|
this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -224,22 +236,6 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
return this.result?.net ?: 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
public var numberOfHandsPerHour: Double { |
|
|
|
|
|
|
|
|
|
var playersHandsPerHour: Int = Session.livePlayersHandsPerHour // default is live |
|
|
|
|
if let bankroll = self.bankroll { |
|
|
|
|
playersHandsPerHour = bankroll.isLive() ? Session.livePlayersHandsPerHour : Session.onlinePlayersHandsPerHour |
|
|
|
|
} |
|
|
|
|
var numberOfPlayers: Int = 9 // default is 9 players |
|
|
|
|
if let playersAtTable = self.tableSize?.intValue { |
|
|
|
|
numberOfPlayers = playersAtTable |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Double(playersHandsPerHour) / Double(numberOfPlayers) |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
val ONLINE_PLAYER_HANDS_PER_HOUR = 400.0 |
|
|
|
|
@Ignore |
|
|
|
|
@ -250,7 +246,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
*/ |
|
|
|
|
val numberOfHandsPerHour: Double |
|
|
|
|
get() { |
|
|
|
|
val tableSize = this.tableSize ?: 9 |
|
|
|
|
val tableSize = this.tableSize ?: 9 // 9 is the default table size if null |
|
|
|
|
val isLive = this.bankroll?.live ?: true |
|
|
|
|
val playerHandsPerHour = if (isLive) LIVE_PLAYER_HANDS_PER_HOUR else ONLINE_PLAYER_HANDS_PER_HOUR |
|
|
|
|
return playerHandsPerHour / tableSize.toDouble() |
|
|
|
|
@ -461,22 +457,21 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
@Ignore |
|
|
|
|
override val viewType: Int = RowViewType.ROW_SESSION.ordinal |
|
|
|
|
|
|
|
|
|
override fun uniqueIdentifier(): String { |
|
|
|
|
return this.id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getDisplayName(): String { |
|
|
|
|
return "Session ${this.creationDate}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
@Ignore |
|
|
|
|
private var rowRepresentationForCurrentState : List<RowRepresentable> = this.updatedRowRepresentationForCurrentState() |
|
|
|
|
|
|
|
|
|
private fun updatedRowRepresentationForCurrentState(): List<RowRepresentable> { |
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
|
|
|
|
|
// Headers |
|
|
|
|
when (getState()) { |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
rows.add( |
|
|
|
|
HeaderRowRepresentable( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
title = getFormattedDuration(), |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
|
@ -486,7 +481,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
} |
|
|
|
|
SessionState.PAUSED -> { |
|
|
|
|
rows.add( |
|
|
|
|
HeaderRowRepresentable( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
resId = R.string.pause, |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
|
@ -496,33 +491,29 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
} |
|
|
|
|
SessionState.FINISHED -> { |
|
|
|
|
rows.add( |
|
|
|
|
HeaderRowRepresentable( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
|
title = getFormattedDuration(), |
|
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
rows.add( |
|
|
|
|
HeaderRowRepresentable( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_AMOUNT, |
|
|
|
|
resId = R.string.hour_rate_without_pauses, |
|
|
|
|
computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
//TODO V2: Add Bankroll variation |
|
|
|
|
/* |
|
|
|
|
if (!isTournament()) { |
|
|
|
|
rows.add( |
|
|
|
|
HeaderRowRepresentable( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.HEADER_TITLE_VALUE, |
|
|
|
|
resId = R.string.bankroll_variation, |
|
|
|
|
computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
rows.add(SeparatorRowRepresentable()) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
@ -534,6 +525,15 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateRowRepresentation() { |
|
|
|
|
this.rowRepresentationForCurrentState = this.updatedRowRepresentationForCurrentState() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
return this.rowRepresentationForCurrentState |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: RowRepresentable): Boolean { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|