mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Address review comments
This commit is contained in:
@@ -116,15 +116,7 @@ class NumberButtonViewTest : BaseViewTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClick_shortToggleDisabled() {
|
||||
prefs.isShortToggleEnabled = false
|
||||
view.performClick()
|
||||
assertTrue(edited)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClick_shortToggleEnabled() {
|
||||
prefs.isShortToggleEnabled = true
|
||||
fun testClick() {
|
||||
view.performClick()
|
||||
assertTrue(edited)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
hasNotes = emptyList(),
|
||||
theme = themeSwitcher.currentTheme,
|
||||
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
||||
onDateClickedListener = onDateClickedListener ?: OnDateClickedListener { _, _ -> },
|
||||
onDateClickedListener = onDateClickedListener ?: object : OnDateClickedListener {},
|
||||
padding = 10.0,
|
||||
)
|
||||
dataView = AndroidDataView(context!!, null)
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
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 org.isoron.uhabits.utils.toMeasureSpec
|
||||
@@ -104,7 +105,8 @@ class CheckmarkButtonView(
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
performToggle()
|
||||
if (preferences.isShortToggleEnabled) onEdit()
|
||||
else performToggle()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -134,8 +136,6 @@ class CheckmarkButtonView(
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
|
||||
private val pNotesIndicator: Paint = Paint()
|
||||
|
||||
fun draw(canvas: Canvas) {
|
||||
paint.color = when (value) {
|
||||
YES_MANUAL, YES_AUTO, SKIP -> color
|
||||
@@ -145,7 +145,6 @@ class CheckmarkButtonView(
|
||||
}
|
||||
else -> lowContrastColor
|
||||
}
|
||||
pNotesIndicator.color = color
|
||||
val id = when (value) {
|
||||
SKIP -> R.string.fa_skipped
|
||||
NO -> R.string.fa_times
|
||||
@@ -181,10 +180,7 @@ class CheckmarkButtonView(
|
||||
canvas.drawText(label, rect.centerX(), rect.centerY(), paint)
|
||||
}
|
||||
|
||||
if (hasNotes) {
|
||||
val cy = 0.8f * em
|
||||
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
||||
}
|
||||
drawNotesIndicator(canvas, color, em, hasNotes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class CheckmarkPanelView(
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var notes = BooleanArray(0)
|
||||
var notesIndicators = BooleanArray(0)
|
||||
set(values) {
|
||||
field = values
|
||||
setupButtons()
|
||||
@@ -85,7 +85,7 @@ class CheckmarkPanelView(
|
||||
else -> UNKNOWN
|
||||
}
|
||||
button.hasNotes = when {
|
||||
index + dataOffset < notes.size -> notes[index + dataOffset]
|
||||
index + dataOffset < notesIndicators.size -> notesIndicators[index + dataOffset]
|
||||
else -> false
|
||||
}
|
||||
button.color = color
|
||||
|
||||
@@ -99,7 +99,7 @@ class HabitCardListView(
|
||||
cardView.score = score
|
||||
cardView.unit = habit.unit
|
||||
cardView.threshold = habit.targetValue / habit.frequency.denominator
|
||||
cardView.notes = notesIndicators
|
||||
cardView.notesIndicators = notesIndicators
|
||||
|
||||
val detector = GestureDetector(context, CardViewGestureDetector(holder))
|
||||
cardView.setOnTouchListener { _, ev ->
|
||||
|
||||
@@ -115,11 +115,11 @@ class HabitCardView(
|
||||
numberPanel.threshold = value
|
||||
}
|
||||
|
||||
var notes
|
||||
get() = checkmarkPanel.notes
|
||||
var notesIndicators
|
||||
get() = checkmarkPanel.notesIndicators
|
||||
set(values) {
|
||||
checkmarkPanel.notes = values
|
||||
numberPanel.notes = values
|
||||
checkmarkPanel.notesIndicators = values
|
||||
numberPanel.notesIndicators = values
|
||||
}
|
||||
|
||||
var checkmarkPanel: CheckmarkPanelView
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.InterfaceUtils.getDimension
|
||||
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
|
||||
@@ -156,8 +157,6 @@ class NumberButtonView(
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
|
||||
private val pNotesIndicator: Paint = Paint()
|
||||
|
||||
init {
|
||||
em = pNumber.measureText("m")
|
||||
lowContrast = sres.getColor(R.attr.contrast40)
|
||||
@@ -205,7 +204,6 @@ class NumberButtonView(
|
||||
pNumber.color = activeColor
|
||||
pNumber.typeface = typeface
|
||||
pUnit.color = activeColor
|
||||
pNotesIndicator.color = color
|
||||
|
||||
if (units.isBlank()) {
|
||||
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
||||
@@ -218,10 +216,7 @@ class NumberButtonView(
|
||||
canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit)
|
||||
}
|
||||
|
||||
if (hasNotes) {
|
||||
val cy = 0.8f * em
|
||||
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
||||
}
|
||||
drawNotesIndicator(canvas, color, em, hasNotes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class NumberPanelView(
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var notes = BooleanArray(0)
|
||||
var notesIndicators = BooleanArray(0)
|
||||
set(values) {
|
||||
field = values
|
||||
setupButtons()
|
||||
@@ -97,7 +97,7 @@ class NumberPanelView(
|
||||
else -> 0.0
|
||||
}
|
||||
button.hasNotes = when {
|
||||
index + dataOffset < notes.size -> notes[index + dataOffset]
|
||||
index + dataOffset < notesIndicators.size -> notesIndicators[index + dataOffset]
|
||||
else -> false
|
||||
}
|
||||
button.color = color
|
||||
|
||||
@@ -22,7 +22,9 @@ package org.isoron.uhabits.utils
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Handler
|
||||
import android.view.LayoutInflater
|
||||
@@ -199,5 +201,15 @@ fun View.dim(id: Int) = InterfaceUtils.getDimension(context, id)
|
||||
fun View.sp(value: Float) = InterfaceUtils.spToPixels(context, value)
|
||||
fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value)
|
||||
fun View.str(id: Int) = resources.getString(id)
|
||||
|
||||
fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, hasNotes: Boolean) {
|
||||
val pNotesIndicator = Paint()
|
||||
pNotesIndicator.color = color
|
||||
if (hasNotes) {
|
||||
val cy = 0.8f * size
|
||||
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
||||
}
|
||||
}
|
||||
|
||||
val View.sres: StyledResources
|
||||
get() = StyledResources(context)
|
||||
|
||||
Reference in New Issue
Block a user