mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-08 01:58:52 -06:00
Simplify the code
This commit is contained in:
@@ -36,7 +36,6 @@ import dagger.Lazy
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.views.BundleSavedState
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.NumericalHabitType
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -98,13 +97,7 @@ class HabitCardListView(
|
||||
cardView.dataOffset = dataOffset
|
||||
cardView.score = score
|
||||
cardView.unit = habit.unit
|
||||
if (habit.targetType == NumericalHabitType.AT_LEAST) {
|
||||
cardView.higherThreshold = habit.targetValue / habit.frequency.denominator
|
||||
cardView.lowerThreshold = 0.0
|
||||
} else {
|
||||
cardView.higherThreshold = (habit.targetValue * 2) / habit.frequency.denominator
|
||||
cardView.lowerThreshold = habit.targetValue / habit.frequency.denominator
|
||||
}
|
||||
cardView.threshold = habit.targetValue / habit.frequency.denominator
|
||||
|
||||
val detector = GestureDetector(context, CardViewGestureDetector(holder))
|
||||
cardView.setOnTouchListener { _, ev ->
|
||||
|
||||
@@ -109,16 +109,10 @@ class HabitCardView(
|
||||
numberPanel.values = values.map { it / 1000.0 }.toDoubleArray()
|
||||
}
|
||||
|
||||
var lowerThreshold: Double
|
||||
get() = numberPanel.lowerThreshold
|
||||
var threshold: Double
|
||||
get() = numberPanel.threshold
|
||||
set(value) {
|
||||
numberPanel.lowerThreshold = value
|
||||
}
|
||||
|
||||
var higherThreshold: Double
|
||||
get() = numberPanel.higherThreshold
|
||||
set(value) {
|
||||
numberPanel.higherThreshold = value
|
||||
numberPanel.threshold = value
|
||||
}
|
||||
|
||||
var checkmarkPanel: CheckmarkPanelView
|
||||
@@ -243,8 +237,7 @@ class HabitCardView(
|
||||
color = c
|
||||
units = h.unit
|
||||
targetType = h.targetType
|
||||
lowerThreshold = 0.0
|
||||
higherThreshold = h.targetValue
|
||||
threshold = h.targetValue
|
||||
visibility = when (h.isNumerical) {
|
||||
true -> View.VISIBLE
|
||||
false -> View.GONE
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.isoron.uhabits.utils.dim
|
||||
import org.isoron.uhabits.utils.getFontAwesome
|
||||
import org.isoron.uhabits.utils.showMessage
|
||||
import org.isoron.uhabits.utils.sres
|
||||
import java.lang.Double.max
|
||||
import java.text.DecimalFormat
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -83,13 +84,7 @@ class NumberButtonView(
|
||||
invalidate()
|
||||
}
|
||||
|
||||
var lowerThreshold = 0.0
|
||||
set(value) {
|
||||
field = value
|
||||
invalidate()
|
||||
}
|
||||
|
||||
var higherThreshold = 0.0
|
||||
var threshold = 0.0
|
||||
set(value) {
|
||||
field = value
|
||||
invalidate()
|
||||
@@ -167,15 +162,15 @@ class NumberButtonView(
|
||||
fun draw(canvas: Canvas) {
|
||||
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) {
|
||||
when {
|
||||
value <= lowerThreshold -> lowContrast
|
||||
value < higherThreshold -> mediumContrast
|
||||
else -> color
|
||||
max(0.0, value) >= threshold -> color
|
||||
value <= 0 -> lowContrast
|
||||
else -> mediumContrast
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
value >= higherThreshold || value < 0 -> lowContrast
|
||||
value > lowerThreshold -> mediumContrast
|
||||
else -> color
|
||||
value <= threshold -> color
|
||||
value >= 2 * threshold -> lowContrast
|
||||
else -> mediumContrast
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +190,7 @@ class NumberButtonView(
|
||||
textSize = dim(R.dimen.smallerTextSize)
|
||||
}
|
||||
else -> {
|
||||
label = if (targetType == NumericalHabitType.AT_LEAST) "0" else "inf"
|
||||
label = "0"
|
||||
typeface = BOLD_TYPEFACE
|
||||
textSize = dim(R.dimen.smallTextSize)
|
||||
}
|
||||
|
||||
@@ -54,13 +54,7 @@ class NumberPanelView(
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var lowerThreshold = 0.0
|
||||
set(value) {
|
||||
field = value
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var higherThreshold = 0.0
|
||||
var threshold = 0.0
|
||||
set(value) {
|
||||
field = value
|
||||
setupButtons()
|
||||
@@ -98,8 +92,7 @@ class NumberPanelView(
|
||||
}
|
||||
button.color = color
|
||||
button.targetType = targetType
|
||||
button.lowerThreshold = lowerThreshold
|
||||
button.higherThreshold = higherThreshold
|
||||
button.threshold = threshold
|
||||
button.units = units
|
||||
button.onEdit = { onEdit(timestamp) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user