add score as text

pull/646/head
asdoi 5 years ago
parent 84523869e8
commit 039ab1225b

@ -20,6 +20,7 @@
package org.isoron.uhabits.activities.habits.list.views package org.isoron.uhabits.activities.habits.list.views
import android.content.* import android.content.*
import android.graphics.Typeface
import android.os.* import android.os.*
import android.os.Build.VERSION.* import android.os.Build.VERSION.*
import android.os.Build.VERSION_CODES.* import android.os.Build.VERSION_CODES.*
@ -74,6 +75,7 @@ class HabitCardView(
set(value) { set(value) {
scoreRing.percentage = value.toFloat() scoreRing.percentage = value.toFloat()
scoreRing.precision = 1.0f / 16 scoreRing.precision = 1.0f / 16
scoreText.text = "${(value * 100).toInt()}%"
} }
var unit var unit
@ -100,6 +102,7 @@ class HabitCardView(
private var innerFrame: LinearLayout private var innerFrame: LinearLayout
private var label: TextView private var label: TextView
private var scoreRing: RingView private var scoreRing: RingView
private var scoreText: TextView
init { init {
scoreRing = RingView(context).apply { scoreRing = RingView(context).apply {
@ -113,6 +116,17 @@ class HabitCardView(
setThickness(thickness) setThickness(thickness)
} }
scoreText = TextView(context).apply {
val margin = dp(8f).toInt()
setSingleLine()
gravity = Gravity.CENTER
typeface = Typeface.DEFAULT_BOLD
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
setMargins(margin, 0, margin, 0)
gravity = Gravity.CENTER
}
}
label = TextView(context).apply { label = TextView(context).apply {
maxLines = 2 maxLines = 2
ellipsize = TextUtils.TruncateAt.END ellipsize = TextUtils.TruncateAt.END
@ -142,6 +156,7 @@ class HabitCardView(
if (SDK_INT >= LOLLIPOP) elevation = dp(1f) if (SDK_INT >= LOLLIPOP) elevation = dp(1f)
addView(scoreRing) addView(scoreRing)
addView(scoreText)
addView(label) addView(label)
addView(checkmarkPanel) addView(checkmarkPanel)
addView(numberPanel) addView(numberPanel)
@ -207,6 +222,9 @@ class HabitCardView(
scoreRing.apply { scoreRing.apply {
color = c color = c
} }
scoreText.apply {
setTextColor(c)
}
checkmarkPanel.apply { checkmarkPanel.apply {
color = c color = c
visibility = when (h.isNumerical) { visibility = when (h.isNumerical) {

Loading…
Cancel
Save