Added delay after toggling a habit and before sort

This commit is contained in:
Jakub Kalinowski
2021-09-12 18:22:55 +02:00
parent fc1478645b
commit dc2894f51f
2 changed files with 31 additions and 9 deletions

View File

@@ -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)
}
}
}

View File

@@ -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) {