Increment and decrement gestures from HabitList

pull/419/head^2
Jake Powell 7 years ago
parent 3787bc9cda
commit f1d9a019dd

@ -129,6 +129,14 @@ class HabitCardView(
numberPanel = numberPanelFactory.create().apply {
visibility = GONE
onIncrement = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onIncrement(it, timestamp)}
}
onDecrement = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onDecrement(it, timestamp)}
}
onEdit = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onEdit(it, timestamp) }

@ -81,6 +81,8 @@ class NumberButtonView(
invalidate()
}
var onIncrement: () -> Unit = {}
var onDecrement: () -> Unit = {}
var onEdit: () -> Unit = {}
private var drawer: Drawer = Drawer(context)
private val detector: GestureDetector = GestureDetector(
@ -90,19 +92,19 @@ class NumberButtonView(
override fun onDown(e: MotionEvent?): Boolean = true
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
Log.d("YOUREIT", "onSingleTapConfirmed")
if (preferences.isShortToggleEnabled) onEdit()
else showMessage(R.string.long_press_to_edit)
onIncrement()
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
return true
}
override fun onDoubleTap(e: MotionEvent?): Boolean {
Log.d("YOUREIT", "onDoubleTap")
onDecrement()
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
return true
}
override fun onLongPress(e: MotionEvent?) {
Log.d("YOUREIT", "onLongPress")
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
onEdit()
}
})

@ -57,6 +57,18 @@ class NumberPanelView(
setupButtons()
}
var onIncrement: (Timestamp) -> Unit = {}
set(value) {
field = value
setupButtons()
}
var onDecrement: (Timestamp) -> Unit = {}
set(value) {
field = value
setupButtons()
}
var onEdit: (Timestamp) -> Unit = {}
set(value) {
field = value
@ -78,6 +90,8 @@ class NumberPanelView(
button.color = color
button.threshold = threshold
button.units = units
button.onIncrement = { onIncrement(timestamp) }
button.onDecrement = { onDecrement(timestamp) }
button.onEdit = { onEdit(timestamp) }
}
}

@ -78,6 +78,26 @@ public class ListHabitsBehavior
screen.showHabitScreen(h);
}
public void onIncrement(@NonNull Habit habit, Timestamp timestamp)
{
CheckmarkList checkmarks = habit.getCheckmarks();
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, (int)(oldValue + 1000)),
habit.getId());
}
public void onDecrement(@NonNull Habit habit, Timestamp timestamp)
{
CheckmarkList checkmarks = habit.getCheckmarks();
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
double newValue = oldValue - 1000;
if (newValue < 0) return;
commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, (int)newValue),
habit.getId());
}
public void onEdit(@NonNull Habit habit, Timestamp timestamp)
{
CheckmarkList checkmarks = habit.getCheckmarks();

Loading…
Cancel
Save