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 { numberPanel = numberPanelFactory.create().apply {
visibility = GONE visibility = GONE
onIncrement = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onIncrement(it, timestamp)}
}
onDecrement = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onDecrement(it, timestamp)}
}
onEdit = { timestamp -> onEdit = { timestamp ->
triggerRipple(timestamp) triggerRipple(timestamp)
habit?.let { behavior.onEdit(it, timestamp) } habit?.let { behavior.onEdit(it, timestamp) }

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

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

@ -78,6 +78,26 @@ public class ListHabitsBehavior
screen.showHabitScreen(h); 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) public void onEdit(@NonNull Habit habit, Timestamp timestamp)
{ {
CheckmarkList checkmarks = habit.getCheckmarks(); CheckmarkList checkmarks = habit.getCheckmarks();

Loading…
Cancel
Save