Make skip days an opt-in feature

pull/672/head
Alinson S. Xavier 5 years ago
parent bef85bf93a
commit d594d3b085

@ -82,6 +82,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
historyChart = new HistoryChart(context); historyChart = new HistoryChart(context);
historyChart.setController(controller); historyChart.setController(controller);
historyChart.setFirstWeekday(prefs.getFirstWeekday()); historyChart.setFirstWeekday(prefs.getFirstWeekday());
historyChart.setSkipEnabled(prefs.isSkipEnabled());
if (savedInstanceState != null) if (savedInstanceState != null)
{ {

@ -102,6 +102,8 @@ public class HistoryChart extends ScrollableChart
@NonNull @NonNull
private Controller controller; private Controller controller;
private boolean skipsEnabled;
public HistoryChart(Context context) public HistoryChart(Context context)
{ {
super(context); super(context);
@ -153,7 +155,10 @@ public class HistoryChart extends ScrollableChart
int offset = timestamp.daysUntil(today); int offset = timestamp.daysUntil(today);
if (offset < checkmarks.length) if (offset < checkmarks.length)
{ {
newValue = Repetition.nextToggleValue(checkmarks[offset]); if(skipsEnabled)
newValue = Repetition.nextToggleValueWithSkip(checkmarks[offset]);
else
newValue = Repetition.nextToggleValueWithoutSkip(checkmarks[offset]);
checkmarks[offset] = newValue; checkmarks[offset] = newValue;
} }
@ -211,6 +216,11 @@ public class HistoryChart extends ScrollableChart
initColors(); initColors();
} }
public void setSkipEnabled(boolean value)
{
this.skipsEnabled = value;
}
public void setIsEditable(boolean isEditable) public void setIsEditable(boolean isEditable)
{ {
this.isEditable = isEditable; this.isEditable = isEditable;

@ -62,7 +62,11 @@ class CheckmarkButtonView(
} }
fun performToggle() { fun performToggle() {
value = Repetition.nextToggleValue(value) value = if(preferences.isSkipEnabled) {
Repetition.nextToggleValueWithSkip(value)
} else {
Repetition.nextToggleValueWithoutSkip(value)
}
onToggle(value) onToggle(value)
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
invalidate() invalidate()

@ -120,7 +120,11 @@ public class HistoryCard extends HabitCard
{ {
if (isCanceled()) return; if (isCanceled()) return;
int[] checkmarks = habit.getCheckmarks().getAllValues(); int[] checkmarks = habit.getCheckmarks().getAllValues();
if(prefs != null) chart.setFirstWeekday(prefs.getFirstWeekday()); if(prefs != null)
{
chart.setFirstWeekday(prefs.getFirstWeekday());
chart.setSkipEnabled(prefs.isSkipEnabled());
}
chart.setCheckmarks(checkmarks); chart.setCheckmarks(checkmarks);
} }

@ -44,6 +44,7 @@ class HistoryWidget(
if (preferedBackgroundAlpha >= 255) widgetView.setShadowAlpha(0x4f) if (preferedBackgroundAlpha >= 255) widgetView.setShadowAlpha(0x4f)
(widgetView.dataView as HistoryChart).apply { (widgetView.dataView as HistoryChart).apply {
setFirstWeekday(firstWeekday) setFirstWeekday(firstWeekday)
setSkipEnabled(prefs.isSkipEnabled)
setColor(PaletteUtils.getColor(context, habit.color)) setColor(PaletteUtils.getColor(context, habit.color))
setCheckmarks(habit.checkmarks.allValues) setCheckmarks(habit.checkmarks.allValues)
setNumerical(habit.isNumerical) setNumerical(habit.isNumerical)

@ -49,7 +49,8 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
data = parser.parseCheckmarkIntent(intent) data = parser.parseCheckmarkIntent(intent)
behavior = WidgetBehavior(component.habitList, behavior = WidgetBehavior(component.habitList,
component.commandRunner, component.commandRunner,
component.notificationTray) component.notificationTray,
component.preferences)
widgetUpdater = component.widgetUpdater widgetUpdater = component.widgetUpdater
showNumberSelector(this) showNumberSelector(this)

@ -200,4 +200,6 @@
<string name="no_boolean_habits">No yes-or-no habits found</string> <string name="no_boolean_habits">No yes-or-no habits found</string>
<string name="increment">Increment</string> <string name="increment">Increment</string>
<string name="decrement">Decrement</string> <string name="decrement">Decrement</string>
<string name="pref_skip_title">Enable skip days</string>
<string name="pref_skip_description">Toggle twice to add a skip instead of a checkmark. Skips keep your score unchanged and don\'t break your streak.</string>
</resources> </resources>

@ -31,6 +31,13 @@
android:title="@string/pref_toggle_title" android:title="@string/pref_toggle_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_skip_enabled"
android:summary="@string/pref_skip_description"
android:title="@string/pref_skip_title"
app:iconSpaceReserved="false" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="pref_checkmark_reverse_order" android:key="pref_checkmark_reverse_order"

@ -56,7 +56,7 @@ public final class Repetition
this.value = value; this.value = value;
} }
public static int nextToggleValue(int value) public static int nextToggleValueWithSkip(int value)
{ {
switch(value) { switch(value) {
case NO: 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 @Override
public boolean equals(Object o) public boolean equals(Object o)

@ -338,6 +338,11 @@ public class Preferences
storage.putString("pref_widget_opacity", Integer.toString(value)); 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 * @return An integer representing the first day of the week. Sunday

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

Loading…
Cancel
Save