Skip to content

Commit

Permalink
plusonelabs#356 End date is not needed in a Widget entry: it is the s…
Browse files Browse the repository at this point in the history
…ame as in an underlying event
  • Loading branch information
yvolk committed Dec 28, 2019
1 parent f367a1c commit b45122d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ public class CalendarEntry extends WidgetEntry<CalendarEntry> {
private CalendarEvent event;

public static CalendarEntry fromEvent(CalendarEvent event, DateTime entryDate) {
CalendarEntry entry = new CalendarEntry(entryDate, event.getEndDate());
CalendarEntry entry = new CalendarEntry(entryDate);
entry.allDay = event.isAllDay();
entry.event = event;
return entry;
}

private CalendarEntry(DateTime entryDate, DateTime eventEndDate) {
super(WidgetEntryPosition.ENTRY_DATE, entryDate, eventEndDate);
private CalendarEntry(DateTime entryDate) {
super(WidgetEntryPosition.ENTRY_DATE, entryDate);
}

@Nullable
@Override
public DateTime getEndDate() {
return event.getEndDate();
}

@Override
Expand Down Expand Up @@ -78,7 +84,7 @@ public boolean isStartOfMultiDayEvent() {
}

public boolean isEndOfMultiDayEvent() {
return isPartOfMultiDayEvent() && isLastEntryOfEvent;
return isPartOfMultiDayEvent() && isLastEntryOfEvent();
}

public boolean spansOneFullDay() {
Expand Down Expand Up @@ -127,7 +133,7 @@ private String createTimeStringForCalendarEntry(Context context) {
startStr = createTimeString(context, entryDate);
}
if (getSettings().getShowEndTime()) {
if (!isDateDefined(event.getEndDate()) || (isPartOfMultiDayEvent() && !isLastEntryOfEvent)) {
if (!isDateDefined(event.getEndDate()) || (isPartOfMultiDayEvent() && !isLastEntryOfEvent())) {
endStr = ARROW;
separator = SPACE;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public class DayHeader extends WidgetEntry<DayHeader> {

public DayHeader(DateTime date) {
super(DAY_HEADER, date, null);
super(DAY_HEADER, date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum LastEntryType {
public final LastEntryType type;

public LastEntry(LastEntryType type, DateTime date) {
super(LIST_FOOTER, date, null);
super(LIST_FOOTER, date);
this.type = type;
}
}
14 changes: 11 additions & 3 deletions app/src/main/java/org/andstatus/todoagenda/widget/TaskEntry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.andstatus.todoagenda.widget;

import androidx.annotation.Nullable;

import org.andstatus.todoagenda.prefs.OrderedEventSource;
import org.andstatus.todoagenda.task.TaskEvent;
import org.joda.time.DateTime;
Expand All @@ -10,13 +12,19 @@ public class TaskEntry extends WidgetEntry<TaskEntry> {
private TaskEvent event;

public static TaskEntry fromEvent(TaskEvent event) {
TaskEntry entry = new TaskEntry(ENTRY_DATE, event.getStartDate(), event.getDueDate());
TaskEntry entry = new TaskEntry(ENTRY_DATE, event.getStartDate());
entry.event = event;
return entry;
}

private TaskEntry(WidgetEntryPosition entryPosition, DateTime entryDate, DateTime endDate) {
super(entryPosition, entryDate, endDate);
private TaskEntry(WidgetEntryPosition entryPosition, DateTime entryDate) {
super(entryPosition, entryDate);
}

@Nullable
@Override
public DateTime getEndDate() {
return event.getDueDate();
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/org/andstatus/todoagenda/widget/WidgetEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ public abstract class WidgetEntry<T extends WidgetEntry<T>> implements Comparabl

public final WidgetEntryPosition entryPosition;
public final DateTime entryDate;
@Nullable
public final DateTime endDate;
public final boolean isLastEntryOfEvent;

protected WidgetEntry(WidgetEntryPosition entryPosition, DateTime entryDate, @Nullable DateTime eventEndDate) {
protected WidgetEntry(WidgetEntryPosition entryPosition, DateTime entryDate) {
this.entryPosition = entryPosition;
this.entryDate = fixEntryDate(entryPosition, entryDate);
endDate = eventEndDate;
isLastEntryOfEvent = endDate == null ||
!entryPosition.entryDateIsRequired ||
endDate.isBefore(DateUtil.startOfNextDay(this.entryDate));
}

private static DateTime fixEntryDate(WidgetEntryPosition entryPosition, DateTime entryDate) {
Expand Down Expand Up @@ -64,12 +57,19 @@ private static void throwIfNull(WidgetEntryPosition entryPosition, DateTime entr
}
}

public boolean isLastEntryOfEvent() {
return getEndDate() == null ||
!entryPosition.entryDateIsRequired ||
getEndDate().isBefore(DateUtil.startOfNextDay(this.entryDate));
}

public DateTime getEntryDay() {
return entryDate.withTimeAtStartOfDay();
}

@Nullable
public DateTime getEndDate() {
return endDate;
return null;
}

public OrderedEventSource getSource() {
Expand Down Expand Up @@ -136,7 +136,7 @@ public TimeSection getTimeSection() {
}
return DateUtil.isBeforeToday(entryDate)
? TimeSection.PAST
: (DateUtil.isToday(endDate) ? TimeSection.TODAY : TimeSection.FUTURE);
: (DateUtil.isToday(getEndDate()) ? TimeSection.TODAY : TimeSection.FUTURE);
}

public boolean duplicates(WidgetEntry other) {
Expand Down

0 comments on commit b45122d

Please sign in to comment.