mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Simplify the code
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -44,8 +44,7 @@ class NumberButtonViewTest : BaseViewTest() {
|
||||
view = component.getNumberButtonViewFactory().create().apply {
|
||||
units = "steps"
|
||||
targetType = NumericalHabitType.AT_LEAST
|
||||
lowerThreshold = 50.0
|
||||
higherThreshold = 100.0
|
||||
threshold = 100.0
|
||||
color = PaletteUtils.getAndroidTestColor(8)
|
||||
onEdit = { edited = true }
|
||||
}
|
||||
@@ -71,39 +70,39 @@ class NumberButtonViewTest : BaseViewTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_aboveHigherThreshold() {
|
||||
fun testRender_aboveThreshold() {
|
||||
view.value = 500.0
|
||||
assertRenders(view, "$PATH/render_above.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_atMostAboveHigherThreshold() {
|
||||
fun testRender_atMostAboveThreshold() {
|
||||
view.value = 500.0
|
||||
view.targetType = NumericalHabitType.AT_MOST
|
||||
assertRenders(view, "$PATH/render_at_most_above.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_betweenThresholds() {
|
||||
fun testRender_belowThreshold() {
|
||||
view.value = 99.0
|
||||
assertRenders(view, "$PATH/render_between.png")
|
||||
assertRenders(view, "$PATH/render_below.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_atMostBetweenThresholds() {
|
||||
view.value = 99.0
|
||||
view.value = 110.0
|
||||
view.targetType = NumericalHabitType.AT_MOST
|
||||
assertRenders(view, "$PATH/render_at_most_between.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_belowLowerThreshold() {
|
||||
fun testRender_zero() {
|
||||
view.value = 0.0
|
||||
assertRenders(view, "$PATH/render_below.png")
|
||||
assertRenders(view, "$PATH/render_zero.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRender_atMostBelowLowerThreshold() {
|
||||
fun testRender_atMostBelowThreshold() {
|
||||
view.value = 0.0
|
||||
view.targetType = NumericalHabitType.AT_MOST
|
||||
assertRenders(view, "$PATH/render_at_most_below.png")
|
||||
|
||||
@@ -57,8 +57,7 @@ class NumberPanelViewTest : BaseViewTest() {
|
||||
color = PaletteUtils.getAndroidTestColor(7)
|
||||
units = "steps"
|
||||
targetType = NumericalHabitType.AT_LEAST
|
||||
lowerThreshold = 0.0
|
||||
higherThreshold = 5000.0
|
||||
threshold = 5000.0
|
||||
}
|
||||
view.onAttachedToWindow()
|
||||
measureView(view, dpToPixels(200), dpToPixels(200))
|
||||
|
||||
@@ -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