Skip to content

Commit

Permalink
#308 Tasks do have Start Date
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Jul 20, 2019
1 parent bfbcc25 commit 1149fa9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskEvent> 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();
}
}
47 changes: 42 additions & 5 deletions app/src/main/java/org/andstatus/todoagenda/task/TaskEvent.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1149fa9

Please sign in to comment.