mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Cycle through through all checkmark states
This commit is contained in:
@@ -81,11 +81,11 @@ class CheckmarkButtonView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun performToggle() {
|
fun performToggle() {
|
||||||
value = if (preferences.isSkipEnabled) {
|
value = Entry.nextToggleValue(
|
||||||
Entry.nextToggleValueWithSkip(value)
|
value = value,
|
||||||
} else {
|
isSkipEnabled = preferences.isSkipEnabled,
|
||||||
Entry.nextToggleValueWithoutSkip(value)
|
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||||
}
|
)
|
||||||
onToggle(value)
|
onToggle(value)
|
||||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||||
invalidate()
|
invalidate()
|
||||||
|
|||||||
@@ -50,19 +50,18 @@ data class Entry(
|
|||||||
*/
|
*/
|
||||||
const val UNKNOWN = -1
|
const val UNKNOWN = -1
|
||||||
|
|
||||||
fun nextToggleValueWithSkip(value: Int): Int {
|
fun nextToggleValue(
|
||||||
|
value: Int,
|
||||||
|
isSkipEnabled: Boolean,
|
||||||
|
areQuestionMarksEnabled: Boolean
|
||||||
|
): Int {
|
||||||
return when (value) {
|
return when (value) {
|
||||||
NO, UNKNOWN, YES_AUTO -> YES_MANUAL
|
YES_AUTO -> YES_MANUAL
|
||||||
YES_MANUAL -> SKIP
|
YES_MANUAL -> if (isSkipEnabled) SKIP else NO
|
||||||
SKIP -> NO
|
SKIP -> NO
|
||||||
else -> NO
|
NO -> if (areQuestionMarksEnabled) UNKNOWN else YES_MANUAL
|
||||||
}
|
UNKNOWN -> YES_MANUAL
|
||||||
}
|
else -> YES_MANUAL
|
||||||
|
|
||||||
fun nextToggleValueWithoutSkip(value: Int): Int {
|
|
||||||
return when (value) {
|
|
||||||
NO, UNKNOWN, YES_AUTO -> YES_MANUAL
|
|
||||||
else -> NO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ class HistoryCardPresenter(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val currentValue = habit.computedEntries.get(timestamp).value
|
val currentValue = habit.computedEntries.get(timestamp).value
|
||||||
val nextValue = if (preferences.isSkipEnabled) {
|
val nextValue = Entry.nextToggleValue(
|
||||||
Entry.nextToggleValueWithSkip(currentValue)
|
value = currentValue,
|
||||||
} else {
|
isSkipEnabled = preferences.isSkipEnabled,
|
||||||
Entry.nextToggleValueWithoutSkip(currentValue)
|
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||||
}
|
)
|
||||||
commandRunner.run(
|
commandRunner.run(
|
||||||
CreateRepetitionCommand(
|
CreateRepetitionCommand(
|
||||||
habitList,
|
habitList,
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ package org.isoron.uhabits.core.ui.widgets
|
|||||||
import org.isoron.uhabits.core.commands.CommandRunner
|
import org.isoron.uhabits.core.commands.CommandRunner
|
||||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValueWithSkip
|
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValueWithoutSkip
|
|
||||||
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.Timestamp
|
import org.isoron.uhabits.core.models.Timestamp
|
||||||
@@ -48,13 +47,11 @@ class WidgetBehavior @Inject constructor(
|
|||||||
|
|
||||||
fun onToggleRepetition(habit: Habit, timestamp: Timestamp) {
|
fun onToggleRepetition(habit: Habit, timestamp: Timestamp) {
|
||||||
val currentValue = habit.originalEntries.get(timestamp).value
|
val currentValue = habit.originalEntries.get(timestamp).value
|
||||||
val newValue: Int
|
val newValue = nextToggleValue(
|
||||||
newValue =
|
value = currentValue,
|
||||||
if (preferences.isSkipEnabled) nextToggleValueWithSkip(
|
isSkipEnabled = preferences.isSkipEnabled,
|
||||||
currentValue
|
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||||
) else nextToggleValueWithoutSkip(
|
)
|
||||||
currentValue
|
|
||||||
)
|
|
||||||
setValue(habit, timestamp, newValue)
|
setValue(habit, timestamp, newValue)
|
||||||
notificationTray.cancel(habit)
|
notificationTray.cancel(habit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||||
|
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||||
|
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||||
|
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.nextToggleValue
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class EntryTest {
|
||||||
|
@Test
|
||||||
|
fun testNextValue() {
|
||||||
|
check(
|
||||||
|
mapOf(
|
||||||
|
YES_AUTO to YES_MANUAL,
|
||||||
|
YES_MANUAL to SKIP,
|
||||||
|
SKIP to NO,
|
||||||
|
NO to UNKNOWN,
|
||||||
|
UNKNOWN to YES_MANUAL,
|
||||||
|
),
|
||||||
|
isSkipEnabled = true,
|
||||||
|
areQuestionMarksEnabled = true,
|
||||||
|
)
|
||||||
|
check(
|
||||||
|
mapOf(
|
||||||
|
YES_AUTO to YES_MANUAL,
|
||||||
|
YES_MANUAL to NO,
|
||||||
|
SKIP to NO,
|
||||||
|
NO to UNKNOWN,
|
||||||
|
UNKNOWN to YES_MANUAL,
|
||||||
|
),
|
||||||
|
isSkipEnabled = false,
|
||||||
|
areQuestionMarksEnabled = true,
|
||||||
|
)
|
||||||
|
check(
|
||||||
|
mapOf(
|
||||||
|
YES_AUTO to YES_MANUAL,
|
||||||
|
YES_MANUAL to SKIP,
|
||||||
|
SKIP to NO,
|
||||||
|
NO to YES_MANUAL,
|
||||||
|
UNKNOWN to YES_MANUAL,
|
||||||
|
),
|
||||||
|
isSkipEnabled = true,
|
||||||
|
areQuestionMarksEnabled = false,
|
||||||
|
)
|
||||||
|
check(
|
||||||
|
mapOf(
|
||||||
|
YES_AUTO to YES_MANUAL,
|
||||||
|
YES_MANUAL to NO,
|
||||||
|
SKIP to NO,
|
||||||
|
NO to YES_MANUAL,
|
||||||
|
UNKNOWN to YES_MANUAL,
|
||||||
|
),
|
||||||
|
isSkipEnabled = false,
|
||||||
|
areQuestionMarksEnabled = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun check(
|
||||||
|
map: Map<Int, Int>,
|
||||||
|
isSkipEnabled: Boolean,
|
||||||
|
areQuestionMarksEnabled: Boolean
|
||||||
|
) {
|
||||||
|
for ((value, expected) in map) {
|
||||||
|
assertEquals(
|
||||||
|
nextToggleValue(
|
||||||
|
value = value,
|
||||||
|
isSkipEnabled = isSkipEnabled,
|
||||||
|
areQuestionMarksEnabled = areQuestionMarksEnabled,
|
||||||
|
),
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,8 +26,7 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValueWithSkip
|
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValueWithoutSkip
|
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
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
|
||||||
@@ -42,6 +41,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
|
|||||||
private lateinit var behavior: WidgetBehavior
|
private lateinit var behavior: WidgetBehavior
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
private lateinit var today: Timestamp
|
private lateinit var today: Timestamp
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
@@ -81,12 +81,14 @@ class WidgetBehaviorTest : BaseUnitTest() {
|
|||||||
Entry.NO,
|
Entry.NO,
|
||||||
Entry.YES_MANUAL,
|
Entry.YES_MANUAL,
|
||||||
Entry.YES_AUTO,
|
Entry.YES_AUTO,
|
||||||
Entry.SKIP
|
Entry.SKIP,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
whenever(preferences.isSkipEnabled).thenReturn(skipEnabled)
|
whenever(preferences.isSkipEnabled).thenReturn(skipEnabled)
|
||||||
val nextValue: Int = if (skipEnabled) nextToggleValueWithSkip(currentValue) else nextToggleValueWithoutSkip(
|
val nextValue: Int = nextToggleValue(
|
||||||
currentValue
|
currentValue,
|
||||||
|
isSkipEnabled = skipEnabled,
|
||||||
|
areQuestionMarksEnabled = false
|
||||||
)
|
)
|
||||||
habit.originalEntries.add(Entry(today, currentValue))
|
habit.originalEntries.add(Entry(today, currentValue))
|
||||||
behavior.onToggleRepetition(habit, today)
|
behavior.onToggleRepetition(habit, today)
|
||||||
|
|||||||
Reference in New Issue
Block a user