mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
HistoryCard: Make colors more consistent for AT_MOST habits
This commit is contained in:
@@ -29,7 +29,8 @@ import android.view.View
|
||||
import android.view.View.OnClickListener
|
||||
import android.view.View.OnLongClickListener
|
||||
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.inject.ActivityContext
|
||||
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.getFontAwesome
|
||||
import org.isoron.uhabits.utils.sres
|
||||
import java.lang.Double.max
|
||||
import java.text.DecimalFormat
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -90,7 +90,7 @@ class NumberButtonView(
|
||||
invalidate()
|
||||
}
|
||||
|
||||
var targetType = NumericalHabitType.AT_LEAST
|
||||
var targetType = AT_LEAST
|
||||
set(value) {
|
||||
field = value
|
||||
invalidate()
|
||||
@@ -164,18 +164,11 @@ class NumberButtonView(
|
||||
}
|
||||
|
||||
fun draw(canvas: Canvas) {
|
||||
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) {
|
||||
when {
|
||||
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast
|
||||
max(0.0, value) >= threshold -> color
|
||||
else -> mediumContrast
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
value < 0.0 && preferences.areQuestionMarksEnabled -> lowContrast
|
||||
value <= threshold -> color
|
||||
else -> mediumContrast
|
||||
}
|
||||
val activeColor = when {
|
||||
value < 0.0 -> lowContrast
|
||||
(targetType == AT_LEAST) && (value >= threshold) -> color
|
||||
(targetType == AT_MOST) && (value <= threshold) -> color
|
||||
else -> mediumContrast
|
||||
}
|
||||
|
||||
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.Habit
|
||||
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.Timestamp
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
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.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.Theme
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
data class HistoryCardState(
|
||||
@@ -146,36 +151,24 @@ class HistoryCardPresenter(
|
||||
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
|
||||
val entries = habit.computedEntries.getByInterval(oldest, today)
|
||||
val series = if (habit.isNumerical) {
|
||||
if (habit.targetType == NumericalHabitType.AT_LEAST) {
|
||||
entries.map {
|
||||
when (max(0, it.value)) {
|
||||
0 -> HistoryChart.Square.OFF
|
||||
else -> HistoryChart.Square.ON
|
||||
}
|
||||
}
|
||||
} else {
|
||||
entries.map {
|
||||
when {
|
||||
max(0.0, it.value / 1000.0) <= habit.targetValue -> HistoryChart.Square.ON
|
||||
else -> HistoryChart.Square.OFF
|
||||
}
|
||||
entries.map {
|
||||
when {
|
||||
it.value == Entry.UNKNOWN -> OFF
|
||||
(habit.targetType == AT_MOST) && (it.value / 1000.0 <= habit.targetValue) -> ON
|
||||
(habit.targetType == AT_LEAST) && (it.value / 1000.0 >= habit.targetValue) -> ON
|
||||
else -> GREY
|
||||
}
|
||||
}
|
||||
} else {
|
||||
entries.map {
|
||||
when (it.value) {
|
||||
YES_MANUAL -> HistoryChart.Square.ON
|
||||
YES_AUTO -> HistoryChart.Square.DIMMED
|
||||
SKIP -> HistoryChart.Square.HATCHED
|
||||
else -> HistoryChart.Square.OFF
|
||||
YES_MANUAL -> ON
|
||||
YES_AUTO -> DIMMED
|
||||
SKIP -> HATCHED
|
||||
else -> OFF
|
||||
}
|
||||
}
|
||||
}
|
||||
val defaultSquare = if (habit.isNumerical && habit.targetType == NumericalHabitType.AT_MOST)
|
||||
HistoryChart.Square.ON
|
||||
else
|
||||
HistoryChart.Square.OFF
|
||||
|
||||
val notesIndicators = entries.map {
|
||||
when (it.notes) {
|
||||
"" -> false
|
||||
@@ -189,7 +182,7 @@ class HistoryCardPresenter(
|
||||
today = today.toLocalDate(),
|
||||
theme = theme,
|
||||
series = series,
|
||||
defaultSquare = defaultSquare,
|
||||
defaultSquare = OFF,
|
||||
notesIndicators = notesIndicators,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ class HistoryChart(
|
||||
enum class Square {
|
||||
ON,
|
||||
OFF,
|
||||
GREY,
|
||||
DIMMED,
|
||||
HATCHED,
|
||||
}
|
||||
@@ -216,6 +217,9 @@ class HistoryChart(
|
||||
Square.OFF -> {
|
||||
theme.lowContrastTextColor
|
||||
}
|
||||
Square.GREY -> {
|
||||
theme.mediumContrastTextColor
|
||||
}
|
||||
Square.DIMMED, Square.HATCHED -> {
|
||||
color.blendWith(theme.cardBackgroundColor, 0.5)
|
||||
}
|
||||
@@ -254,7 +258,7 @@ class HistoryChart(
|
||||
|
||||
if (hasNotes) {
|
||||
circleColor = when (value) {
|
||||
Square.ON -> theme.lowContrastTextColor
|
||||
Square.ON, Square.GREY -> theme.lowContrastTextColor
|
||||
else -> color
|
||||
}
|
||||
canvas.setColor(circleColor)
|
||||
|
||||
Reference in New Issue
Block a user