HistoryCard: Make colors more consistent for AT_MOST habits

pull/1260/head
Alinson S. Xavier 4 years ago
parent d40a5a89cd
commit 5b8a7c39e2
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -29,7 +29,8 @@ import android.view.View
import android.view.View.OnClickListener import android.view.View.OnClickListener
import android.view.View.OnLongClickListener import android.view.View.OnLongClickListener
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.NumericalHabitType import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
import org.isoron.uhabits.core.models.NumericalHabitType.AT_MOST
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.inject.ActivityContext import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils.getDimension import org.isoron.uhabits.utils.InterfaceUtils.getDimension
@ -37,7 +38,6 @@ import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.drawNotesIndicator import org.isoron.uhabits.utils.drawNotesIndicator
import org.isoron.uhabits.utils.getFontAwesome import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sres import org.isoron.uhabits.utils.sres
import java.lang.Double.max
import java.text.DecimalFormat import java.text.DecimalFormat
import javax.inject.Inject import javax.inject.Inject
@ -90,7 +90,7 @@ class NumberButtonView(
invalidate() invalidate()
} }
var targetType = NumericalHabitType.AT_LEAST var targetType = AT_LEAST
set(value) { set(value) {
field = value field = value
invalidate() invalidate()
@ -164,18 +164,11 @@ class NumberButtonView(
} }
fun draw(canvas: Canvas) { fun draw(canvas: Canvas) {
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) { val activeColor = when {
when { value < 0.0 -> lowContrast
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast (targetType == AT_LEAST) && (value >= threshold) -> color
max(0.0, value) >= threshold -> color (targetType == AT_MOST) && (value <= threshold) -> color
else -> mediumContrast else -> mediumContrast
}
} else {
when {
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast
value <= threshold -> color
else -> mediumContrast
}
} }
val label: String val label: String

@ -29,16 +29,21 @@ import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitList import org.isoron.uhabits.core.models.HabitList
import org.isoron.uhabits.core.models.NumericalHabitType import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
import org.isoron.uhabits.core.models.NumericalHabitType.AT_MOST
import org.isoron.uhabits.core.models.PaletteColor import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.core.models.Timestamp import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.core.ui.views.HistoryChart import org.isoron.uhabits.core.ui.views.HistoryChart
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.DIMMED
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.GREY
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.HATCHED
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.OFF
import org.isoron.uhabits.core.ui.views.HistoryChart.Square.ON
import org.isoron.uhabits.core.ui.views.OnDateClickedListener import org.isoron.uhabits.core.ui.views.OnDateClickedListener
import org.isoron.uhabits.core.ui.views.Theme import org.isoron.uhabits.core.ui.views.Theme
import org.isoron.uhabits.core.utils.DateUtils import org.isoron.uhabits.core.utils.DateUtils
import kotlin.math.max
import kotlin.math.roundToInt import kotlin.math.roundToInt
data class HistoryCardState( data class HistoryCardState(
@ -146,36 +151,24 @@ class HistoryCardPresenter(
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
val entries = habit.computedEntries.getByInterval(oldest, today) val entries = habit.computedEntries.getByInterval(oldest, today)
val series = if (habit.isNumerical) { val series = if (habit.isNumerical) {
if (habit.targetType == NumericalHabitType.AT_LEAST) { entries.map {
entries.map { when {
when (max(0, it.value)) { it.value == Entry.UNKNOWN -> OFF
0 -> HistoryChart.Square.OFF (habit.targetType == AT_MOST) && (it.value / 1000.0 <= habit.targetValue) -> ON
else -> HistoryChart.Square.ON (habit.targetType == AT_LEAST) && (it.value / 1000.0 >= habit.targetValue) -> ON
} else -> GREY
}
} else {
entries.map {
when {
max(0.0, it.value / 1000.0) <= habit.targetValue -> HistoryChart.Square.ON
else -> HistoryChart.Square.OFF
}
} }
} }
} else { } else {
entries.map { entries.map {
when (it.value) { when (it.value) {
YES_MANUAL -> HistoryChart.Square.ON YES_MANUAL -> ON
YES_AUTO -> HistoryChart.Square.DIMMED YES_AUTO -> DIMMED
SKIP -> HistoryChart.Square.HATCHED SKIP -> HATCHED
else -> HistoryChart.Square.OFF else -> OFF
} }
} }
} }
val defaultSquare = if (habit.isNumerical && habit.targetType == NumericalHabitType.AT_MOST)
HistoryChart.Square.ON
else
HistoryChart.Square.OFF
val notesIndicators = entries.map { val notesIndicators = entries.map {
when (it.notes) { when (it.notes) {
"" -> false "" -> false
@ -189,7 +182,7 @@ class HistoryCardPresenter(
today = today.toLocalDate(), today = today.toLocalDate(),
theme = theme, theme = theme,
series = series, series = series,
defaultSquare = defaultSquare, defaultSquare = OFF,
notesIndicators = notesIndicators, notesIndicators = notesIndicators,
) )
} }

@ -53,6 +53,7 @@ class HistoryChart(
enum class Square { enum class Square {
ON, ON,
OFF, OFF,
GREY,
DIMMED, DIMMED,
HATCHED, HATCHED,
} }
@ -216,6 +217,9 @@ class HistoryChart(
Square.OFF -> { Square.OFF -> {
theme.lowContrastTextColor theme.lowContrastTextColor
} }
Square.GREY -> {
theme.mediumContrastTextColor
}
Square.DIMMED, Square.HATCHED -> { Square.DIMMED, Square.HATCHED -> {
color.blendWith(theme.cardBackgroundColor, 0.5) color.blendWith(theme.cardBackgroundColor, 0.5)
} }
@ -254,7 +258,7 @@ class HistoryChart(
if (hasNotes) { if (hasNotes) {
circleColor = when (value) { circleColor = when (value) {
Square.ON -> theme.lowContrastTextColor Square.ON, Square.GREY -> theme.lowContrastTextColor
else -> color else -> color
} }
canvas.setColor(circleColor) canvas.setColor(circleColor)

Loading…
Cancel
Save