Set Session Type as enum

feature/top10
Aurelien Hubert 7 years ago
parent 24fa8e530b
commit 7b40862bbb
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/extensions/SessionExtensions.kt
  2. 24
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  5. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt

@ -18,7 +18,7 @@ enum class SessionState {
fun Session.getState(): SessionState { fun Session.getState(): SessionState {
if (timeFrame == null) { if (timeFrame == null) {
return SessionState.INVALID return SessionState.PENDING
} }
val endDate = timeFrame?.endDate val endDate = timeFrame?.endDate

@ -27,18 +27,12 @@ import kotlin.collections.ArrayList
open class Session : RealmObject(), SessionInterface, Savable, open class Session : RealmObject(), SessionInterface, Savable,
RowRepresentableDataSource, RowRepresentable { RowRepresentableDataSource, RowRepresentable {
enum class Type { enum class Type {
CASH_GAME, CASH_GAME,
TOURNAMENT TOURNAMENT
} }
companion object { companion object {
// Type: cash game = 0, tournament = 1
const val TYPE_GAME = 0
const val TYPE_TOURNAMENT = 1
fun newInstance(): Session { fun newInstance(): Session {
val session = Session() val session = Session()
session.result = Result() session.result = Result()
@ -53,7 +47,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
/** /**
* Indicates the type of session, cash game or tournament * Indicates the type of session, cash game or tournament
*/ */
var type: Int = TYPE_GAME var type: Int = Type.CASH_GAME.ordinal
// The result of the main user // The result of the main user
var result: Result? = null var result: Result? = null
@ -123,6 +117,20 @@ open class Session : RealmObject(), SessionInterface, Savable,
// The features of the tournament, like Knockout, Shootout, Turbo... // The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
/**
* Return if this session is a tournament
*/
fun isTournament(): Boolean {
return type == Type.TOURNAMENT.ordinal
}
/**
* Return if this session is a cash game
*/
fun isCashGame(): Boolean {
return type == Type.CASH_GAME.ordinal
}
/** /**
* Start a session * Start a session
*/ */
@ -336,7 +344,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
) )
) )
if (type == TYPE_GAME) { if (!isTournament()) {
rows.add( rows.add(
HeaderRowRepresentable( HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE, RowViewType.HEADER_TITLE_VALUE,

@ -281,12 +281,12 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
} else { } else {
realm.beginTransaction() realm.beginTransaction()
currentSession = realm.createObject(Session::class.java, UUID.randomUUID().toString()) currentSession = realm.createObject(Session::class.java, UUID.randomUUID().toString())
currentSession.type = if (isTournament) Session.TYPE_TOURNAMENT else Session.TYPE_GAME currentSession.type = if (isTournament) Session.Type.TOURNAMENT.ordinal else Session.Type.CASH_GAME.ordinal
realm.commitTransaction() realm.commitTransaction()
} }
toolbar.title = toolbar.title =
if (currentSession.type == Session.TYPE_TOURNAMENT) getString(R.string.tournament) else getString(R.string.cash_game) if (currentSession.isTournament()) getString(R.string.tournament) else getString(R.string.cash_game)
sessionAdapter = RowRepresentableAdapter(currentSession, this) sessionAdapter = RowRepresentableAdapter(currentSession, this)
recyclerView.adapter = sessionAdapter recyclerView.adapter = sessionAdapter

@ -96,7 +96,7 @@ class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource {
val tSessions = mutableListOf<Session>() val tSessions = mutableListOf<Session>()
allSessions.forEach { session -> allSessions.forEach { session ->
if (session.type == Session.Type.CASH_GAME.ordinal) { if (session.isCashGame()) {
cgSessions.add(session) cgSessions.add(session)
} else { } else {
tSessions.add(session) tSessions.add(session)

@ -64,7 +64,7 @@ class SessionRowView : FrameLayout {
// Title / Game type // Title / Game type
var title = "" var title = ""
if (session.type == Session.TYPE_TOURNAMENT) { if (session.isTournament()) {
if (session.tournamentEntryFee != null) { if (session.tournamentEntryFee != null) {
title += session.tournamentEntryFee?.toCurrency() title += session.tournamentEntryFee?.toCurrency()
} }
@ -76,7 +76,7 @@ class SessionRowView : FrameLayout {
title = context.getString(R.string.tournament).capitalize() title = context.getString(R.string.tournament).capitalize()
} }
} else if (session.type == Session.TYPE_GAME) { } else {
if (session.cgSmallBlind != null && session.cgBigBlind != null) { if (session.cgSmallBlind != null && session.cgBigBlind != null) {
title += session.getBlinds() title += session.getBlinds()
} }

@ -36,7 +36,7 @@ enum class SessionRow : RowRepresentable {
*/ */
fun getRows(type: Int, sessionState: SessionState): ArrayList<RowRepresentable> { fun getRows(type: Int, sessionState: SessionState): ArrayList<RowRepresentable> {
when (type) { when (type) {
Session.TYPE_TOURNAMENT -> { Session.Type.TOURNAMENT.ordinal -> {
return when (sessionState) { return when (sessionState) {
SessionState.PENDING -> { SessionState.PENDING -> {
arrayListOf( arrayListOf(
@ -54,7 +54,7 @@ enum class SessionRow : RowRepresentable {
else -> arrayListOf() else -> arrayListOf()
} }
} }
Session.TYPE_GAME -> { Session.Type.CASH_GAME.ordinal -> {
return when (sessionState) { return when (sessionState) {
SessionState.PENDING -> { SessionState.PENDING -> {
arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE) arrayListOf(GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE)

Loading…
Cancel
Save