|
|
|
|
@ -1,158 +1,179 @@ |
|
|
|
|
package net.pokeranalytics.android.model.realm |
|
|
|
|
|
|
|
|
|
import android.text.InputType |
|
|
|
|
import io.realm.* |
|
|
|
|
import io.realm.annotations.Ignore |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import net.pokeranalytics.android.calculus.SessionInterface |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.DynamicRowDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.SessionRow |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.* |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.BottomSheetData |
|
|
|
|
import net.pokeranalytics.android.util.data.sessionDao |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, DisplayableDataSource { |
|
|
|
|
open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, DisplayableDataSource, EditableDataSource { |
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
|
var id = UUID.randomUUID().toString() |
|
|
|
|
@PrimaryKey |
|
|
|
|
var id = UUID.randomUUID().toString() |
|
|
|
|
|
|
|
|
|
// The result of the main user |
|
|
|
|
var result: Result? = null |
|
|
|
|
// The result of the main user |
|
|
|
|
var result: Result? = null |
|
|
|
|
|
|
|
|
|
// The time frame of the Session, i.e. the start & end date |
|
|
|
|
var timeFrame: TimeFrame? = null |
|
|
|
|
// The time frame of the Session, i.e. the start & end date |
|
|
|
|
var timeFrame: TimeFrame? = null |
|
|
|
|
|
|
|
|
|
// The time frame sessionGroup, which can contain multiple sessions |
|
|
|
|
override var sessionSet: SessionSet? = null |
|
|
|
|
// The time frame sessionGroup, which can contain multiple sessions |
|
|
|
|
override var sessionSet: SessionSet? = null |
|
|
|
|
|
|
|
|
|
// the date of creation of the app |
|
|
|
|
var creationDate: Date = Date() |
|
|
|
|
// the date of creation of the app |
|
|
|
|
var creationDate: Date = Date() |
|
|
|
|
|
|
|
|
|
// The bankroll hosting the results |
|
|
|
|
var bankroll: Bankroll? = null |
|
|
|
|
// The bankroll hosting the results |
|
|
|
|
var bankroll: Bankroll? = null |
|
|
|
|
|
|
|
|
|
// The limit type: NL, PL... |
|
|
|
|
var limit: Int? = null |
|
|
|
|
// The limit type: NL, PL... |
|
|
|
|
var limit: Int? = null |
|
|
|
|
|
|
|
|
|
// The game played during the Session |
|
|
|
|
var game: Game? = null |
|
|
|
|
// The game played during the Session |
|
|
|
|
var game: Game? = null |
|
|
|
|
|
|
|
|
|
// The number of players at the table |
|
|
|
|
var tableSize: Int? = null |
|
|
|
|
// The number of players at the table |
|
|
|
|
var tableSize: Int? = null |
|
|
|
|
|
|
|
|
|
// the location where the session is played |
|
|
|
|
var location: Location? = null |
|
|
|
|
// the location where the session is played |
|
|
|
|
var location: Location? = null |
|
|
|
|
|
|
|
|
|
// The number of tables played at the same time |
|
|
|
|
var numberOfTables: Int = 1 |
|
|
|
|
// The number of tables played at the same time |
|
|
|
|
var numberOfTables: Int = 1 |
|
|
|
|
|
|
|
|
|
// The hands list associated with the Session |
|
|
|
|
var hands: RealmList<HandHistory> = RealmList() |
|
|
|
|
// The hands list associated with the Session |
|
|
|
|
var hands: RealmList<HandHistory> = RealmList() |
|
|
|
|
|
|
|
|
|
// The list of opponents who participated to the session |
|
|
|
|
var opponents: RealmList<Player> = RealmList() |
|
|
|
|
// The list of opponents who participated to the session |
|
|
|
|
var opponents: RealmList<Player> = RealmList() |
|
|
|
|
|
|
|
|
|
// A comment written by the user |
|
|
|
|
var comment: String = "" |
|
|
|
|
// A comment written by the user |
|
|
|
|
var comment: String = "" |
|
|
|
|
|
|
|
|
|
// Cash Game |
|
|
|
|
// Cash Game |
|
|
|
|
|
|
|
|
|
// The small blind value |
|
|
|
|
var cgSmallBlind: Double? = null |
|
|
|
|
// The small blind value |
|
|
|
|
var cgSmallBlind: Double? = null |
|
|
|
|
|
|
|
|
|
// The big blind value |
|
|
|
|
var cgBigBlind: Double? = null |
|
|
|
|
// The big blind value |
|
|
|
|
var cgBigBlind: Double? = null |
|
|
|
|
|
|
|
|
|
// Tournament |
|
|
|
|
// Tournament |
|
|
|
|
|
|
|
|
|
// The entry fee of the tournament |
|
|
|
|
var tournamentEntryFee: Double? = null |
|
|
|
|
// The entry fee of the tournament |
|
|
|
|
var tournamentEntryFee: Double? = null |
|
|
|
|
|
|
|
|
|
// The total number of players who participated in the tournament |
|
|
|
|
var tournamentNumberOfPlayers: Int? = null |
|
|
|
|
// The total number of players who participated in the tournament |
|
|
|
|
var tournamentNumberOfPlayers: Int? = null |
|
|
|
|
|
|
|
|
|
// The name of the tournament |
|
|
|
|
var tournamentType: TournamentName? = null |
|
|
|
|
// The name of the tournament |
|
|
|
|
var tournamentType: TournamentName? = null |
|
|
|
|
|
|
|
|
|
// The kind of the tournament, MTT or SnG |
|
|
|
|
var tournamentKind: Int? = null |
|
|
|
|
// The kind of the tournament, MTT or SnG |
|
|
|
|
var tournamentKind: Int? = null |
|
|
|
|
|
|
|
|
|
// The features of the tournament, like Knockout, Shootout, Turbo... |
|
|
|
|
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() |
|
|
|
|
// The features of the tournament, like Knockout, Shootout, Turbo... |
|
|
|
|
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
fun newInstance(): Session { |
|
|
|
|
var session: Session = Session() |
|
|
|
|
session.result = Result() |
|
|
|
|
session.timeFrame = TimeFrame() |
|
|
|
|
return session |
|
|
|
|
} |
|
|
|
|
fun newInstance(): Session { |
|
|
|
|
var session: Session = Session() |
|
|
|
|
session.result = Result() |
|
|
|
|
session.timeFrame = TimeFrame() |
|
|
|
|
return session |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore // SessionInterface value |
|
|
|
|
override var value: Double = 0.0 |
|
|
|
|
get() { |
|
|
|
|
return this.result?.net ?: 0.0 |
|
|
|
|
} |
|
|
|
|
@Ignore // SessionInterface value |
|
|
|
|
override var value: Double = 0.0 |
|
|
|
|
get() { |
|
|
|
|
return this.result?.net ?: 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
override var estimatedHands: Double = 0.0 |
|
|
|
|
@Ignore |
|
|
|
|
override var estimatedHands: Double = 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 bbNetResult: Double = 0.0 |
|
|
|
|
get() { |
|
|
|
|
this.cgBigBlind?.let { bb -> |
|
|
|
|
this.result?.let { result -> |
|
|
|
|
return result.net / bb |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 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 var buyin: Double = 0.0 |
|
|
|
|
get() { |
|
|
|
|
this.result?.let { |
|
|
|
|
it.buyin?.let { |
|
|
|
|
return it |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): ArrayList<DynamicRowInterface> { |
|
|
|
|
val rows = ArrayList<DynamicRowInterface>() |
|
|
|
|
rows.addAll(SessionRow.values()) |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: DynamicRowInterface): Boolean { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: DynamicRowInterface): String { |
|
|
|
|
return when (row) { |
|
|
|
|
SessionRow.BLINDS -> "Blinds" |
|
|
|
|
SessionRow.GAME -> "Game" |
|
|
|
|
SessionRow.DATE -> "Date" |
|
|
|
|
else -> "--" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override var title: String = "Change that: $creationDate" |
|
|
|
|
override fun adapterRows(): ArrayList<DynamicRowInterface> { |
|
|
|
|
val rows = ArrayList<DynamicRowInterface>() |
|
|
|
|
rows.addAll(SessionRow.values()) |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: DynamicRowInterface): Boolean { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: DynamicRowInterface): String { |
|
|
|
|
return when (row) { |
|
|
|
|
SessionRow.BLINDS -> "Blinds" |
|
|
|
|
SessionRow.GAME -> "Game" |
|
|
|
|
SessionRow.DATE -> "Date" |
|
|
|
|
else -> "--" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override var title: String = "Change that: $creationDate" |
|
|
|
|
|
|
|
|
|
override fun getBottomSheetData(row: DynamicRowInterface): ArrayList<BottomSheetData> { |
|
|
|
|
|
|
|
|
|
val data = ArrayList<BottomSheetData>() |
|
|
|
|
|
|
|
|
|
// Todo: Localize & set real data |
|
|
|
|
when (row) { |
|
|
|
|
SessionRow.GAME -> { |
|
|
|
|
data.add(BottomSheetData("Game", game, "", 0, arrayListOf(Game(), Game(), Game()))) |
|
|
|
|
} |
|
|
|
|
SessionRow.DATE -> { |
|
|
|
|
data.add(BottomSheetData("Date", timeFrame?.startDate, "Start date")) |
|
|
|
|
data.add(BottomSheetData("Date", timeFrame?.endDate, "End date")) |
|
|
|
|
} |
|
|
|
|
SessionRow.BLINDS -> { |
|
|
|
|
data.add(BottomSheetData("Blind", cgSmallBlind, "Small blind", InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
data.add(BottomSheetData("Blind", cgBigBlind, "Big blind", InputType.TYPE_CLASS_NUMBER)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return data |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum class TournamentKind { |
|
|
|
|
MTT, |
|
|
|
|
SNG |
|
|
|
|
MTT, |
|
|
|
|
SNG |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -161,63 +182,63 @@ enum class TournamentKind { |
|
|
|
|
*/ |
|
|
|
|
class SessionDao(realmDb: Realm) { |
|
|
|
|
|
|
|
|
|
var realm: Realm = realmDb |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create or update session |
|
|
|
|
*/ |
|
|
|
|
fun createOrUpdateSession(session: Session): Session { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
val sessionToSave = realm.copyToRealmOrUpdate(session) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
return realm.copyFromRealm(sessionToSave) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create or update sessions |
|
|
|
|
*/ |
|
|
|
|
fun createOrUpdateSessions(sessions: List<Session>): List<Session> { |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
// Update |
|
|
|
|
val sessionsToSave = realm.copyToRealmOrUpdate(sessions) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
return realm.copyFromRealm(sessionsToSave) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Find all sessions |
|
|
|
|
*/ |
|
|
|
|
fun findAllSessions(): RealmResults<Session> { |
|
|
|
|
return realm.where(Session::class.java).findAll().sort("creationDate", Sort.DESCENDING) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Find session by id |
|
|
|
|
*/ |
|
|
|
|
fun findSessionById(sessionId: Int): Session? { |
|
|
|
|
return realm.copyFromRealm(realm.where(Session::class.java).equalTo("id", sessionId).findFirst()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete session |
|
|
|
|
*/ |
|
|
|
|
fun deleteSession(sessionId: Int) { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
realm.sessionDao().findSessionById(sessionId)?.deleteFromRealm() |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete all sessions |
|
|
|
|
*/ |
|
|
|
|
fun deleteAllSessions() { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
realm.sessionDao().findAllSessions().deleteAllFromRealm() |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
var realm: Realm = realmDb |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create or update session |
|
|
|
|
*/ |
|
|
|
|
fun createOrUpdateSession(session: Session): Session { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
val sessionToSave = realm.copyToRealmOrUpdate(session) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
return realm.copyFromRealm(sessionToSave) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create or update sessions |
|
|
|
|
*/ |
|
|
|
|
fun createOrUpdateSessions(sessions: List<Session>): List<Session> { |
|
|
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
|
|
// Update |
|
|
|
|
val sessionsToSave = realm.copyToRealmOrUpdate(sessions) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
|
|
return realm.copyFromRealm(sessionsToSave) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Find all sessions |
|
|
|
|
*/ |
|
|
|
|
fun findAllSessions(): RealmResults<Session> { |
|
|
|
|
return realm.where(Session::class.java).findAll().sort("creationDate", Sort.DESCENDING) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Find session by id |
|
|
|
|
*/ |
|
|
|
|
fun findSessionById(sessionId: Int): Session? { |
|
|
|
|
return realm.copyFromRealm(realm.where(Session::class.java).equalTo("id", sessionId).findFirst()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete session |
|
|
|
|
*/ |
|
|
|
|
fun deleteSession(sessionId: Int) { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
realm.sessionDao().findSessionById(sessionId)?.deleteFromRealm() |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete all sessions |
|
|
|
|
*/ |
|
|
|
|
fun deleteAllSessions() { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
realm.sessionDao().findAllSessions().deleteAllFromRealm() |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |