Work on Session with tournament

feature/top10
Aurelien Hubert 7 years ago
parent 5374a9f605
commit 4aeb654104
  1. 243
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt

@ -181,6 +181,21 @@ open class Session : RealmObject(), SessionInterface, Savable,
return if (cgSmallBlind == null) "--" else "${cgSmallBlind?.toCurrency()}/${cgBigBlind?.round()}" return if (cgSmallBlind == null) "--" else "${cgSmallBlind?.toCurrency()}/${cgBigBlind?.round()}"
} }
/**
* Return the game title
*/
fun getGameTitle(): String {
var gameTitle = ""
limit?.let {
gameTitle += Limit.values()[it].shortName + " "
}
if (game != null) {
gameTitle += game?.name
}
return if (gameTitle.isNotBlank()) gameTitle else "--"
}
/** /**
* Delete the object from realm * Delete the object from realm
* TODO: Cascade delete? * TODO: Cascade delete?
@ -214,21 +229,6 @@ open class Session : RealmObject(), SessionInterface, Savable,
} }
} }
} }
}
/**
* Return the game title
*/
fun getGameTitle(): String {
var gameTitle = ""
limit?.let {
gameTitle += Limit.values()[it].shortName + " "
}
if (game != null) {
gameTitle += game?.name
}
return if (gameTitle.isNotBlank()) gameTitle else "--"
} }
@Ignore // SessionInterface value @Ignore // SessionInterface value
@ -285,25 +285,39 @@ open class Session : RealmObject(), SessionInterface, Savable,
// Headers // Headers
when (getState()) { when (getState()) {
SessionState.STARTED -> { SessionState.STARTED -> {
rows.add(HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT, rows.add(
title = getDuration(), value = result?.net.toString())) HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString()
)
)
} }
SessionState.PAUSED -> { SessionState.PAUSED -> {
rows.add(HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT, rows.add(
resId = R.string.pause, value = result?.net.toString())) HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.pause, value = result?.net.toString()
)
)
} }
SessionState.FINISHED -> { SessionState.FINISHED -> {
rows.add( rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT, HeaderRowRepresentable(
title = getDuration(), value = result?.net.toString()) RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString()
)
) )
rows.add( rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_VALUE, HeaderRowRepresentable(
resId = R.string.hour_rate_without_pauses, value = result?.net.toString()) RowViewType.HEADER_TITLE_VALUE,
resId = R.string.hour_rate_without_pauses, value = result?.net.toString()
)
) )
rows.add( rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_VALUE, HeaderRowRepresentable(
resId = R.string.bankroll_variation, value = result?.net.toString()) RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation, value = result?.net.toString()
)
) )
} }
else -> { else -> {
@ -321,18 +335,22 @@ open class Session : RealmObject(), SessionInterface, Savable,
override fun stringForRow(row: RowRepresentable, context: Context): String { override fun stringForRow(row: RowRepresentable, context: Context): String {
return when (row) { return when (row) {
SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--" SessionRow.BANKROLL -> bankroll?.name ?: "--"
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
SessionRow.BLINDS -> getBlinds() SessionRow.BLINDS -> getBlinds()
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--"
SessionRow.GAME -> getGameTitle() SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: "--"
SessionRow.LOCATION -> location?.name ?: "--" SessionRow.LOCATION -> location?.name ?: "--"
SessionRow.BANKROLL -> bankroll?.name ?: "--" SessionRow.PLAYERS -> "TODO"
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: "--" SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: "--"
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--" SessionRow.PRIZE -> "TODO"
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--" SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--" SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--" SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: "--"
else -> "--" else -> "--"
} }
} }
@ -351,15 +369,20 @@ open class Session : RealmObject(), SessionInterface, Savable,
val data = ArrayList<RowRepresentableEditDescriptor>() val data = ArrayList<RowRepresentableEditDescriptor>()
when (row) { when (row) {
SessionRow.CASHED_OUT -> { SessionRow.BANKROLL -> {
// Add current bankroll and bankrolls list
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm)))
}
SessionRow.BLINDS -> {
data.add( data.add(
RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER) RowRepresentableEditDescriptor(
cgSmallBlind?.round(), R.string.smallblind, InputType.TYPE_CLASS_NUMBER
)
) )
}
SessionRow.INITIAL_BUY_IN -> {
data.add( data.add(
//TODO: Manage initial buy in RowRepresentableEditDescriptor(
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER) cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER
)
) )
} }
SessionRow.BUY_IN -> { SessionRow.BUY_IN -> {
@ -380,52 +403,62 @@ open class Session : RealmObject(), SessionInterface, Savable,
) )
) )
} }
SessionRow.TIPS -> { SessionRow.CASHED_OUT -> {
// Disable the buttons with value = 0, add current value & set the 2 edit texts data.add(
data.add(RowRepresentableEditDescriptor(cgSmallBlind ?: 0.0)) RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
data.add(RowRepresentableEditDescriptor(cgBigBlind ?: 0.0)) )
data.add(RowRepresentableEditDescriptor(result?.tips ?: 0.0))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
} }
SessionRow.TABLE_SIZE -> { SessionRow.COMMENT -> {
data.add(RowRepresentableEditDescriptor(tableSize)) data.add(RowRepresentableEditDescriptor(comment, R.string.comment, InputType.TYPE_CLASS_TEXT))
} }
SessionRow.GAME -> { SessionRow.GAME -> {
// Add current game & games list // Add current game & games list
data.add(RowRepresentableEditDescriptor(limit)) data.add(RowRepresentableEditDescriptor(limit))
data.add(RowRepresentableEditDescriptor(game, data = LiveData.GAME.items(realm))) data.add(RowRepresentableEditDescriptor(game, data = LiveData.GAME.items(realm)))
} }
SessionRow.INITIAL_BUY_IN -> {
data.add(
RowRepresentableEditDescriptor(tournamentEntryFee?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.LOCATION -> { SessionRow.LOCATION -> {
// Add current location and locations list // Add current location and locations list
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm))) data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm)))
} }
SessionRow.BANKROLL -> { //TODO
// Add current bankroll and bankrolls list SessionRow.PLAYERS -> {
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm))) data.add(
} RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
SessionRow.TOURNAMENT_TYPE -> { )
// Add current tournament type and tournament types list
data.add(RowRepresentableEditDescriptor(tournamentType, data = LiveData.TOURNAMENT_TYPE.items(realm)))
} }
SessionRow.BLINDS -> { SessionRow.POSITION -> {
data.add( data.add(
RowRepresentableEditDescriptor( RowRepresentableEditDescriptor(
cgSmallBlind?.round(), result?.tournamentFinalPosition,
R.string.smallblind, inputType = InputType.TYPE_CLASS_NUMBER
InputType.TYPE_CLASS_NUMBER
) )
) )
}
//TODO
SessionRow.PRIZE -> {
data.add( data.add(
RowRepresentableEditDescriptor( RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
cgBigBlind?.round(),
R.string.bigblind,
InputType.TYPE_CLASS_NUMBER
)
) )
} }
SessionRow.COMMENT -> { SessionRow.TABLE_SIZE -> {
data.add(RowRepresentableEditDescriptor(comment, R.string.comment, InputType.TYPE_CLASS_TEXT)) data.add(RowRepresentableEditDescriptor(tableSize))
}
SessionRow.TIPS -> {
// Disable the buttons with value = 0, add current value & set the 2 edit texts
data.add(RowRepresentableEditDescriptor(cgSmallBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(cgBigBlind ?: 0.0))
data.add(RowRepresentableEditDescriptor(result?.tips ?: 0.0))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
data.add(RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER))
}
SessionRow.TOURNAMENT_TYPE -> {
// Add current tournament type and tournament types list
data.add(RowRepresentableEditDescriptor(tournamentType, data = LiveData.TOURNAMENT_TYPE.items(realm)))
} }
} }
@ -435,6 +468,29 @@ open class Session : RealmObject(), SessionInterface, Savable,
override fun updateValue(value: Any?, row: RowRepresentable) { override fun updateValue(value: Any?, row: RowRepresentable) {
realm.beginTransaction() realm.beginTransaction()
when (row) { when (row) {
SessionRow.BANKROLL -> bankroll = value as Bankroll?
SessionRow.BLINDS -> if (value is ArrayList<*>) {
cgSmallBlind = try {
(value[0] as String? ?: "0").toDouble()
} catch (e: Exception) {
null
}
cgBigBlind = try {
(value[1] as String? ?: "0").toDouble()
} catch (e: Exception) {
null
}
cgBigBlind?.let {
if (cgSmallBlind == null || cgSmallBlind == 0.0) {
cgSmallBlind = it / 2.0
}
}
} else if (value == null) {
cgSmallBlind = null
cgBigBlind = null
}
SessionRow.BUY_IN -> { SessionRow.BUY_IN -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.buyin = value as Double? localResult.buyin = value as Double?
@ -445,12 +501,14 @@ open class Session : RealmObject(), SessionInterface, Savable,
localResult.cashout = if (value == null) null else (value as String).toDouble() localResult.cashout = if (value == null) null else (value as String).toDouble()
result = localResult result = localResult
} }
SessionRow.TIPS -> { SessionRow.COMMENT -> comment = value as String? ?: ""
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.tips = value as Double? SessionRow.END_DATE -> if (value is Date?) {
result = localResult val timeFrameToUpdate =
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
timeFrameToUpdate.setDate(null, value)
timeFrame = timeFrameToUpdate
} }
SessionRow.TABLE_SIZE -> tableSize = value as Int?
SessionRow.GAME -> { SessionRow.GAME -> {
if (value is ArrayList<*>) { if (value is ArrayList<*>) {
limit = try { limit = try {
@ -465,32 +523,15 @@ open class Session : RealmObject(), SessionInterface, Savable,
} }
} }
} }
SessionRow.BANKROLL -> bankroll = value as Bankroll? SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble()
SessionRow.LOCATION -> location = value as Location? SessionRow.LOCATION -> location = value as Location?
SessionRow.COMMENT -> comment = value as String? ?: "" SessionRow.PLAYERS -> ""//TODO
SessionRow.BLINDS -> if (value is ArrayList<*>) { SessionRow.POSITION -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
cgSmallBlind = try { localResult.tournamentFinalPosition = if (value == null) null else (value as String).toInt()
(value[0] as String? ?: "0").toDouble() result = localResult
} catch (e: Exception) {
null
}
cgBigBlind = try {
(value[1] as String? ?: "0").toDouble()
} catch (e: Exception) {
null
}
cgBigBlind?.let {
if (cgSmallBlind == null || cgSmallBlind == 0.0) {
cgSmallBlind = it / 2.0
}
}
} else if (value == null) {
cgSmallBlind = null
cgBigBlind = null
} }
SessionRow.TOURNAMENT_TYPE -> tournamentType = value as TournamentType? SessionRow.PRIZE -> ""//TODO
SessionRow.START_DATE -> if (value is Date?) { SessionRow.START_DATE -> if (value is Date?) {
if (value == null) { if (value == null) {
timeFrame = null timeFrame = null
@ -501,12 +542,14 @@ open class Session : RealmObject(), SessionInterface, Savable,
timeFrame = timeFrameToUpdate timeFrame = timeFrameToUpdate
} }
} }
SessionRow.END_DATE -> if (value is Date?) { SessionRow.TABLE_SIZE -> tableSize = value as Int?
val timeFrameToUpdate = SessionRow.TIPS -> {
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java) val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
timeFrameToUpdate.setDate(null, value) localResult.tips = value as Double?
timeFrame = timeFrameToUpdate result = localResult
} }
SessionRow.TOURNAMENT_TYPE -> tournamentType = value as TournamentType?
} }
realm.commitTransaction() realm.commitTransaction()
} }

@ -28,7 +28,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SessionRow import net.pokeranalytics.android.ui.view.SessionRow
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.util.toast import net.pokeranalytics.android.util.toast
import timber.log.Timber
import java.util.* import java.util.*
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate { class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate {
@ -254,8 +253,6 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
recyclerView.adapter = sessionAdapter recyclerView.adapter = sessionAdapter
updateSessionUI() updateSessionUI()
Timber.d("Session state: ${currentSession.getState()}")
Timber.d("Result: ${currentSession.result}")
} }
} }

@ -200,7 +200,7 @@ enum class SessionRow : RowRepresentable {
override val bottomSheetType: BottomSheetType override val bottomSheetType: BottomSheetType
get() { get() {
return when (this) { return when (this) {
CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME -> BottomSheetType.EDIT_TEXT CASHED_OUT, INITIAL_BUY_IN, BREAK_TIME, POSITION, PLAYERS, PRIZE -> BottomSheetType.EDIT_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME GAME -> BottomSheetType.LIST_GAME

Loading…
Cancel
Save