diff --git a/app/src/main/java/prototype/xd/scheduler/entities/TodoEntryList.java b/app/src/main/java/prototype/xd/scheduler/entities/TodoEntryList.java index d236eec..c2b6248 100644 --- a/app/src/main/java/prototype/xd/scheduler/entities/TodoEntryList.java +++ b/app/src/main/java/prototype/xd/scheduler/entities/TodoEntryList.java @@ -316,10 +316,11 @@ public boolean isNotGlobalEntryVisibleOnDay(@NonNull TodoEntry entry, long targe public void notifyEntryVisibilityChanged(@NonNull TodoEntry entry, boolean coreDaysChanged, + boolean extendedDaysChanged, @NonNull Set invalidatedDaySet, boolean onlyAddDifference) { // if the entry is currently marked as global in the list and is global now - if (globalEntries.contains(entry) && entry.isGlobal() && !coreDaysChanged) { + if (globalEntries.contains(entry) && entry.isGlobal()) { Logger.warning(NAME, "Trying to change visibility range of a global entry"); return; } @@ -350,12 +351,20 @@ public void notifyEntryVisibilityChanged(@NonNull TodoEntry entry, TodoEntry.FullDaySet newDaySet = entry.getFullDaySet(firstLoadedDay, lastLoadedDay); if (onlyAddDifference) { - Logger.debug(NAME, "Added difference to invalidatedDaySet"); - invalidatedDaySet.addAll(displayUpcomingExpired ? - Sets.symmetricDifference(prevExpiredUpcomingDays, newDaySet.getUpcomingExpiredDaySet()) : - Sets.symmetricDifference(prevCoreDays, newDaySet.getCoreDaySet())); + if (displayUpcomingExpired && extendedDaysChanged) { + invalidatedDaySet.addAll(Sets.symmetricDifference(prevExpiredUpcomingDays, newDaySet.getUpcomingExpiredDaySet())); + } + // Sometimes the extended days may change in a way, that a new core day is on an old extended day, like this + // Before: _ _ _ _ E - - - - + // After: _ _ _ _ E E - - - - + // In this case the only changed extended day will be the last one, so we also need to add the difference from the core days + if (coreDaysChanged) { + invalidatedDaySet.addAll(Sets.symmetricDifference(prevCoreDays, newDaySet.getCoreDaySet())); + } + Logger.debug(NAME, "Added difference to invalidatedDaySet"); } else { + // Add both new and old sets invalidatedDaySet.addAll(displayUpcomingExpired ? prevExpiredUpcomingDays : prevCoreDays); invalidatedDaySet.addAll(displayUpcomingExpired ? newDaySet.getUpcomingExpiredDaySet() : newDaySet.getCoreDaySet()); diff --git a/app/src/main/java/prototype/xd/scheduler/fragments/HomeFragment.java b/app/src/main/java/prototype/xd/scheduler/fragments/HomeFragment.java index ad076fd..ee4a218 100644 --- a/app/src/main/java/prototype/xd/scheduler/fragments/HomeFragment.java +++ b/app/src/main/java/prototype/xd/scheduler/fragments/HomeFragment.java @@ -1,7 +1,6 @@ package prototype.xd.scheduler.fragments; -import static prototype.xd.scheduler.utilities.DateManager.currentlySelectedTimestampUTC; -import static prototype.xd.scheduler.utilities.DateManager.dateStringUTCFromMsUTC; +import static prototype.xd.scheduler.utilities.DateManager.getCurrentlySelectedDate; import static prototype.xd.scheduler.utilities.DateManager.getEndOfMonthDayUTC; import static prototype.xd.scheduler.utilities.DateManager.getStartOfMonthDayUTC; import static prototype.xd.scheduler.utilities.DateManager.selectDate; @@ -155,7 +154,7 @@ private void setupListeners(@NonNull ContentWrapperBinding contentBnd, todoListViewAdapter.notifyEntryListChanged(); // update the status text with entry count int events = todoListViewAdapter.getItemCount(); - binding.contentWrapper.toolbar.setTitle(getString(R.string.status, dateStringUTCFromMsUTC(currentlySelectedTimestampUTC), events)); + binding.contentWrapper.toolbar.setTitle(getString(R.string.status, getCurrentlySelectedDate(), events)); binding.contentWrapper.content.noEventsText.setVisibility(events == 0 ? View.VISIBLE : View.GONE); }); diff --git a/app/src/main/java/prototype/xd/scheduler/utilities/DateManager.java b/app/src/main/java/prototype/xd/scheduler/utilities/DateManager.java index 85a0ac2..7d21161 100644 --- a/app/src/main/java/prototype/xd/scheduler/utilities/DateManager.java +++ b/app/src/main/java/prototype/xd/scheduler/utilities/DateManager.java @@ -49,7 +49,6 @@ private DateManager() throws InstantiationException { private static LocalDate currentDate = LocalDate.now(); public static long currentlySelectedDayUTC = DAY_FLAG_GLOBAL; - public static long currentlySelectedTimestampUTC = DAY_FLAG_GLOBAL; @NonNull public static final Locale systemLocale = Objects.requireNonNull(LocaleList.getDefault().get(0)); @@ -121,7 +120,6 @@ public static synchronized void updateDate() { public static synchronized void selectDate(@NonNull LocalDate date) { updateDate(); currentlySelectedDayUTC = date.toEpochDay(); - currentlySelectedTimestampUTC = daysToMs(currentlySelectedDayUTC); } public static long getStartOfMonthDayUTC(@NonNull YearMonth month) { @@ -182,13 +180,13 @@ public static long msToDays(long msUTC) { } public static long daysToMs(long daysUTC) { - return TimeUnit.MILLISECONDS.convert(daysUTC, TimeUnit.DAYS) + ONE_MINUTE_MS; + return TimeUnit.MILLISECONDS.convert(daysUTC, TimeUnit.DAYS); } - // return date given a UTC timestamp + // return currently selected date date @NonNull - public static String dateStringUTCFromMsUTC(long msUTC) { - return dateFormat.format(msUTCtoLocalDate(msUTC, ZoneOffset.UTC)); + public static String getCurrentlySelectedDate() { + return dateFormat.format(msUTCtoLocalDate(daysToMs(currentlySelectedDayUTC), ZoneOffset.UTC)); } // return date (months are 3 letters instead of numbers) and time given a UTC timestamp diff --git a/app/src/main/java/prototype/xd/scheduler/utilities/TodoEntryManager.java b/app/src/main/java/prototype/xd/scheduler/utilities/TodoEntryManager.java index 94dd528..9f8db91 100644 --- a/app/src/main/java/prototype/xd/scheduler/utilities/TodoEntryManager.java +++ b/app/src/main/java/prototype/xd/scheduler/utilities/TodoEntryManager.java @@ -94,11 +94,12 @@ public void accept(@NonNull TodoEntry entry, @NonNull Set parameters) { && todoEntries.displayUpcomingExpired; // parameters that change event range - if (extendedDaysChanged || coreDaysChanged) { + if (coreDaysChanged || extendedDaysChanged) { todoEntries.notifyEntryVisibilityChanged( entry, coreDaysChanged, + extendedDaysChanged, daysToRebind, // include all days if BG_COLOR changed, else include just the difference !parameters.contains(BG_COLOR.CURRENT.key)); @@ -351,6 +352,7 @@ private void notifyDatasetChanged(boolean timezoneChanged) { todoEntries.notifyEntryVisibilityChanged( todoEntry, true, + true, daysToRebind, true); } diff --git a/app/src/main/java/prototype/xd/scheduler/views/DateSelectButton.java b/app/src/main/java/prototype/xd/scheduler/views/DateSelectButton.java index a3e3269..76cd8de 100644 --- a/app/src/main/java/prototype/xd/scheduler/views/DateSelectButton.java +++ b/app/src/main/java/prototype/xd/scheduler/views/DateSelectButton.java @@ -1,9 +1,8 @@ package prototype.xd.scheduler.views; -import static prototype.xd.scheduler.utilities.DateManager.currentlySelectedDayUTC; import static prototype.xd.scheduler.utilities.DateManager.dateStringMonthNamesUTCFromMsUTC; -import static prototype.xd.scheduler.utilities.DateManager.msToDays; import static prototype.xd.scheduler.utilities.DateManager.daysToMs; +import static prototype.xd.scheduler.utilities.DateManager.msToDays; import android.content.Context; import android.util.AttributeSet; @@ -21,8 +20,8 @@ public class DateSelectButton extends MaterialButton { - private Long selectedDayUTC; - private Long selectedMsUTC; + private volatile Long selectedDayUTC; + private volatile Long selectedMsUTC; private MaterialDatePicker.Builder datePickerBuilder; @@ -49,13 +48,10 @@ public DateSelectButton(@NonNull Context context, @Nullable AttributeSet attrs) } public void setup(@NonNull FragmentManager fragmentManager, long initialDay) { - if(initialDay == -1) { - initialDay = currentlySelectedDayUTC; - } long initialMsUTC = daysToMs(initialDay); selectedDayUTC = initialDay; selectedMsUTC = initialMsUTC; - + datePickerBuilder.setSelection(initialMsUTC); MaterialDatePicker datePicker = datePickerBuilder.build();