Improve currency mamangement for sessions and stats

feature/top10
Aurelien Hubert 7 years ago
parent 9e18a22d7f
commit 004093a170
  1. 21
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  2. 24
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  5. 15
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetMultiSelectionFragment.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetSumFragment.kt
  7. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt

@ -5,10 +5,11 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.FormattingException import net.pokeranalytics.android.exceptions.FormattingException
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.FormatUtils import net.pokeranalytics.android.util.CurrencyUtils
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.formatted import net.pokeranalytics.android.util.extensions.formatted
import net.pokeranalytics.android.util.extensions.formattedHourlyDuration import net.pokeranalytics.android.util.extensions.formattedHourlyDuration
import java.util.*
/** /**
* An enum representing all the types of Session statistics * An enum representing all the types of Session statistics
@ -99,7 +100,7 @@ enum class Stat : RowRepresentable {
/** /**
* ComputedStat contains a [stat] and their associated [value] * ComputedStat contains a [stat] and their associated [value]
*/ */
class ComputedStat(stat: Stat, value: Double) { class ComputedStat(var stat: Stat, var value: Double, var currency: Currency? = null) {
constructor(stat: Stat, value: Double, previousValue: Double?) : this(stat, value) { constructor(stat: Stat, value: Double, previousValue: Double?) : this(stat, value) {
if (previousValue != null) { if (previousValue != null) {
@ -107,16 +108,6 @@ class ComputedStat(stat: Stat, value: Double) {
} }
} }
/**
* The statistic type
*/
var stat: Stat = stat
/**
* The stat value
*/
var value: Double = value
/** /**
* The variation of the stat * The variation of the stat
*/ */
@ -135,7 +126,7 @@ class ComputedStat(stat: Stat, value: Double) {
// Amounts + red/green // Amounts + red/green
Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB, Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB,
Stat.AVERAGE_NET_BB -> { Stat.AVERAGE_NET_BB -> {
val numberFormat= FormatUtils.getCurrencyFormatter(context) val numberFormat= CurrencyUtils.getCurrencyFormatter(context, currency)
val color = if (this.value >= this.stat.threshold) R.color.green else R.color.red val color = if (this.value >= this.stat.threshold) R.color.green else R.color.red
return TextFormat(numberFormat.format(this.value), color) return TextFormat(numberFormat.format(this.value), color)
} // white integers } // white integers
@ -148,10 +139,10 @@ class ComputedStat(stat: Stat, value: Double) {
Stat.WIN_RATIO, Stat.ROI -> { Stat.WIN_RATIO, Stat.ROI -> {
val color = if (value * 100 >= this.stat.threshold) R.color.green else R.color.red val color = if (value * 100 >= this.stat.threshold) R.color.green else R.color.red
return TextFormat("${(value * 100).formatted()}%", color) return TextFormat("${(value * 100).formatted()}%", color)
} // white amounts } // white amountsr
Stat.AVERAGE_BUYIN, Stat.STANDARD_DEVIATION, Stat.STANDARD_DEVIATION_HOURLY, Stat.AVERAGE_BUYIN, Stat.STANDARD_DEVIATION, Stat.STANDARD_DEVIATION_HOURLY,
Stat.STANDARD_DEVIATION_BB_PER_100_HANDS -> { Stat.STANDARD_DEVIATION_BB_PER_100_HANDS -> {
val numberFormat= FormatUtils.getCurrencyFormatter(context) val numberFormat= CurrencyUtils.getCurrencyFormatter(context, currency)
return TextFormat(numberFormat.format(this.value)) return TextFormat(numberFormat.format(this.value))
} }
else -> throw FormattingException("Stat formatting of ${this.stat.name} not handled") else -> throw FormattingException("Stat formatting of ${this.stat.name} not handled")

@ -28,6 +28,7 @@ import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.util.CurrencyUtils
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.* import net.pokeranalytics.android.util.extensions.*
import java.util.* import java.util.*
@ -484,7 +485,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
CustomizableRowRepresentable( CustomizableRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG, RowViewType.HEADER_TITLE_AMOUNT_BIG,
title = getFormattedDuration(), title = getFormattedDuration(),
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll))
) )
) )
rows.add(SeparatorRowRepresentable()) rows.add(SeparatorRowRepresentable())
@ -494,7 +495,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
CustomizableRowRepresentable( CustomizableRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG, RowViewType.HEADER_TITLE_AMOUNT_BIG,
resId = R.string.pause, resId = R.string.pause,
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll))
) )
) )
rows.add(SeparatorRowRepresentable()) rows.add(SeparatorRowRepresentable())
@ -504,14 +505,14 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
CustomizableRowRepresentable( CustomizableRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG, RowViewType.HEADER_TITLE_AMOUNT_BIG,
title = getFormattedDuration(), title = getFormattedDuration(),
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0, CurrencyUtils.getCurrency(bankroll))
) )
) )
rows.add( rows.add(
CustomizableRowRepresentable( CustomizableRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT, RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.hour_rate_without_pauses, resId = R.string.hour_rate_without_pauses,
computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate) computedStat = ComputedStat(Stat.HOURLY_RATE, this.hourlyRate, CurrencyUtils.getCurrency(bankroll))
) )
) )
@ -520,7 +521,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
CustomizableRowRepresentable( CustomizableRowRepresentable(
RowViewType.HEADER_TITLE_VALUE, RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation, resId = R.string.bankroll_variation,
computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0) computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0, CurrencyUtils.getCurrency(bankroll))
) )
) )
} }
@ -553,18 +554,18 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT
SessionRow.BLINDS -> getBlinds() SessionRow.BLINDS -> getBlinds()
SessionRow.BREAK_TIME -> if (this.breakDuration > 0.0) this.breakDuration.toMinutes() else NULL_TEXT SessionRow.BREAK_TIME -> if (this.breakDuration > 0.0) this.breakDuration.toMinutes() else NULL_TEXT
SessionRow.BUY_IN -> this.result?.buyin?.toCurrency() ?: NULL_TEXT SessionRow.BUY_IN -> this.result?.buyin?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency() ?: NULL_TEXT SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT SessionRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT
SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT
SessionRow.GAME -> getGameTitle() SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.LOCATION -> location?.name ?: NULL_TEXT SessionRow.LOCATION -> location?.name ?: NULL_TEXT
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT
SessionRow.START_DATE -> this.startDate?.shortDateTime() ?: NULL_TEXT SessionRow.START_DATE -> this.startDate?.shortDateTime() ?: NULL_TEXT
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT SessionRow.TIPS -> result?.tips?.toCurrency(CurrencyUtils.getCurrency(bankroll)) ?: NULL_TEXT
SessionRow.TOURNAMENT_TYPE -> this.tournamentType?.let { SessionRow.TOURNAMENT_TYPE -> this.tournamentType?.let {
TournamentType.values()[it].localizedTitle(context) TournamentType.values()[it].localizedTitle(context)
} ?: run { } ?: run {
@ -575,10 +576,12 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
"${tournamentFeatures.subList(0,2).joinToString { "${tournamentFeatures.subList(0,2).joinToString {
it.name it.name
}}, ..." }}, ..."
} else { } else if (tournamentFeatures.size > 0) {
tournamentFeatures.joinToString { tournamentFeatures.joinToString {
it.name it.name
} }
} else {
NULL_TEXT
} }
} }
SessionRow.TOURNAMENT_NAME -> tournamentName?.name ?: NULL_TEXT SessionRow.TOURNAMENT_NAME -> tournamentName?.name ?: NULL_TEXT
@ -681,6 +684,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
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?
result = localResult result = localResult
this.updateRowRepresentation()
} }
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> { SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> {
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)

@ -26,6 +26,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.util.CurrencyUtils
import java.util.* import java.util.*
@ -99,9 +100,9 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
currentSession.startDate currentSession.startDate
) )
SessionRow.BANKROLL -> { SessionRow.BANKROLL -> {
BottomSheetFragment.create(fragmentManager, row, this, data, false) BottomSheetFragment.create(fragmentManager, row, this, data, false, CurrencyUtils.getCurrency(currentSession.bankroll))
} }
else -> BottomSheetFragment.create(fragmentManager, row, this, data) else -> BottomSheetFragment.create(fragmentManager, row, this, data, currentCurrency = CurrencyUtils.getCurrency(currentSession.bankroll))
} }
} }

@ -22,11 +22,13 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TransactionRow import net.pokeranalytics.android.ui.view.rowrepresentable.TransactionRow
import java.util.*
open class BottomSheetFragment : BottomSheetDialogFragment() { open class BottomSheetFragment : BottomSheetDialogFragment() {
lateinit var row: RowRepresentable lateinit var row: RowRepresentable
lateinit var delegate: RowRepresentableDelegate lateinit var delegate: RowRepresentableDelegate
var currentCurrency: Currency? = null
private var isClearable: Boolean = true private var isClearable: Boolean = true
private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>? = null private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>? = null
@ -40,7 +42,8 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
row: RowRepresentable, row: RowRepresentable,
delegate: RowRepresentableDelegate, delegate: RowRepresentableDelegate,
rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>?, rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor>?,
isClearable: Boolean? = true isClearable: Boolean? = true,
currentCurrency: Currency? = null
): BottomSheetFragment { ): BottomSheetFragment {
val bottomSheetFragment = row.bottomSheetType.newInstance() val bottomSheetFragment = row.bottomSheetType.newInstance()
bottomSheetFragment.show(fragmentManager, "bottomSheet") bottomSheetFragment.show(fragmentManager, "bottomSheet")
@ -48,7 +51,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
bottomSheetFragment.delegate = delegate bottomSheetFragment.delegate = delegate
bottomSheetFragment.rowRepresentableEditDescriptors = rowRepresentableEditDescriptors bottomSheetFragment.rowRepresentableEditDescriptors = rowRepresentableEditDescriptors
bottomSheetFragment.isClearable = isClearable ?: true bottomSheetFragment.isClearable = isClearable ?: true
bottomSheetFragment.currentCurrency = currentCurrency
return bottomSheetFragment return bottomSheetFragment
} }
} }

@ -2,18 +2,14 @@ package net.pokeranalytics.android.ui.fragment.components.bottomsheet
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle
import android.view.View
import io.realm.RealmList import io.realm.RealmList
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmResults
import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException import net.pokeranalytics.android.exceptions.RowRepresentableEditDescriptorException
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.activity.EditableDataActivity import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import timber.log.Timber
/** /**
* Manage multiple items selection in a bottom sheet list * Manage multiple items selection in a bottom sheet list
@ -38,7 +34,6 @@ open class BottomSheetMultiSelectionFragment : BottomSheetListFragment() {
} }
} }
//TODO: Set the correct values
override fun getValue(): Any? { override fun getValue(): Any? {
return selectedRows return selectedRows
} }
@ -50,16 +45,6 @@ open class BottomSheetMultiSelectionFragment : BottomSheetListFragment() {
selectedRows.add(row) selectedRows.add(row)
} }
dataAdapter.refreshRow(row) dataAdapter.refreshRow(row)
/*
realmData?.let {
val selectedData = it[position]
selectedData?.let {data ->
this.delegate.onRowValueChanged(data, this.row)
dismiss()
}
}
*/
} }
override fun isSelected(row: RowRepresentable): Boolean { override fun isSelected(row: RowRepresentable): Boolean {

@ -63,7 +63,7 @@ class BottomSheetSumFragment : BottomSheetFragment() {
0.0 0.0
} }
currentValue.text = currentDefaultValue.toCurrency() currentValue.text = currentDefaultValue.toCurrency(currentCurrency)
// First value // First value
val defaultValue1 = try { val defaultValue1 = try {
@ -72,7 +72,7 @@ class BottomSheetSumFragment : BottomSheetFragment() {
0.0 0.0
} }
button1.text = "+ ${defaultValue1.toCurrency()}" button1.text = "+ ${defaultValue1.toCurrency(currentCurrency)}"
button1.visibility = if (defaultValue1 > 0) View.VISIBLE else View.GONE button1.visibility = if (defaultValue1 > 0) View.VISIBLE else View.GONE
button1.setOnClickListener { button1.setOnClickListener {
this.delegate.onRowValueChanged(currentDefaultValue + defaultValue1, row) this.delegate.onRowValueChanged(currentDefaultValue + defaultValue1, row)
@ -86,7 +86,7 @@ class BottomSheetSumFragment : BottomSheetFragment() {
0.0 0.0
} }
button2.text = "+ ${defaultValue2.toCurrency()}" button2.text = "+ ${defaultValue2.toCurrency(currentCurrency)}"
button2.visibility = if (defaultValue2 > 0) View.VISIBLE else View.GONE button2.visibility = if (defaultValue2 > 0) View.VISIBLE else View.GONE
button2.setOnClickListener { button2.setOnClickListener {
this.delegate.onRowValueChanged(currentDefaultValue + defaultValue2, row) this.delegate.onRowValueChanged(currentDefaultValue + defaultValue2, row)

@ -14,6 +14,7 @@ import net.pokeranalytics.android.model.TableSize
import net.pokeranalytics.android.model.extensions.SessionState import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.CurrencyUtils
import net.pokeranalytics.android.util.extensions.getDayNumber import net.pokeranalytics.android.util.extensions.getDayNumber
import net.pokeranalytics.android.util.extensions.getShortDayName import net.pokeranalytics.android.util.extensions.getShortDayName
import net.pokeranalytics.android.util.extensions.shortTime import net.pokeranalytics.android.util.extensions.shortTime
@ -65,7 +66,7 @@ class SessionRowView : FrameLayout {
var title = "" var title = ""
if (session.isTournament()) { if (session.isTournament()) {
if (session.tournamentEntryFee != null) { if (session.tournamentEntryFee != null) {
title += session.tournamentEntryFee?.toCurrency() title += session.tournamentEntryFee?.toCurrency(CurrencyUtils.getCurrency(session.bankroll))
} }
session.game?.let { session.game?.let {
title += (if (title.isNotEmpty()) " " else "") + session.getGameTitle() title += (if (title.isNotEmpty()) " " else "") + session.getGameTitle()
@ -140,7 +141,7 @@ class SessionRowView : FrameLayout {
rowHistorySession.infoTitle.isVisible = false rowHistorySession.infoTitle.isVisible = false
val result = session.result?.net ?: 0.0 val result = session.result?.net ?: 0.0
val formattedStat = ComputedStat(Stat.NETRESULT, result).format(context) val formattedStat = ComputedStat(Stat.NETRESULT, result, currency = CurrencyUtils.getCurrency(session.bankroll)).format(context)
rowHistorySession.gameResult.setTextColor(formattedStat.getColor(context)) rowHistorySession.gameResult.setTextColor(formattedStat.getColor(context))
rowHistorySession.gameResult.text = formattedStat.text rowHistorySession.gameResult.text = formattedStat.text
} }

Loading…
Cancel
Save