diff --git a/api/src/main/java/com/todoroo/andlib/data/AbstractDatabase.java b/api/src/main/java/com/todoroo/andlib/data/AbstractDatabase.java index 7d408fa0f..2ac46fcc6 100644 --- a/api/src/main/java/com/todoroo/andlib/data/AbstractDatabase.java +++ b/api/src/main/java/com/todoroo/andlib/data/AbstractDatabase.java @@ -177,15 +177,6 @@ abstract public class AbstractDatabase { database = null; } - /** - * Clear all data in database. Warning: this does what it says. Any open - * database resources will be abruptly closed. - */ - public synchronized final void clear() { - close(); - ContextManager.getContext().deleteDatabase(getName()); - } - /** * @return sql database. opens database if not yet open */ diff --git a/api/src/main/java/com/todoroo/andlib/sql/Criterion.java b/api/src/main/java/com/todoroo/andlib/sql/Criterion.java index 4747a2441..29cc4765d 100644 --- a/api/src/main/java/com/todoroo/andlib/sql/Criterion.java +++ b/api/src/main/java/com/todoroo/andlib/sql/Criterion.java @@ -26,13 +26,6 @@ public abstract class Criterion { } }; - public static Criterion none = new Criterion(Operator.exists) { - @Override - protected void populate(StringBuilder sb) { - sb.append(0); - } - }; - public static Criterion and(final Criterion criterion, final Criterion... criterions) { return new Criterion(Operator.and) { diff --git a/api/src/main/java/org/tasks/date/DateTimeUtils.java b/api/src/main/java/org/tasks/date/DateTimeUtils.java index a6617bd68..dc35fbc17 100644 --- a/api/src/main/java/org/tasks/date/DateTimeUtils.java +++ b/api/src/main/java/org/tasks/date/DateTimeUtils.java @@ -20,10 +20,6 @@ public class DateTimeUtils { return new Date(year - 1900, month - 1, day); } - public static Date newDate(int year, int month, int day, int hour, int minute, int second) { - return new Date(year - 1900, month - 1, day, hour, minute, second); - } - public static Date newDateUtc(int year, int month, int day, int hour, int minute, int second) { return newDate(Date.UTC(year - 1900, month - 1, day, hour, minute, second)); } diff --git a/astrid/src/androidTest/java/com/todoroo/andlib/utility/DateUtilitiesTest.java b/astrid/src/androidTest/java/com/todoroo/andlib/utility/DateUtilitiesTest.java index 33f289929..49351ee20 100644 --- a/astrid/src/androidTest/java/com/todoroo/andlib/utility/DateUtilitiesTest.java +++ b/astrid/src/androidTest/java/com/todoroo/andlib/utility/DateUtilitiesTest.java @@ -26,6 +26,7 @@ import static com.todoroo.andlib.utility.DateUtilities.getWeekdayShort; import static com.todoroo.andlib.utility.DateUtilities.isEndOfMonth; import static com.todoroo.andlib.utility.DateUtilities.oneMonthFromNow; import static org.tasks.Freeze.freezeAt; +import static org.tasks.TestUtilities.newDateTime; import static org.tasks.date.DateTimeUtils.newDate; public class DateUtilitiesTest extends AndroidTestCase { @@ -96,23 +97,23 @@ public class DateUtilitiesTest extends AndroidTestCase { public void testGet24HourTime() { DateUtilities.is24HourOverride = true; - assertEquals("9:05", getTimeString(null, newDate(2014, 1, 4, 9, 5, 36))); - assertEquals("13:00", getTimeString(null, newDate(2014, 1, 4, 13, 0, 1))); + assertEquals("9:05", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36))); + assertEquals("13:00", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 1))); } public void testGetTime() { DateUtilities.is24HourOverride = false; - assertEquals("9:05 AM", getTimeString(null, newDate(2014, 1, 4, 9, 5, 36))); - assertEquals("1:05 PM", getTimeString(null, newDate(2014, 1, 4, 13, 5, 36))); + assertEquals("9:05 AM", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36))); + assertEquals("1:05 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 5, 36))); } public void testGetTimeWithNoMinutes() { DateUtilities.is24HourOverride = false; - assertEquals("1 PM", getTimeString(null, newDate(2014, 1, 4, 13, 0, 59))); // derp? + assertEquals("1 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 59))); // derp? } public void testGetDateStringWithYear() { - assertEquals("Jan 4, 2014", getDateString(newDate(2014, 1, 4, 0, 0, 0))); + assertEquals("Jan 4, 2014", getDateString(newDateTime(2014, 1, 4, 0, 0, 0))); } public void testGetDateStringHidingYear() { diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/dao/TaskDaoTests.java b/astrid/src/androidTest/java/com/todoroo/astrid/dao/TaskDaoTests.java index d7dd1dcd1..6b58bd95c 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/dao/TaskDaoTests.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/dao/TaskDaoTests.java @@ -7,7 +7,6 @@ package com.todoroo.astrid.dao; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; @@ -37,7 +36,7 @@ public class TaskDaoTests extends DatabaseTestCase { // create task "happy" Task task = new Task(); task.setTitle("happy"); - assertTrue(taskDao.save(task)); + taskDao.save(task); cursor = taskDao.query( Query.select(IDS)); assertEquals(1, cursor.getCount()); @@ -50,7 +49,7 @@ public class TaskDaoTests extends DatabaseTestCase { // create task "sad" task = new Task(); task.setTitle("sad"); - assertTrue(taskDao.save(task)); + taskDao.save(task); cursor = taskDao.query( Query.select(IDS)); assertEquals(2, cursor.getCount()); @@ -60,7 +59,7 @@ public class TaskDaoTests extends DatabaseTestCase { long sadId = task.getId(); assertNotSame(Task.NO_ID, sadId); task.setTitle("melancholy"); - assertTrue(taskDao.save(task)); + taskDao.save(task); cursor = taskDao.query( Query.select(IDS)); assertEquals(2, cursor.getCount()); @@ -80,35 +79,35 @@ public class TaskDaoTests extends DatabaseTestCase { // create normal task Task task = new Task(); task.setTitle("normal"); - assertTrue(taskDao.save(task)); + taskDao.save(task); // create blank task task = new Task(); task.setTitle(""); - assertTrue(taskDao.save(task)); + taskDao.save(task); // create hidden task task = new Task(); task.setTitle("hidden"); task.setHideUntil(DateUtilities.now() + 10000); - assertTrue(taskDao.save(task)); + taskDao.save(task); // create task with deadlines task = new Task(); task.setTitle("deadlineInFuture"); task.setDueDate(DateUtilities.now() + 10000); - assertTrue(taskDao.save(task)); + taskDao.save(task); task = new Task(); task.setTitle("deadlineInPast"); task.setDueDate(DateUtilities.now() - 10000); - assertTrue(taskDao.save(task)); + taskDao.save(task); // create completed task task = new Task(); task.setTitle("completed"); task.setCompletionDate(DateUtilities.now() - 10000); - assertTrue(taskDao.save(task)); + taskDao.save(task); // check has no name TodorooCursor cursor = taskDao.query( @@ -118,39 +117,12 @@ public class TaskDaoTests extends DatabaseTestCase { assertEquals("", cursor.getString(1)); cursor.close(); - // check has deadlines - cursor = taskDao.query(Query.select(TITLES).where( - TaskCriteria.hasDeadlines()).orderBy(Order.asc(Task.DUE_DATE))); - assertEquals(2, cursor.getCount()); - cursor.moveToNext(); - assertEquals("deadlineInPast", cursor.getString(1)); - cursor.moveToNext(); - assertEquals("deadlineInFuture", cursor.getString(1)); - cursor.close(); - // check is active cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria. isActive())); assertEquals(5, cursor.getCount()); cursor.close(); - // check due before / after - cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria. - dueBeforeNow())); - cursor.moveToNext(); - assertEquals(1, cursor.getCount()); - cursor.close(); - cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria. - dueAfterNow())); - assertEquals(1, cursor.getCount()); - cursor.close(); - - // check completed before - cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria. - completed())); - assertEquals(1, cursor.getCount()); - cursor.close(); - // check is visible cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria. isVisible())); @@ -170,7 +142,7 @@ public class TaskDaoTests extends DatabaseTestCase { // create task "happy" Task task = new Task(); task.setTitle("happy"); - assertTrue(taskDao.save(task)); + taskDao.save(task); cursor = taskDao.query( Query.select(IDS)); assertEquals(1, cursor.getCount()); @@ -196,7 +168,7 @@ public class TaskDaoTests extends DatabaseTestCase { task.setTitle("happy"); task.setID(1L); - assertFalse(taskDao.save(task)); + taskDao.save(task); cursor = taskDao.query( Query.select(IDS)); diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java b/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java index 045e1576b..eae85780b 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java @@ -22,6 +22,8 @@ import javax.inject.Inject; @SuppressWarnings("nls") public class GtasksTaskListUpdaterTest extends DatabaseTestCase { + private static final int VALUE_UNSET = -1; + @Inject GtasksTaskListUpdater gtasksTaskListUpdater; @Inject GtasksListService gtasksListService; @Inject GtasksMetadataService gtasksMetadataService; @@ -80,7 +82,7 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase { public void disabled_testNewTaskOrder() { givenTasksABCDE(); - Task newTask = createTask("F", GtasksMetadata.VALUE_UNSET, 0); + Task newTask = createTask("F", VALUE_UNSET, 0); whenCalculatingOrder(); thenExpectMetadataIndentAndOrder(newTask, 5, 0); @@ -139,7 +141,13 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase { } private void whenCalculatingParentsAndSiblings() { - gtasksTaskListUpdater.createParentSiblingMaps(); + createParentSiblingMaps(); + } + + void createParentSiblingMaps() { + for(StoreObject list : gtasksListService.getLists()) { + gtasksTaskListUpdater.updateParentSiblingMapsFor(list); + } } private void whenCalculatingOrder() { @@ -172,9 +180,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase { taskService.save(task); Metadata metadata = gtasksMetadata.createEmptyMetadata(task.getId()); metadata.setValue(GtasksMetadata.LIST_ID, "1"); - if(order != GtasksMetadata.VALUE_UNSET) + if(order != VALUE_UNSET) metadata.setValue(GtasksMetadata.ORDER, order); - if(indent != GtasksMetadata.VALUE_UNSET) + if(indent != VALUE_UNSET) metadata.setValue(GtasksMetadata.INDENT, indent); metadataService.save(metadata); return task; diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java b/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java index 806dc8f51..8d2b1e5ba 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java @@ -22,6 +22,8 @@ import javax.inject.Inject; @SuppressWarnings("nls") public class GtasksTaskMovingTest extends DatabaseTestCase { + private static final int VALUE_UNSET = -1; + @Inject GtasksListService gtasksListService; @Inject GtasksMetadataService gtasksMetadataService; @Inject GtasksTaskListUpdater gtasksTaskListUpdater; @@ -281,9 +283,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase { taskService.save(task); Metadata metadata = gtasksMetadata.createEmptyMetadata(task.getId()); metadata.setValue(GtasksMetadata.LIST_ID, "1"); - if(order != GtasksMetadata.VALUE_UNSET) + if(order != VALUE_UNSET) metadata.setValue(GtasksMetadata.ORDER, order); - if(indent != GtasksMetadata.VALUE_UNSET) + if(indent != VALUE_UNSET) metadata.setValue(GtasksMetadata.INDENT, indent); metadataService.save(metadata); return task; diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/repeats/AdvancedRepeatTest.java b/astrid/src/androidTest/java/com/todoroo/astrid/repeats/AdvancedRepeatTest.java index e7ef2dad9..da1bd4bdc 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/repeats/AdvancedRepeatTest.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/repeats/AdvancedRepeatTest.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import static org.tasks.TestUtilities.newDateTime; import static org.tasks.date.DateTimeUtils.newDate; public class AdvancedRepeatTest extends AndroidTestCase { @@ -46,7 +47,7 @@ public class AdvancedRepeatTest extends AndroidTestCase { buildRRule(1, Frequency.DAILY); // test specific day & time - long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime()); + long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime()); task.setDueDate(dayWithTime); long nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY; @@ -58,7 +59,7 @@ public class AdvancedRepeatTest extends AndroidTestCase { buildRRule(1, Frequency.DAILY); // test specific day & time - long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime()); + long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime()); task.setDueDate(dayWithTime); Date todayWithTime = newDate(); diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/test/DatabaseTestCase.java b/astrid/src/androidTest/java/com/todoroo/astrid/test/DatabaseTestCase.java index 59e6dc53e..4b55c4b27 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/test/DatabaseTestCase.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/test/DatabaseTestCase.java @@ -19,7 +19,8 @@ public abstract class DatabaseTestCase extends InjectingTestCase { protected void setUp() { super.setUp(); - database.clear(); + database.close(); + getContext().deleteDatabase(database.getName()); database.openForWriting(); } diff --git a/astrid/src/androidTest/java/com/todoroo/astrid/utility/AstridDefaultPreferenceSpecTest.java b/astrid/src/androidTest/java/com/todoroo/astrid/utility/AstridDefaultPreferenceSpecTest.java index 012642349..85c200012 100644 --- a/astrid/src/androidTest/java/com/todoroo/astrid/utility/AstridDefaultPreferenceSpecTest.java +++ b/astrid/src/androidTest/java/com/todoroo/astrid/utility/AstridDefaultPreferenceSpecTest.java @@ -93,11 +93,11 @@ public class AstridDefaultPreferenceSpecTest extends AndroidTestCase { } private boolean quietHoursEnabled() { - return preferences.getBoolean(R.string.p_rmd_enable_quiet); + return preferences.getBoolean(R.string.p_rmd_enable_quiet, false); } private boolean hasMigrated() { - return preferences.getBoolean(R.string.p_rmd_hasMigrated); + return preferences.getBoolean(R.string.p_rmd_hasMigrated, false); } private void setOldQuietHoursStart(int index) { diff --git a/astrid/src/androidTest/java/org/tasks/TestUtilities.java b/astrid/src/androidTest/java/org/tasks/TestUtilities.java index 8fdab7da5..34ee152f1 100644 --- a/astrid/src/androidTest/java/org/tasks/TestUtilities.java +++ b/astrid/src/androidTest/java/org/tasks/TestUtilities.java @@ -2,6 +2,8 @@ package org.tasks; import android.content.Context; +import java.util.Date; + public class TestUtilities { private static boolean mockitoInitialized; @@ -12,4 +14,8 @@ public class TestUtilities { mockitoInitialized = true; } } + + public static Date newDateTime(int year, int month, int day, int hour, int minute, int second) { + return new Date(year - 1900, month - 1, day, hour, minute, second); + } } diff --git a/astrid/src/androidTest/java/org/tasks/date/DateTimeUtilsTest.java b/astrid/src/androidTest/java/org/tasks/date/DateTimeUtilsTest.java index 6533e6d72..f13e3e8e8 100644 --- a/astrid/src/androidTest/java/org/tasks/date/DateTimeUtilsTest.java +++ b/astrid/src/androidTest/java/org/tasks/date/DateTimeUtilsTest.java @@ -9,6 +9,7 @@ import org.tasks.Snippet; import java.util.Date; import static org.tasks.Freeze.freezeAt; +import static org.tasks.TestUtilities.newDateTime; import static org.tasks.date.DateTimeUtils.currentTimeMillis; import static org.tasks.date.DateTimeUtils.newDate; import static org.tasks.date.DateTimeUtils.newDateUtc; @@ -35,7 +36,7 @@ public class DateTimeUtilsTest extends AndroidTestCase { } public void testCreateNewDateTime() { - assertEquals(new Date(114, 0, 1, 15, 17, 53), newDate(2014, 1, 1, 15, 17, 53)); + assertEquals(new Date(114, 0, 1, 15, 17, 53), newDateTime(2014, 1, 1, 15, 17, 53)); } public void testCreateNewUtcDate() { diff --git a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index e21628e5d..626d71b53 100644 --- a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -15,7 +15,6 @@ import android.content.IntentFilter; import android.content.res.Resources; import android.database.Cursor; import android.database.sqlite.SQLiteException; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.TextUtils; @@ -109,7 +108,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel private static final long WAIT_BEFORE_AUTOSYNC = 2000L; public static final int ACTIVITY_EDIT_TASK = 0; public static final int ACTIVITY_SETTINGS = 1; - public static final int ACTIVITY_MENU_EXTERNAL = 4; public static final int ACTIVITY_REQUEST_NEW_FILTER = 5; // --- menu codes @@ -376,15 +374,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel // Hook } - protected void addMenuItem(Menu menu, CharSequence title, Drawable image, Intent customIntent, int id) { - Activity activity = getActivity(); - if(!(activity instanceof TaskListActivity)) { - MenuItem item = menu.add(Menu.NONE, id, Menu.NONE, title); - item.setIcon(image); - item.setIntent(customIntent); - } - } - protected void setUpUiComponents() { // set listener for quick-changing task priority getListView().setOnKeyListener(new OnKeyListener() { diff --git a/astrid/src/main/java/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/main/java/com/todoroo/astrid/dao/TaskDao.java index 5a8b3be76..60ef16b64 100644 --- a/astrid/src/main/java/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/main/java/com/todoroo/astrid/dao/TaskDao.java @@ -102,26 +102,6 @@ public class TaskDao extends RemoteModelDao { return Task.HIDE_UNTIL.lt(Functions.now()); } - /** @return tasks that have a due date */ - public static Criterion hasDeadlines() { - return Task.DUE_DATE.neq(0); - } - - /** @return tasks that are due before a certain unixtime */ - public static Criterion dueBeforeNow() { - return Criterion.and(Task.DUE_DATE.gt(0), Task.DUE_DATE.lt(Functions.now())); - } - - /** @return tasks that are due after a certain unixtime */ - public static Criterion dueAfterNow() { - return Task.DUE_DATE.gt(Functions.now()); - } - - /** @return tasks completed before a given unixtime */ - public static Criterion completed() { - return Criterion.and(Task.COMPLETION_DATE.gt(0), Task.COMPLETION_DATE.lt(Functions.now())); - } - /** @return tasks that have a blank or null title */ public static Criterion hasNoTitle() { return Criterion.or(Task.TITLE.isNull(), Task.TITLE.eq("")); @@ -164,20 +144,17 @@ public class TaskDao extends RemoteModelDao { * * @return true if save occurred, false otherwise (i.e. nothing changed) */ - public boolean save(Task task) { - boolean saveSuccessful; + public void save(Task task) { if (task.getId() == Task.NO_ID) { try { - saveSuccessful = createNew(task); + createNew(task); } catch (SQLiteConstraintException e) { log.error(e.getMessage(), e); - saveSuccessful = handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists + handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists } } else { - saveSuccessful = saveExisting(task); + saveExisting(task); } - - return saveSuccessful; } public boolean handleSQLiteConstraintException(Task task) { diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java index 650139efa..2b2ab32d3 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java @@ -23,8 +23,6 @@ import javax.inject.Singleton; @Singleton public class GtasksMetadata { - static final int VALUE_UNSET = -1; - /** metadata key */ public static final String METADATA_KEY = "gtasks"; //$NON-NLS-1$ diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java index 14aa60258..6cbc510c7 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java @@ -112,15 +112,6 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater