mirror of https://github.com/tasks/tasks
Adjust hide until when due date modified by gtasks
parent
7e40bef31f
commit
087280fddd
@ -0,0 +1,60 @@
|
|||||||
|
package org.tasks.makers;
|
||||||
|
|
||||||
|
import com.natpryce.makeiteasy.Instantiator;
|
||||||
|
import com.natpryce.makeiteasy.Property;
|
||||||
|
import com.natpryce.makeiteasy.PropertyLookup;
|
||||||
|
import com.natpryce.makeiteasy.PropertyValue;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||||
|
import static org.tasks.makers.Maker.make;
|
||||||
|
|
||||||
|
public class TaskMaker {
|
||||||
|
|
||||||
|
public static Property<Task, DateTime> DUE_DATE = newProperty();
|
||||||
|
public static Property<Task, DateTime> DUE_TIME = newProperty();
|
||||||
|
public static Property<Task, DateTime> REMINDER_LAST = newProperty();
|
||||||
|
public static Property<Task, Integer> HIDE_TYPE = newProperty();
|
||||||
|
public static Property<Task, Integer> REMINDERS = newProperty();
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public static Task newTask(PropertyValue<? super Task, ?>... properties) {
|
||||||
|
return make(instantiator, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Instantiator<Task> instantiator = new Instantiator<Task>() {
|
||||||
|
@Override
|
||||||
|
public Task instantiate(PropertyLookup<Task> lookup) {
|
||||||
|
Task task = new Task();
|
||||||
|
|
||||||
|
DateTime dueDate = lookup.valueOf(DUE_DATE, (DateTime) null);
|
||||||
|
if (dueDate != null) {
|
||||||
|
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.getMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime dueTime = lookup.valueOf(DUE_TIME, (DateTime) null);
|
||||||
|
if (dueTime != null) {
|
||||||
|
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, dueTime.getMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
int hideType = lookup.valueOf(HIDE_TYPE, -1);
|
||||||
|
if (hideType >= 0) {
|
||||||
|
task.setHideUntil(task.createHideUntil(hideType, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
int reminderFlags = lookup.valueOf(REMINDERS, -1);
|
||||||
|
if (reminderFlags >= 0) {
|
||||||
|
task.setReminderFlags(reminderFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime reminderLast = lookup.valueOf(REMINDER_LAST, (DateTime) null);
|
||||||
|
if (reminderLast != null) {
|
||||||
|
task.setReminderLast(reminderLast.getMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.todoroo.astrid.gtasks.sync;
|
||||||
|
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||||
|
import static com.todoroo.astrid.data.Task.HIDE_UNTIL_DUE;
|
||||||
|
import static com.todoroo.astrid.data.Task.HIDE_UNTIL_DUE_TIME;
|
||||||
|
import static com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider.mergeDates;
|
||||||
|
import static org.tasks.makers.TaskMaker.DUE_DATE;
|
||||||
|
import static org.tasks.makers.TaskMaker.DUE_TIME;
|
||||||
|
import static org.tasks.makers.TaskMaker.HIDE_TYPE;
|
||||||
|
import static org.tasks.makers.TaskMaker.newTask;
|
||||||
|
|
||||||
|
public class GtasksSyncV2ProviderTest extends AndroidTestCase {
|
||||||
|
|
||||||
|
public void testMergeDate() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
|
||||||
|
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(new DateTime(2016, 3, 11, 12, 0).getMillis(), remote.getDueDate().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMergeTime() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
|
||||||
|
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 11, 13, 30)));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2016, 3, 11, 13, 30, 1).getMillis(),
|
||||||
|
remote.getDueDate().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueDateAdjustHideBackwards() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
|
||||||
|
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(new DateTime(2016, 3, 11).getMillis(), remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueDateAdjustHideForwards() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 14)));
|
||||||
|
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(new DateTime(2016, 3, 14).getMillis(), remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueTimeAdjustHideBackwards() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
|
||||||
|
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),
|
||||||
|
with(HIDE_TYPE, HIDE_UNTIL_DUE_TIME));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(new DateTime(2016, 3, 11, 13, 30, 1).getMillis(), remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueTimeAdjustTimeForwards() {
|
||||||
|
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 14)));
|
||||||
|
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),
|
||||||
|
with(HIDE_TYPE, HIDE_UNTIL_DUE_TIME));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(new DateTime(2016, 3, 14, 13, 30, 1).getMillis(), remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueDateClearHide() {
|
||||||
|
Task remote = newTask();
|
||||||
|
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(0, remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDueTimeClearHide() {
|
||||||
|
Task remote = newTask();
|
||||||
|
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),
|
||||||
|
with(HIDE_TYPE, HIDE_UNTIL_DUE_TIME));
|
||||||
|
|
||||||
|
mergeDates(remote, local);
|
||||||
|
|
||||||
|
assertEquals(0, remote.getHideUntil().longValue());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue