Skip to content

Commit 7beb792

Browse files
kalina559hiqua
authored andcommitted
Added delay after toggling a habit
1 parent c50c5af commit 7beb792

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkButtonView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ class CheckmarkButtonView(
8080
setOnLongClickListener(this)
8181
}
8282

83-
fun performToggle() {
83+
private fun performToggle() {
8484
value = Entry.nextToggleValue(
8585
value = value,
8686
isSkipEnabled = preferences.isSkipEnabled,
8787
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
8888
)
89+
8990
onToggle(value)
9091
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
9192
invalidate()

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import android.widget.TextView
3636
import org.isoron.platform.gui.toInt
3737
import org.isoron.uhabits.R
3838
import org.isoron.uhabits.activities.common.views.RingView
39+
import org.isoron.uhabits.activities.habits.list.views.HabitCardView.Companion.delay
3940
import org.isoron.uhabits.core.models.Habit
4041
import org.isoron.uhabits.core.models.ModelObservable
4142
import org.isoron.uhabits.core.models.Timestamp
@@ -143,7 +144,11 @@ class HabitCardView(
143144
checkmarkPanel = checkmarkPanelFactory.create().apply {
144145
onToggle = { timestamp, value ->
145146
triggerRipple(timestamp)
146-
habit?.let { behavior.onToggle(it, timestamp, value) }
147+
habit?.let {
148+
{
149+
behavior.onToggle(it, timestamp, value)
150+
}.delay(TOGGLE_DELAY_MILLIS)
151+
}
147152
}
148153
}
149154

@@ -263,4 +268,12 @@ class HabitCardView(
263268
}
264269
innerFrame.setBackgroundResource(background)
265270
}
271+
272+
companion object {
273+
const val TOGGLE_DELAY_MILLIS = 2000L
274+
275+
fun (() -> Unit).delay(delayInMillis: Long) {
276+
Handler(Looper.getMainLooper()).postDelayed(this, delayInMillis)
277+
}
278+
}
266279
}

0 commit comments

Comments
 (0)