diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Format.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Format.kt
index 1a99b722..a5d26c6c 100644
--- a/app/src/main/java/net/pokeranalytics/android/calculus/Format.kt
+++ b/app/src/main/java/net/pokeranalytics/android/calculus/Format.kt
@@ -4,12 +4,11 @@ import android.content.Context
import android.graphics.Color
import androidx.core.content.ContextCompat
-class TextFormat(text: String, color: Int? = null) {
- var text: String = text
- private var color: Int? = color
+class TextFormat(var text: String, var color: Int? = null) {
fun getColor(context: Context) : Int {
this.color?.let { return ContextCompat.getColor(context, it) }
return Color.WHITE
}
+
}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
index 06390a19..dd70d1d9 100644
--- a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
+++ b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
@@ -9,7 +9,6 @@ import net.pokeranalytics.android.util.Preferences
import net.pokeranalytics.android.util.formatted
import net.pokeranalytics.android.util.toMinutes
import java.text.NumberFormat
-import java.util.*
/**
* An enum representing all the types of Session statistics
@@ -133,8 +132,10 @@ class ComputedStat(stat: Stat, value: Double) {
Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB,
Stat.AVERAGE_NET_BB -> {
val numberFormat = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context))
- val color = if (value >= this.stat.threshold) R.color.green else R.color.red
- return TextFormat(numberFormat.format(value), color)
+ numberFormat.minimumFractionDigits = 0
+ numberFormat.maximumFractionDigits = 2
+ val color = if (this.value >= this.stat.threshold) R.color.green else R.color.red
+ return TextFormat(numberFormat.format(this.value), color)
} // white integers
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.HANDS_PLAYED -> {
return TextFormat("${value.toInt()}")
@@ -149,7 +150,9 @@ class ComputedStat(stat: Stat, value: Double) {
Stat.AVERAGE_BUYIN, Stat.STANDARD_DEVIATION, Stat.STANDARD_DEVIATION_HOURLY,
Stat.STANDARD_DEVIATION_BB_PER_100_HANDS -> {
val numberFormat = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context))
- return TextFormat(numberFormat.format(value))
+ numberFormat.minimumFractionDigits = 0
+ numberFormat.maximumFractionDigits = 2
+ return TextFormat(numberFormat.format(this.value))
}
else -> throw FormattingException("Stat formatting of ${this.stat.name} not handled")
}
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/DynamicValueTextView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/DynamicValueTextView.kt
deleted file mode 100644
index 0e5e3d58..00000000
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/DynamicValueTextView.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package net.pokeranalytics.android.ui.view
-
-import android.content.Context
-import android.util.AttributeSet
-import androidx.appcompat.widget.AppCompatTextView
-import androidx.core.content.ContextCompat
-import net.pokeranalytics.android.R
-import net.pokeranalytics.android.util.toCurrency
-
-/**
- * Extended TextView to display amount in the right color / currency
- * Work in progress
- */
-class DynamicValueTextView: AppCompatTextView {
-
- var isCurrency: Boolean = false
- var amount: Double = 0.0
- set(value) {
- field = value
- updateUI()
- }
-
- constructor(context: Context?) : super(context) {
- init(null)
- }
-
- constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
- init(attrs)
- }
-
- constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
- init(attrs)
- }
-
- /**
- * Init class
- */
- private fun init(attrs: AttributeSet?) {
- context.theme.obtainStyledAttributes( attrs, R.styleable.DynamicValueTextView, 0, 0).apply {
- try {
- isCurrency = getBoolean(R.styleable.DynamicValueTextView_isCurrency, false)
- amount = getFloat(R.styleable.DynamicValueTextView_amount, 0f).toDouble()
- updateUI()
- } finally {
- recycle()
- }
- }
- }
-
- /**
- * Update the UI to manage currency format & color management
- */
- private fun updateUI() {
- if (isCurrency) {
- setTextColor(ContextCompat.getColor(context, if (amount >= 0) R.color.green else R.color.red))
- text = amount.toCurrency()
- }
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/FormattedTextView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/FormattedTextView.kt
new file mode 100644
index 00000000..831fd19b
--- /dev/null
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/FormattedTextView.kt
@@ -0,0 +1,47 @@
+package net.pokeranalytics.android.ui.view
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatTextView
+import net.pokeranalytics.android.calculus.TextFormat
+
+/**
+ * Extended TextView to display a TextFormat object
+ */
+class FormattedTextView: AppCompatTextView {
+
+ var textFormat: TextFormat? = null
+ set(value) {
+ field = value
+ updateUI()
+ }
+
+ constructor(context: Context?) : super(context) {
+ init(null)
+ }
+
+ constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
+ init(attrs)
+ }
+
+ constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
+ init(attrs)
+ }
+
+ /**
+ * Init class
+ */
+ private fun init(attrs: AttributeSet?) {
+ }
+
+ /**
+ * Update the UI to manage currency format & color management
+ */
+ private fun updateUI() {
+ textFormat?.let {
+ setTextColor(it.getColor(context))
+ text = it.text
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
index 0287aab7..0e7a146a 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
@@ -16,6 +16,8 @@ import kotlinx.android.synthetic.main.row_title_switch.view.*
import kotlinx.android.synthetic.main.row_title_value.view.*
import kotlinx.android.synthetic.main.row_title_value_action.view.*
import net.pokeranalytics.android.R
+import net.pokeranalytics.android.calculus.ComputedStat
+import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable
@@ -28,7 +30,6 @@ interface BindableHolder {
fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
}
-
}
@@ -178,12 +179,13 @@ enum class RowViewType {
itemView.rowHeaderTitleAmount_title.text = row.title
}
- itemView.rowHeaderTitleAmount_value.isCurrency = true
- itemView.rowHeaderTitleAmount_value.amount = try {
+ val value = try {
row.value?.toDouble() ?: 0.0
} catch (e: Exception) {
0.0
}
+ val stat = ComputedStat(Stat.NETRESULT, value)
+ itemView.rowHeaderTitleAmount_value.textFormat = stat.format(itemView.context)
}
}
}
diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
index 89262a63..e26a7e48 100644
--- a/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
+++ b/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
@@ -8,6 +8,8 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.row_session_view.view.*
import net.pokeranalytics.android.R
+import net.pokeranalytics.android.calculus.ComputedStat
+import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.TableSize
import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState
@@ -123,7 +125,9 @@ class SessionRowView : FrameLayout {
rowHistorySession.playingTitle.isVisible = false
val result = session.result?.net ?: 0.0
- rowHistorySession.gameResult.amount = result
+
+ val stat = ComputedStat(Stat.NETRESULT, result)
+ rowHistorySession.gameResult.textFormat = stat.format(context)
}
}
diff --git a/app/src/main/res/layout/row_header_title_amount.xml b/app/src/main/res/layout/row_header_title_amount.xml
index 1dc898e8..83737250 100644
--- a/app/src/main/res/layout/row_header_title_amount.xml
+++ b/app/src/main/res/layout/row_header_title_amount.xml
@@ -24,7 +24,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
-
-
-
-
-
+