Add a method Habit.dismiss(), and teach HabitMatcher to filter habits dismissed Today.

pull/558/head
Scrimbly 6 years ago
parent 105383e505
commit 23a66e3b6c

@ -23,6 +23,7 @@ import androidx.annotation.*;
import org.apache.commons.lang3.builder.*; import org.apache.commons.lang3.builder.*;
import java.time.LocalDate;
import java.util.*; import java.util.*;
import javax.annotation.concurrent.*; import javax.annotation.concurrent.*;
@ -31,6 +32,7 @@ import javax.inject.*;
import static org.isoron.uhabits.core.models.Checkmark.*; import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle; import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
/** /**
* The thing that the user wants to track. * The thing that the user wants to track.
*/ */
@ -66,6 +68,8 @@ public class Habit
@NonNull @NonNull
private CheckmarkList checkmarks; private CheckmarkList checkmarks;
private LocalDate lastDismissed = LocalDate.MIN;
private ModelObservable observable = new ModelObservable(); private ModelObservable observable = new ModelObservable();
/** /**
@ -339,6 +343,17 @@ public class Habit
return data.type == NUMBER_HABIT; return data.type == NUMBER_HABIT;
} }
public synchronized boolean isDismissedToday()
{
LocalDate today = LocalDate.now();
return lastDismissed.equals(today);
}
public synchronized void dismiss()
{
lastDismissed = LocalDate.now();
}
public HabitData getData() public HabitData getData()
{ {
return new HabitData(data); return new HabitData(data);

@ -61,6 +61,7 @@ public class HabitMatcher
if (!isArchivedAllowed() && habit.isArchived()) return false; if (!isArchivedAllowed() && habit.isArchived()) return false;
if (isReminderRequired() && !habit.hasReminder()) return false; if (isReminderRequired() && !habit.hasReminder()) return false;
if (!isCompletedAllowed() && habit.isCompletedToday()) return false; if (!isCompletedAllowed() && habit.isCompletedToday()) return false;
if (habit.isDismissedToday()) return false;
return true; return true;
} }
} }

Loading…
Cancel
Save