Make skip days an opt-in feature

This commit is contained in:
2020-11-18 22:13:03 -06:00
parent bef85bf93a
commit d594d3b085
11 changed files with 73 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ public final class Repetition
this.value = value;
}
public static int nextToggleValue(int value)
public static int nextToggleValueWithSkip(int value)
{
switch(value) {
case NO:
@@ -70,6 +70,17 @@ public final class Repetition
}
}
public static int nextToggleValueWithoutSkip(int value)
{
switch(value) {
case NO:
case YES_AUTO:
return YES_MANUAL;
default:
return NO;
}
}
@Override
public boolean equals(Object o)

View File

@@ -338,6 +338,11 @@ public class Preferences
storage.putString("pref_widget_opacity", Integer.toString(value));
}
public boolean isSkipEnabled()
{
return storage.getBoolean("pref_skip_enabled", false);
}
/**
* @return An integer representing the first day of the week. Sunday

View File

@@ -23,6 +23,7 @@ import androidx.annotation.*;
import org.isoron.uhabits.core.commands.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.preferences.*;
import org.isoron.uhabits.core.ui.*;
import org.jetbrains.annotations.*;
@@ -35,16 +36,22 @@ public class WidgetBehavior
@NonNull
private final CommandRunner commandRunner;
private NotificationTray notificationTray;
@NonNull
private final NotificationTray notificationTray;
@NonNull
private final Preferences preferences;
@Inject
public WidgetBehavior(@NonNull HabitList habitList,
@NonNull CommandRunner commandRunner,
@NonNull NotificationTray notificationTray)
@NonNull NotificationTray notificationTray,
@NonNull Preferences preferences)
{
this.habitList = habitList;
this.commandRunner = commandRunner;
this.notificationTray = notificationTray;
this.preferences = preferences;
}
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
@@ -66,8 +73,19 @@ public class WidgetBehavior
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
{
Repetition previous = habit.getRepetitions().getByTimestamp(timestamp);
if(previous == null) performToggle(habit, timestamp, Checkmark.YES_MANUAL);
else performToggle(habit, timestamp, Repetition.nextToggleValue(previous.getValue()));
if(previous == null)
{
performToggle(habit, timestamp, Checkmark.YES_MANUAL);
}
else
{
int value;
if(preferences.isSkipEnabled())
value = Repetition.nextToggleValueWithSkip(previous.getValue());
else
value = Repetition.nextToggleValueWithoutSkip(previous.getValue());
performToggle(habit, timestamp, value);
}
}
private void performToggle(@NonNull Habit habit, Timestamp timestamp, int value)