mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 13:08:51 -06:00
Added delay after toggling a habit and before sort
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
@@ -122,31 +124,40 @@ class ListHabitsMenu @Inject constructor(
|
||||
}
|
||||
|
||||
R.id.actionSortColor -> {
|
||||
behavior.onSortByColor()
|
||||
{ behavior.onSortByColor() }.delay(SORT_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionSortManual -> {
|
||||
behavior.onSortByManually()
|
||||
{ behavior.onSortByManually() }.delay(SORT_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionSortName -> {
|
||||
behavior.onSortByName()
|
||||
{ behavior.onSortByName() }.delay(SORT_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionSortScore -> {
|
||||
behavior.onSortByScore()
|
||||
{ behavior.onSortByScore() }.delay(SORT_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionSortStatus -> {
|
||||
behavior.onSortByStatus()
|
||||
{ behavior.onSortByStatus() }.delay(SORT_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val SORT_DELAY_MILLIS = 1000L
|
||||
const val TOGGLE_DELAY_MILLIS = 2000L
|
||||
|
||||
fun (() -> Unit).delay(delayInMillis: Long) {
|
||||
Handler(Looper.getMainLooper()).postDelayed(this, delayInMillis)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import android.view.HapticFeedbackConstants
|
||||
import android.view.View
|
||||
import android.view.View.MeasureSpec.EXACTLY
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.habits.list.ListHabitsMenu.Companion.delay
|
||||
import org.isoron.uhabits.activities.habits.list.ListHabitsMenu.Companion.TOGGLE_DELAY_MILLIS
|
||||
import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
@@ -80,15 +82,24 @@ class CheckmarkButtonView(
|
||||
setOnLongClickListener(this)
|
||||
}
|
||||
|
||||
fun performToggle() {
|
||||
private fun performToggle() {
|
||||
value = Entry.nextToggleValue(
|
||||
value = value,
|
||||
isSkipEnabled = preferences.isSkipEnabled,
|
||||
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||
)
|
||||
onToggle(value)
|
||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||
invalidate()
|
||||
|
||||
if (preferences.isSkipEnabled) {
|
||||
{
|
||||
onToggle(value)
|
||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||
invalidate()
|
||||
}.delay(TOGGLE_DELAY_MILLIS)
|
||||
} else {
|
||||
onToggle(value)
|
||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
|
||||
Reference in New Issue
Block a user