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

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

View File

@@ -102,6 +102,8 @@ public class HistoryChart extends ScrollableChart
@NonNull
private Controller controller;
private boolean skipsEnabled;
public HistoryChart(Context context)
{
super(context);
@@ -153,7 +155,10 @@ public class HistoryChart extends ScrollableChart
int offset = timestamp.daysUntil(today);
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;
}
@@ -211,6 +216,11 @@ public class HistoryChart extends ScrollableChart
initColors();
}
public void setSkipEnabled(boolean value)
{
this.skipsEnabled = value;
}
public void setIsEditable(boolean isEditable)
{
this.isEditable = isEditable;

View File

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

View File

@@ -120,7 +120,11 @@ public class HistoryCard extends HabitCard
{
if (isCanceled()) return;
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);
}

View File

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

View File

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

View File

@@ -200,4 +200,6 @@
<string name="no_boolean_habits">No yes-or-no habits found</string>
<string name="increment">Increment</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>

View File

@@ -31,6 +31,13 @@
android:title="@string/pref_toggle_title"
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
android:defaultValue="false"
android:key="pref_checkmark_reverse_order"