From 1149fa941bb3542f5db235a4ee8e5687f79f5e68 Mon Sep 17 00:00:00 2001 From: Yuri Volkov Date: Sat, 20 Jul 2019 08:44:59 +0300 Subject: [PATCH] #308 Tasks do have Start Date --- .../todoagenda/task/AbstractTaskProvider.java | 21 --------- .../andstatus/todoagenda/task/TaskEvent.java | 47 +++++++++++++++++-- .../task/dmfs/DmfsOpenTasksEvent.java | 5 ++ .../task/dmfs/DmfsOpenTasksProvider.java | 5 +- .../task/samsung/SamsungTaskEvent.java | 5 ++ .../task/samsung/SamsungTasksProvider.java | 5 +- .../todoagenda/widget/TaskEntry.java | 2 +- 7 files changed, 57 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java b/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java index c6084d4f..e113578e 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/AbstractTaskProvider.java @@ -19,30 +19,9 @@ public AbstractTaskProvider(Context context, int widgetId) { @Override protected void initialiseParameters() { super.initialiseParameters(); - // Move endOfTime to end of day to include all tasks in the last day of range - mEndOfTimeRange = mEndOfTimeRange.millisOfDay().withMaximumValue(); now = DateUtil.now(zone); } public abstract List getTasks(); - - protected DateTime getTaskDate(Long dueMillis, Long startMillis) { - DateTime dueDate; - if (dueMillis != null) { - dueDate = new DateTime(dueMillis, zone); - } else { - if (startMillis != null) { - dueDate = new DateTime(startMillis, zone); - } else { - dueDate = now; - } - } - - if (dueDate.isBefore(now)) { - dueDate = now; - } - - return dueDate.withTimeAtStartOfDay(); - } } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java b/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java index 92d9ed43..a19c5986 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java @@ -1,12 +1,21 @@ package org.andstatus.todoagenda.task; import android.content.Intent; + +import org.andstatus.todoagenda.DateUtil; import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; public abstract class TaskEvent { private long id; private String title; - private DateTime taskDate; + private final DateTimeZone zone; + private DateTime startDate; + private DateTime dueDate; + + protected TaskEvent(DateTimeZone zone) { + this.zone = zone; + } public long getId() { return id; @@ -24,13 +33,41 @@ public void setTitle(String title) { this.title = title; } - public DateTime getTaskDate() { - return taskDate; + public DateTime getStartDate() { + return startDate; } - public void setTaskDate(DateTime taskDate) { - this.taskDate = taskDate; + public DateTime getDueDate() { + return dueDate; } public abstract Intent createOpenCalendarEventIntent(); + + public void setDates(Long startMillis, Long dueMillis) { + startDate = toStartDate(startMillis, dueMillis); + dueDate = toDueDate(startMillis, dueMillis); + } + + private DateTime toStartDate(Long startMillis, Long dueMillis) { + DateTime startDate; + if (startMillis != null) { + startDate = new DateTime(startMillis, zone); + } else { + if (dueMillis != null) { + startDate = new DateTime(dueMillis, zone); + } else { + startDate = DateUtil.now(zone).withTimeAtStartOfDay(); + } + } + return startDate; + } + + private DateTime toDueDate(Long startMillis, Long dueMillis) { + DateTime dueDate = dueMillis == null + ? DateUtil.now(zone).withTimeAtStartOfDay() + : new DateTime(dueMillis, zone); + return startMillis == null + ? dueDate.plusSeconds(1) + : dueDate; + } } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksEvent.java b/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksEvent.java index 687c6e5c..5358143a 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksEvent.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksEvent.java @@ -4,8 +4,13 @@ import android.content.Intent; import org.andstatus.todoagenda.CalendarIntentUtil; import org.andstatus.todoagenda.task.TaskEvent; +import org.joda.time.DateTimeZone; public class DmfsOpenTasksEvent extends TaskEvent { + public DmfsOpenTasksEvent(DateTimeZone zone) { + super(zone); + } + @Override public Intent createOpenCalendarEventIntent() { Intent intent = CalendarIntentUtil.createCalendarIntent(); diff --git a/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksProvider.java b/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksProvider.java index aeae7d53..00fcce97 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/dmfs/DmfsOpenTasksProvider.java @@ -87,7 +87,7 @@ private String getWhereClause() { } private TaskEvent createTask(Cursor cursor) { - TaskEvent task = new DmfsOpenTasksEvent(); + TaskEvent task = new DmfsOpenTasksEvent(zone); task.setId(cursor.getLong(cursor.getColumnIndex(DmfsOpenTasksContract.COLUMN_ID))); task.setTitle(cursor.getString(cursor.getColumnIndex(DmfsOpenTasksContract.COLUMN_TITLE))); @@ -101,8 +101,7 @@ private TaskEvent createTask(Cursor cursor) { if (!cursor.isNull(startDateIdx)) { startMillis = cursor.getLong(startDateIdx); } - task.setTaskDate(getTaskDate(dueMillis, startMillis)); - + task.setDates(startMillis, dueMillis); return task; } } diff --git a/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTaskEvent.java b/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTaskEvent.java index c8859d32..7bf0a397 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTaskEvent.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTaskEvent.java @@ -6,9 +6,14 @@ import org.andstatus.todoagenda.CalendarIntentUtil; import org.andstatus.todoagenda.task.TaskEvent; +import org.joda.time.DateTimeZone; public class SamsungTaskEvent extends TaskEvent { + public SamsungTaskEvent(DateTimeZone zone) { + super(zone); + } + @Override public Intent createOpenCalendarEventIntent() { Intent intent = CalendarIntentUtil.createCalendarIntent(); diff --git a/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTasksProvider.java b/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTasksProvider.java index 2a327178..2d02ab79 100644 --- a/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTasksProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/task/samsung/SamsungTasksProvider.java @@ -76,7 +76,7 @@ private String getWhereClause() { } private TaskEvent createTask(Cursor cursor) { - TaskEvent task = new SamsungTaskEvent(); + TaskEvent task = new SamsungTaskEvent(zone); task.setId(cursor.getLong(cursor.getColumnIndex(SamsungTasksContract.COLUMN_ID))); task.setTitle(cursor.getString(cursor.getColumnIndex(SamsungTasksContract.COLUMN_TITLE))); @@ -85,8 +85,7 @@ private TaskEvent createTask(Cursor cursor) { if (!cursor.isNull(dueDateIdx)) { dueMillis = cursor.getLong(dueDateIdx); } - task.setTaskDate(getTaskDate(dueMillis, null)); - + task.setDates(null, dueMillis); return task; } } diff --git a/app/src/main/java/org/andstatus/todoagenda/widget/TaskEntry.java b/app/src/main/java/org/andstatus/todoagenda/widget/TaskEntry.java index 29cc5269..ec4d086c 100644 --- a/app/src/main/java/org/andstatus/todoagenda/widget/TaskEntry.java +++ b/app/src/main/java/org/andstatus/todoagenda/widget/TaskEntry.java @@ -8,7 +8,7 @@ public class TaskEntry extends WidgetEntry { public static TaskEntry fromEvent(TaskEvent event) { TaskEntry entry = new TaskEntry(); entry.event = event; - entry.setStartDate(event.getTaskDate()); + entry.setStartDate(event.getStartDate()); return entry; }