add last streak as text

pull/646/head
asdoi 5 years ago
parent 84523869e8
commit 2b2b97739c

@ -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.*
@ -87,6 +88,11 @@ class HabitCardView(
set(values) { set(values) {
checkmarkPanel.values = values checkmarkPanel.values = values
numberPanel.values = values.map { it / 1000.0 }.toDoubleArray() numberPanel.values = values.map { it / 1000.0 }.toDoubleArray()
if (habit?.isNumerical == false) {
streakText.apply {
visibility = if (values[0] == 0) View.GONE else View.VISIBLE
}
}
} }
var threshold: Double var threshold: Double
@ -100,6 +106,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 streakText: TextView
init { init {
scoreRing = RingView(context).apply { scoreRing = RingView(context).apply {
@ -113,6 +120,17 @@ class HabitCardView(
setThickness(thickness) setThickness(thickness)
} }
streakText = TextView(context).apply {
val marginRight = dp(8f).toInt()
setSingleLine()
gravity = Gravity.CENTER
typeface = Typeface.DEFAULT_BOLD
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
setMargins(0, 0, marginRight, 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 +160,7 @@ class HabitCardView(
if (SDK_INT >= LOLLIPOP) elevation = dp(1f) if (SDK_INT >= LOLLIPOP) elevation = dp(1f)
addView(scoreRing) addView(scoreRing)
addView(streakText)
addView(label) addView(label)
addView(checkmarkPanel) addView(checkmarkPanel)
addView(numberPanel) addView(numberPanel)
@ -207,6 +226,31 @@ class HabitCardView(
scoreRing.apply { scoreRing.apply {
color = c color = c
} }
if (!h.isNumerical) {
val streaks = h.streaks.all
var isLastStreakBestStreak = false
val lastStreak =
if (streaks != null && streaks.size > 0) {
if (h.streaks.getBest(1)[0] == streaks[0])
isLastStreakBestStreak = true
streaks[0].length
} else 0
streakText.apply {
text = lastStreak.toString()
setTextColor(when (isLastStreakBestStreak) {
true -> c
false -> sres.getColor(R.attr.mediumContrastTextColor)
})
visibility = View.VISIBLE
}
} else {
streakText.apply {
visibility = View.GONE
}
}
checkmarkPanel.apply { checkmarkPanel.apply {
color = c color = c
visibility = when (h.isNumerical) { visibility = when (h.isNumerical) {

Loading…
Cancel
Save