Clean Format and Stat

feature/top10
Aurelien Hubert 7 years ago
parent d2bc919a43
commit 0064422225
  1. 5
      app/src/main/java/net/pokeranalytics/android/calculus/Format.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt

@ -4,12 +4,11 @@ import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
class TextFormat(text: String, color: Int? = null) { class TextFormat(var text: String, var color: Int? = null) {
var text: String = text
private var color: Int? = color
fun getColor(context: Context) : Int { fun getColor(context: Context) : Int {
this.color?.let { return ContextCompat.getColor(context, it) } this.color?.let { return ContextCompat.getColor(context, it) }
return Color.WHITE return Color.WHITE
} }
} }

@ -9,7 +9,6 @@ import net.pokeranalytics.android.util.Preferences
import net.pokeranalytics.android.util.formatted import net.pokeranalytics.android.util.formatted
import net.pokeranalytics.android.util.toMinutes import net.pokeranalytics.android.util.toMinutes
import java.text.NumberFormat import java.text.NumberFormat
import java.util.*
/** /**
* An enum representing all the types of Session statistics * An enum representing all the types of Session statistics
@ -126,6 +125,8 @@ class ComputedStat(stat: Stat, value: Double) {
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 = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context)) val numberFormat = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context))
numberFormat.minimumFractionDigits = 0
numberFormat.maximumFractionDigits = 2
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
@ -142,6 +143,8 @@ class ComputedStat(stat: Stat, value: Double) {
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 = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context)) val numberFormat = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context))
numberFormat.minimumFractionDigits = 0
numberFormat.maximumFractionDigits = 2
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")

Loading…
Cancel
Save