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 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
* 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
@ -285,25 +285,39 @@ open class Session : RealmObject(), SessionInterface, Savable,
// Headers
when (getState()) {
SessionState.STARTED -> {
rows.add(HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString()))
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString()
)
)
}
SessionState.PAUSED -> {
rows.add(HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.pause, value = result?.net.toString()))
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.pause, value = result?.net.toString()
)
)
}
SessionState.FINISHED -> {
rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString())
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
title = getDuration(), value = result?.net.toString()
)
)
rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_VALUE,
resId = R.string.hour_rate_without_pauses, value = result?.net.toString())
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE,
resId = R.string.hour_rate_without_pauses, value = result?.net.toString()
)
)
rows.add(
HeaderRowRepresentable(RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation, value = result?.net.toString())
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation, value = result?.net.toString()
)
)
}
else -> {
@ -321,18 +335,22 @@ open class Session : RealmObject(), SessionInterface, Savable,
override fun stringForRow(row: RowRepresentable, context: Context): String {
return when (row) {
SessionRow.CASHED_OUT -> result?.cashout?.toCurrency() ?: "--"
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
SessionRow.BANKROLL -> bankroll?.name ?: "--"
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.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: "--"
SessionRow.LOCATION -> location?.name ?: "--"
SessionRow.BANKROLL -> bankroll?.name ?: "--"
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: "--"
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--"
SessionRow.PLAYERS -> "TODO"
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: "--"
SessionRow.PRIZE -> "TODO"
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--"
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: "--"
else -> "--"
}
}
@ -351,15 +369,20 @@ open class Session : RealmObject(), SessionInterface, Savable,
val data = ArrayList<RowRepresentableEditDescriptor>()
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(
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(
//TODO: Manage initial buy in
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
RowRepresentableEditDescriptor(
cgBigBlind?.round(), R.string.bigblind, InputType.TYPE_CLASS_NUMBER
)
)
}
SessionRow.BUY_IN -> {
@ -380,52 +403,62 @@ open class Session : RealmObject(), SessionInterface, Savable,
)
)
}
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.CASHED_OUT -> {
data.add(
RowRepresentableEditDescriptor(result?.cashout?.round(), inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.TABLE_SIZE -> {
data.add(RowRepresentableEditDescriptor(tableSize))
SessionRow.COMMENT -> {
data.add(RowRepresentableEditDescriptor(comment, R.string.comment, InputType.TYPE_CLASS_TEXT))
}
SessionRow.GAME -> {
// Add current game & games list
data.add(RowRepresentableEditDescriptor(limit))
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 -> {
// Add current location and locations list
data.add(RowRepresentableEditDescriptor(location, data = LiveData.LOCATION.items(realm)))
}
SessionRow.BANKROLL -> {
// Add current bankroll and bankrolls list
data.add(RowRepresentableEditDescriptor(bankroll, data = LiveData.BANKROLL.items(realm)))
}
SessionRow.TOURNAMENT_TYPE -> {
// Add current tournament type and tournament types list
data.add(RowRepresentableEditDescriptor(tournamentType, data = LiveData.TOURNAMENT_TYPE.items(realm)))
//TODO
SessionRow.PLAYERS -> {
data.add(
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.BLINDS -> {
SessionRow.POSITION -> {
data.add(
RowRepresentableEditDescriptor(
cgSmallBlind?.round(),
R.string.smallblind,
InputType.TYPE_CLASS_NUMBER
result?.tournamentFinalPosition,
inputType = InputType.TYPE_CLASS_NUMBER
)
)
}
//TODO
SessionRow.PRIZE -> {
data.add(
RowRepresentableEditDescriptor(
cgBigBlind?.round(),
R.string.bigblind,
InputType.TYPE_CLASS_NUMBER
)
RowRepresentableEditDescriptor("", inputType = InputType.TYPE_CLASS_NUMBER)
)
}
SessionRow.COMMENT -> {
data.add(RowRepresentableEditDescriptor(comment, R.string.comment, InputType.TYPE_CLASS_TEXT))
SessionRow.TABLE_SIZE -> {
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) {
realm.beginTransaction()
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 -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
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()
result = localResult
}
SessionRow.TIPS -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.tips = value as Double?
result = localResult
SessionRow.COMMENT -> comment = value as String? ?: ""
SessionRow.END_DATE -> if (value is Date?) {
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 -> {
if (value is ArrayList<*>) {
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.COMMENT -> comment = value as String? ?: ""
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.PLAYERS -> ""//TODO
SessionRow.POSITION -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.tournamentFinalPosition = if (value == null) null else (value as String).toInt()
result = localResult
}
SessionRow.TOURNAMENT_TYPE -> tournamentType = value as TournamentType?
SessionRow.PRIZE -> ""//TODO
SessionRow.START_DATE -> if (value is Date?) {
if (value == null) {
timeFrame = null
@ -501,12 +542,14 @@ open class Session : RealmObject(), SessionInterface, Savable,
timeFrame = timeFrameToUpdate
}
}
SessionRow.END_DATE -> if (value is Date?) {
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.TIPS -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.tips = value as Double?
result = localResult
}
SessionRow.TOURNAMENT_TYPE -> tournamentType = value as TournamentType?
}
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.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.util.toast
import timber.log.Timber
import java.util.*
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate {
@ -254,8 +253,6 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
recyclerView.adapter = sessionAdapter
updateSessionUI()
Timber.d("Session state: ${currentSession.getState()}")
Timber.d("Result: ${currentSession.result}")
}
}

@ -200,7 +200,7 @@ enum class SessionRow : RowRepresentable {
override val bottomSheetType: BottomSheetType
get() {
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
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST_GAME

Loading…
Cancel
Save