diff --git a/app/src/main/java/com/github/cmput301f21t44/hellohabits/model/Habit.java b/app/src/main/java/com/github/cmput301f21t44/hellohabits/model/Habit.java index bba9798..46bf434 100644 --- a/app/src/main/java/com/github/cmput301f21t44/hellohabits/model/Habit.java +++ b/app/src/main/java/com/github/cmput301f21t44/hellohabits/model/Habit.java @@ -4,13 +4,6 @@ import java.util.List; public interface Habit { - static final int MONDAY = 0; - static final int TUESDAY = 1; - static final int WEDNESDAY = 2; - static final int THURSDAY = 3; - static final int FRIDAY = 4; - static final int SATURDAY = 5; - static final int SUNDAY = 6; String getId(); @@ -21,5 +14,20 @@ public interface Habit { Instant getDateStarted(); List getEvents(); + boolean[] getDaysOfWeek(); + + static boolean isInDay(Instant today, boolean[] dayOfWeek) { + // dayOfWeek goes from 1-7 (Monday-Sunday) + int dayOfWeek = today.atZone(ZoneId.systemDefault()).getDayOfWeek().getValue(); + + // daysOfWeek is an array that matches the checkBox for viewing. + // in case today is Monday: + // [true, true ,true, true, true, true, true] = every day + // [true, false , false, false, false, false, false] = only on monday + // [true, false , false, false, false, false, true] = for monday and sunday + return daysOfWeek[dayOfWeek-1] + } + + } diff --git a/app/src/main/java/com/github/cmput301f21t44/hellohabits/view/TodaysHabitsFragment.java b/app/src/main/java/com/github/cmput301f21t44/hellohabits/view/TodaysHabitsFragment.java index 03962cf..187bab8 100644 --- a/app/src/main/java/com/github/cmput301f21t44/hellohabits/view/TodaysHabitsFragment.java +++ b/app/src/main/java/com/github/cmput301f21t44/hellohabits/view/TodaysHabitsFragment.java @@ -54,10 +54,17 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { @Override public void onStart() { super.onStart(); - mHabitViewModel.getAllHabits().observe(this, list -> { - // need to cast List to List - List habits = new ArrayList<>(list); - adapter.submitList(habits); + mHabitViewModel.getAllHabits().observe(this, habitList -> { + List todaysHabits = new ArrayList<>(); + Instant today = Instant.now(); + // traverse all h in habitList, and only masks in those who matches the checkBox + // checkBox implementation can be seen in isInDay() from Habit.java + for (Habit h : habitList) { + if (Habit.isInDay(today, h.getDaysOfWeek())) { + todaysHabits.add(h); + } + } + adapter.submitList(todaysHabits); }); }