Added delay after toggling a habit and before sort

pull/1102/head
Jakub Kalinowski 4 years ago
parent fc1478645b
commit dc2894f51f

@ -20,6 +20,8 @@
package org.isoron.uhabits.activities.habits.list package org.isoron.uhabits.activities.habits.list
import android.content.Context import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
@ -122,31 +124,40 @@ class ListHabitsMenu @Inject constructor(
} }
R.id.actionSortColor -> { R.id.actionSortColor -> {
behavior.onSortByColor() { behavior.onSortByColor() }.delay(SORT_DELAY_MILLIS)
return true return true
} }
R.id.actionSortManual -> { R.id.actionSortManual -> {
behavior.onSortByManually() { behavior.onSortByManually() }.delay(SORT_DELAY_MILLIS)
return true return true
} }
R.id.actionSortName -> { R.id.actionSortName -> {
behavior.onSortByName() { behavior.onSortByName() }.delay(SORT_DELAY_MILLIS)
return true return true
} }
R.id.actionSortScore -> { R.id.actionSortScore -> {
behavior.onSortByScore() { behavior.onSortByScore() }.delay(SORT_DELAY_MILLIS)
return true return true
} }
R.id.actionSortStatus -> { R.id.actionSortStatus -> {
behavior.onSortByStatus() { behavior.onSortByStatus() }.delay(SORT_DELAY_MILLIS)
return true return true
} }
else -> return false 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
import android.view.View.MeasureSpec.EXACTLY import android.view.View.MeasureSpec.EXACTLY
import org.isoron.uhabits.R 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
import org.isoron.uhabits.core.models.Entry.Companion.NO 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.SKIP
@ -80,15 +82,24 @@ class CheckmarkButtonView(
setOnLongClickListener(this) setOnLongClickListener(this)
} }
fun performToggle() { private fun performToggle() {
value = Entry.nextToggleValue( value = Entry.nextToggleValue(
value = value, value = value,
isSkipEnabled = preferences.isSkipEnabled, isSkipEnabled = preferences.isSkipEnabled,
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
) )
onToggle(value)
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) if (preferences.isSkipEnabled) {
invalidate() {
onToggle(value)
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
invalidate()
}.delay(TOGGLE_DELAY_MILLIS)
} else {
onToggle(value)
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
invalidate()
}
} }
override fun onClick(v: View) { override fun onClick(v: View) {

Loading…
Cancel
Save