diff --git a/app/schemas/com.todoroo.astrid.dao.Database/52.json b/app/schemas/com.todoroo.astrid.dao.Database/52.json new file mode 100644 index 000000000..ccf42e8d0 --- /dev/null +++ b/app/schemas/com.todoroo.astrid.dao.Database/52.json @@ -0,0 +1,721 @@ +{ + "formatVersion": 1, + "database": { + "version": 52, + "identityHash": "23e6e3a7316ca88f4c420928ee481149", + "entities": [ + { + "tableName": "notification", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `type` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "uid", + "columnName": "uid", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "taskId", + "columnName": "task", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "uid" + ], + "autoGenerate": true + }, + "indices": [ + { + "name": "index_notification_task", + "unique": true, + "columnNames": [ + "task" + ], + "createSql": "CREATE UNIQUE INDEX `index_notification_task` ON `${TABLE_NAME}` (`task`)" + } + ], + "foreignKeys": [] + }, + { + "tableName": "tagdata", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `name` TEXT, `color` INTEGER, `tagOrdering` TEXT, `deleted` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "tagOrdering", + "columnName": "tagOrdering", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "deleted", + "columnName": "deleted", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "userActivity", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `action` TEXT, `message` TEXT, `picture` TEXT, `target_id` TEXT, `created_at` INTEGER, `deleted_at` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "action", + "columnName": "action", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "message", + "columnName": "message", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "picture", + "columnName": "picture", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "targetId", + "columnName": "target_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "created", + "columnName": "created_at", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "deleted", + "columnName": "deleted_at", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "task_attachments", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `task_id` TEXT, `name` TEXT, `path` TEXT, `content_type` TEXT, `deleted_at` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "taskId", + "columnName": "task_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "path", + "columnName": "path", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "contentType", + "columnName": "content_type", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "deleted", + "columnName": "deleted_at", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "task_list_metadata", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `tag_uuid` TEXT, `filter` TEXT, `task_ids` TEXT)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "tagUuid", + "columnName": "tag_uuid", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "filter", + "columnName": "filter", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "taskIds", + "columnName": "task_ids", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "tasks", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` TEXT, `importance` INTEGER, `dueDate` INTEGER, `hideUntil` INTEGER, `created` INTEGER, `modified` INTEGER, `completed` INTEGER, `deleted` INTEGER, `notes` TEXT, `estimatedSeconds` INTEGER, `elapsedSeconds` INTEGER, `timerStart` INTEGER, `notificationFlags` INTEGER, `notifications` INTEGER, `lastNotified` INTEGER, `snoozeTime` INTEGER, `recurrence` TEXT, `repeatUntil` INTEGER, `calendarUri` TEXT, `remoteId` TEXT)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "importance", + "columnName": "importance", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "dueDate", + "columnName": "dueDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "hideUntil", + "columnName": "hideUntil", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "created", + "columnName": "created", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "modified", + "columnName": "modified", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "completed", + "columnName": "completed", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "deleted", + "columnName": "deleted", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "notes", + "columnName": "notes", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "estimatedSeconds", + "columnName": "estimatedSeconds", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "elapsedSeconds", + "columnName": "elapsedSeconds", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "timerStart", + "columnName": "timerStart", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "notificationFlags", + "columnName": "notificationFlags", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "notifications", + "columnName": "notifications", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastNotified", + "columnName": "lastNotified", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "snoozeTime", + "columnName": "snoozeTime", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "recurrence", + "columnName": "recurrence", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "repeatUntil", + "columnName": "repeatUntil", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "calendarUri", + "columnName": "calendarUri", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [ + { + "name": "t_rid", + "unique": true, + "columnNames": [ + "remoteId" + ], + "createSql": "CREATE UNIQUE INDEX `t_rid` ON `${TABLE_NAME}` (`remoteId`)" + } + ], + "foreignKeys": [] + }, + { + "tableName": "alarms", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `time` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "task", + "columnName": "task", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "time", + "columnName": "time", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "locations", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `name` TEXT, `latitude` REAL NOT NULL, `longitude` REAL NOT NULL, `radius` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "task", + "columnName": "task", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "latitude", + "columnName": "latitude", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "longitude", + "columnName": "longitude", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "radius", + "columnName": "radius", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "tags", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `name` TEXT, `tag_uid` TEXT, `task_uid` TEXT)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "task", + "columnName": "task", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "tagUid", + "columnName": "tag_uid", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "taskUid", + "columnName": "task_uid", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "google_tasks", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `remote_id` TEXT, `list_id` TEXT, `parent` INTEGER NOT NULL, `indent` INTEGER NOT NULL, `order` INTEGER NOT NULL, `remote_order` INTEGER NOT NULL, `last_sync` INTEGER NOT NULL, `deleted` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "task", + "columnName": "task", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "remoteId", + "columnName": "remote_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "listId", + "columnName": "list_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "parent", + "columnName": "parent", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "indent", + "columnName": "indent", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "order", + "columnName": "order", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "remoteOrder", + "columnName": "remote_order", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastSync", + "columnName": "last_sync", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "deleted", + "columnName": "deleted", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "filters", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `sql` TEXT, `values` TEXT, `criterion` TEXT)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "sql", + "columnName": "sql", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "values", + "columnName": "values", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "criterion", + "columnName": "criterion", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "google_task_lists", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remote_id` TEXT, `title` TEXT, `remote_order` INTEGER NOT NULL, `last_sync` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, `color` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "remoteId", + "columnName": "remote_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "remoteOrder", + "columnName": "remote_order", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastSync", + "columnName": "last_sync", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "deleted", + "columnName": "deleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"23e6e3a7316ca88f4c420928ee481149\")" + ] + } +} \ No newline at end of file diff --git a/app/src/amazon/java/org/tasks/tasklist/GtasksListFragment.java b/app/src/amazon/java/org/tasks/tasklist/GtasksListFragment.java index 4a73b504c..4e34babf2 100644 --- a/app/src/amazon/java/org/tasks/tasklist/GtasksListFragment.java +++ b/app/src/amazon/java/org/tasks/tasklist/GtasksListFragment.java @@ -2,7 +2,6 @@ package org.tasks.tasklist; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.GtasksFilter; -import com.todoroo.astrid.gtasks.GtasksList; public class GtasksListFragment extends TaskListFragment { public static TaskListFragment newGtasksListFragment(GtasksFilter gtasksFilter, GtasksList list) { diff --git a/app/src/amazon/java/org/tasks/ui/GoogleTaskListFragment.java b/app/src/amazon/java/org/tasks/ui/GoogleTaskListFragment.java index 541d81845..1fef660cd 100644 --- a/app/src/amazon/java/org/tasks/ui/GoogleTaskListFragment.java +++ b/app/src/amazon/java/org/tasks/ui/GoogleTaskListFragment.java @@ -1,7 +1,6 @@ package org.tasks.ui; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import org.tasks.R; import org.tasks.injection.FragmentComponent; diff --git a/app/src/androidTest/java/org/tasks/injection/TestModule.java b/app/src/androidTest/java/org/tasks/injection/TestModule.java index 4f539de42..5213ef1bb 100644 --- a/app/src/androidTest/java/org/tasks/injection/TestModule.java +++ b/app/src/androidTest/java/org/tasks/injection/TestModule.java @@ -4,7 +4,8 @@ import android.arch.persistence.room.Room; import android.content.Context; import com.todoroo.astrid.dao.Database; -import org.tasks.data.StoreObjectDao; + +import org.tasks.data.GoogleTaskListDao; import org.tasks.data.TagDataDao; import org.tasks.data.TaskListMetadataDao; import org.tasks.data.UserActivityDao; @@ -57,8 +58,8 @@ public class TestModule { } @Provides - public StoreObjectDao getStoreObjectDao(Database database) { - return database.getStoreObjectDao(); + public GoogleTaskListDao getGoogleTaskListDao(Database database) { + return database.getGoogleTaskListDao(); } @Provides diff --git a/app/src/androidTest/java/org/tasks/makers/GtaskListMaker.java b/app/src/androidTest/java/org/tasks/makers/GtaskListMaker.java index 675c3f443..af3de448e 100644 --- a/app/src/androidTest/java/org/tasks/makers/GtaskListMaker.java +++ b/app/src/androidTest/java/org/tasks/makers/GtaskListMaker.java @@ -3,34 +3,30 @@ package org.tasks.makers; import com.natpryce.makeiteasy.Instantiator; import com.natpryce.makeiteasy.Property; import com.natpryce.makeiteasy.PropertyValue; -import org.tasks.data.StoreObject; -import com.todoroo.astrid.gtasks.GtasksList; + +import org.tasks.data.GoogleTaskList; import static com.natpryce.makeiteasy.Property.newProperty; import static org.tasks.makers.Maker.make; public class GtaskListMaker { - public static final Property ID = newProperty(); - public static final Property ORDER = newProperty(); - public static final Property REMOTE_ID = newProperty(); - public static final Property LAST_SYNC = newProperty(); - public static final Property NAME = newProperty(); + public static final Property ID = newProperty(); + public static final Property ORDER = newProperty(); + public static final Property REMOTE_ID = newProperty(); + public static final Property LAST_SYNC = newProperty(); + public static final Property NAME = newProperty(); - public static GtasksList newGtaskList(PropertyValue... properties) { + public static GoogleTaskList newGtaskList(PropertyValue... properties) { return make(instantiator, properties); } - private static final Instantiator instantiator = lookup -> { - StoreObject storeObject = new StoreObject() {{ - setType(GtasksList.TYPE); - setDeleted(0L); - setId(lookup.valueOf(GtaskListMaker.ID, 0L)); - setItem(lookup.valueOf(REMOTE_ID, "1")); - setValue(lookup.valueOf(NAME, "Default")); - setValue2(String.valueOf(lookup.valueOf(ORDER, 0))); - setValue3(String.valueOf(lookup.valueOf(LAST_SYNC, 0L))); - }}; - return new GtasksList(storeObject); - }; + private static final Instantiator instantiator = lookup -> new GoogleTaskList() {{ + setDeleted(0L); + setId(lookup.valueOf(GtaskListMaker.ID, 0L)); + setRemoteId(lookup.valueOf(REMOTE_ID, "1")); + setTitle(lookup.valueOf(NAME, "Default")); + setRemoteOrder(lookup.valueOf(ORDER, 0)); + setLastSync(lookup.valueOf(LAST_SYNC, 0L)); + }}; } diff --git a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java index 3daa23484..7a01a708a 100644 --- a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java +++ b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksIndentActionTest.java @@ -15,6 +15,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.InjectingTestCase; import org.tasks.injection.TestComponent; @@ -36,7 +37,7 @@ public class GtasksIndentActionTest extends InjectingTestCase { @Inject GoogleTaskDao googleTaskDao; private Task task; - private GtasksList storeList; + private GoogleTaskList storeList; @Test public void testIndentWithoutMetadata() { diff --git a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java index 4113021b0..749bbcb99 100644 --- a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java +++ b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksListServiceTest.java @@ -4,13 +4,14 @@ import android.support.test.runner.AndroidJUnit4; import com.google.api.client.util.DateTime; import com.google.api.services.tasks.model.TaskList; -import org.tasks.data.StoreObjectDao; import com.todoroo.astrid.service.TaskDeleter; import org.junit.Test; import org.junit.runner.RunWith; import org.tasks.LocalBroadcastManager; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; +import org.tasks.data.GoogleTaskListDao; import org.tasks.data.TaskListDataProvider; import org.tasks.injection.InjectingTestCase; import org.tasks.injection.TestComponent; @@ -39,13 +40,13 @@ public class GtasksListServiceTest extends InjectingTestCase { @Inject LocalBroadcastManager localBroadcastManager; @Inject GoogleTaskDao googleTaskDao; - @Inject StoreObjectDao storeObjectDao; + @Inject GoogleTaskListDao googleTaskListDao; private GtasksListService gtasksListService; @Override public void setUp() { super.setUp(); - gtasksListService = new GtasksListService(storeObjectDao, taskListDataProvider, taskDeleter, + gtasksListService = new GtasksListService(googleTaskListDao, taskListDataProvider, taskDeleter, localBroadcastManager, googleTaskDao); } @@ -65,13 +66,13 @@ public class GtasksListServiceTest extends InjectingTestCase { with(ID, 1L), with(REMOTE_ID, "1"), with(NAME, "Default")), - storeObjectDao.getGtasksList(1L)); + googleTaskListDao.getById(1L)); } @Test public void testGetListByRemoteId() { - GtasksList list = newGtaskList(with(REMOTE_ID, "1")); - storeObjectDao.persist(list); + GoogleTaskList list = newGtaskList(with(REMOTE_ID, "1")); + list.setId(googleTaskListDao.insertOrReplace(list)); assertEquals(list, gtasksListService.getList("1")); } @@ -83,19 +84,19 @@ public class GtasksListServiceTest extends InjectingTestCase { @Test public void testDeleteMissingList() { - storeObjectDao.persist(newGtaskList(with(ID, 1L), with(REMOTE_ID, "1"))); + googleTaskListDao.insertOrReplace(newGtaskList(with(ID, 1L), with(REMOTE_ID, "1"))); TaskList taskList = newRemoteList(with(RemoteGtaskListMaker.REMOTE_ID, "2")); setLists(taskList); - assertEquals(singletonList(newGtaskList(with(ID, 2L), with(REMOTE_ID, "2")).getStoreObject()), - storeObjectDao.getGtasksLists()); + assertEquals(singletonList(newGtaskList(with(ID, 2L), with(REMOTE_ID, "2"))), + googleTaskListDao.getActiveLists()); } @Test public void testUpdateListName() { - storeObjectDao.persist(newGtaskList( + googleTaskListDao.insertOrReplace(newGtaskList( with(ID, 1L), with(REMOTE_ID, "1"), with(NAME, "oldName"))); @@ -104,7 +105,7 @@ public class GtasksListServiceTest extends InjectingTestCase { with(RemoteGtaskListMaker.REMOTE_ID, "1"), with(RemoteGtaskListMaker.NAME, "newName"))); - assertEquals("newName", storeObjectDao.getGtasksList(1).getName()); + assertEquals("newName", googleTaskListDao.getById(1).getTitle()); } @Test diff --git a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java index fcc55c874..c9def46b3 100644 --- a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java +++ b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdaterTest.java @@ -16,6 +16,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.InjectingTestCase; import org.tasks.injection.TestComponent; @@ -157,7 +158,7 @@ public class GtasksTaskListUpdaterTest extends InjectingTestCase { } void createParentSiblingMaps() { - for(GtasksList list : gtasksListService.getLists()) { + for(GoogleTaskList list : gtasksListService.getLists()) { gtasksTaskListUpdater.updateParentSiblingMapsFor(list); } } diff --git a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java index 364ef1827..69b0154d0 100644 --- a/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java +++ b/app/src/androidTestGoogleplay/java/com/todoroo/astrid/gtasks/GtasksTaskMovingTest.java @@ -15,6 +15,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.InjectingTestCase; import org.tasks.injection.TestComponent; @@ -38,7 +39,7 @@ public class GtasksTaskMovingTest extends InjectingTestCase { @Inject GoogleTaskDao googleTaskDao; private Task A, B, C, D, E, F; - private GtasksList list; + private GoogleTaskList list; /* Starting State: * diff --git a/app/src/generic/java/org/tasks/tasklist/GtasksListFragment.java b/app/src/generic/java/org/tasks/tasklist/GtasksListFragment.java index 4a73b504c..4e34babf2 100644 --- a/app/src/generic/java/org/tasks/tasklist/GtasksListFragment.java +++ b/app/src/generic/java/org/tasks/tasklist/GtasksListFragment.java @@ -2,7 +2,6 @@ package org.tasks.tasklist; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.GtasksFilter; -import com.todoroo.astrid.gtasks.GtasksList; public class GtasksListFragment extends TaskListFragment { public static TaskListFragment newGtasksListFragment(GtasksFilter gtasksFilter, GtasksList list) { diff --git a/app/src/generic/java/org/tasks/ui/GoogleTaskListFragment.java b/app/src/generic/java/org/tasks/ui/GoogleTaskListFragment.java index 541d81845..1fef660cd 100644 --- a/app/src/generic/java/org/tasks/ui/GoogleTaskListFragment.java +++ b/app/src/generic/java/org/tasks/ui/GoogleTaskListFragment.java @@ -1,7 +1,6 @@ package org.tasks.ui; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import org.tasks.R; import org.tasks.injection.FragmentComponent; diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java index e6b73a28f..17c332f04 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java @@ -8,6 +8,7 @@ package com.todoroo.astrid.gtasks; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.GtasksFilter; +import org.tasks.data.GoogleTaskList; import org.tasks.gtasks.SyncAdapterHelper; import java.util.List; @@ -41,7 +42,7 @@ public class GtasksFilterExposer { } List listFilters = newArrayList(); - for (GtasksList list : gtasksListService.getLists()) { + for (GoogleTaskList list : gtasksListService.getLists()) { listFilters.add(filterFromList(list)); } return listFilters; @@ -49,7 +50,7 @@ public class GtasksFilterExposer { public Filter getFilter(long id) { if (syncAdapterHelper.isEnabled()) { - GtasksList list = gtasksListService.getList(id); + GoogleTaskList list = gtasksListService.getList(id); if (list != null) { return filterFromList(list); } @@ -57,7 +58,7 @@ public class GtasksFilterExposer { return null; } - private Filter filterFromList(GtasksList list) { + private Filter filterFromList(GoogleTaskList list) { return new GtasksFilter(list); } } diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java index a80fccb6f..5a2bbf7f4 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java @@ -7,12 +7,13 @@ package com.todoroo.astrid.gtasks; import com.google.api.services.tasks.model.TaskList; import com.todoroo.astrid.api.GtasksFilter; -import org.tasks.data.StoreObjectDao; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.TaskDeleter; import org.tasks.LocalBroadcastManager; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; +import org.tasks.data.GoogleTaskListDao; import org.tasks.data.TaskListDataProvider; import java.util.HashSet; @@ -24,34 +25,33 @@ import javax.inject.Inject; import timber.log.Timber; import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Lists.transform; import static org.tasks.time.DateTimeUtils.printTimestamp; public class GtasksListService { - private final StoreObjectDao storeObjectDao; + private final GoogleTaskListDao googleTaskListDao; private final TaskListDataProvider taskListDataProvider; private final TaskDeleter taskDeleter; - private LocalBroadcastManager localBroadcastManager; + private final LocalBroadcastManager localBroadcastManager; private final GoogleTaskDao googleTaskDao; @Inject - public GtasksListService(StoreObjectDao storeObjectDao, TaskListDataProvider taskListDataProvider, + public GtasksListService(GoogleTaskListDao googleTaskListDao, TaskListDataProvider taskListDataProvider, TaskDeleter taskDeleter, LocalBroadcastManager localBroadcastManager, GoogleTaskDao googleTaskDao) { - this.storeObjectDao = storeObjectDao; + this.googleTaskListDao = googleTaskListDao; this.taskListDataProvider = taskListDataProvider; this.taskDeleter = taskDeleter; this.localBroadcastManager = localBroadcastManager; this.googleTaskDao = googleTaskDao; } - public List getLists() { - return transform(storeObjectDao.getGtasksLists(), GtasksList::new); + public List getLists() { + return googleTaskListDao.getActiveLists(); } - public GtasksList getList(long id) { - return storeObjectDao.getGtasksList(id); + public GoogleTaskList getList(long id) { + return googleTaskListDao.getById(id); } /** @@ -60,10 +60,10 @@ public class GtasksListService { * @param remoteLists remote information about your lists */ public synchronized void updateLists(List remoteLists) { - List lists = getLists(); + List lists = getLists(); Set previousLists = new HashSet<>(); - for(GtasksList list : lists) { + for(GoogleTaskList list : lists) { previousLists.add(list.getId()); } @@ -71,8 +71,8 @@ public class GtasksListService { com.google.api.services.tasks.model.TaskList remote = remoteLists.get(i); String id = remote.getId(); - GtasksList local = null; - for(GtasksList list : lists) { + GoogleTaskList local = null; + for(GoogleTaskList list : lists) { if(list.getRemoteId().equals(id)) { local = list; break; @@ -82,24 +82,25 @@ public class GtasksListService { String title = remote.getTitle(); if(local == null) { Timber.d("Adding new gtask list %s", title); - local = new GtasksList(id); + local = new GoogleTaskList(); + local.setRemoteId(id); } - local.setName(title); - local.setOrder(i); - storeObjectDao.persist(local); + local.setTitle(title); + local.setRemoteOrder(i); + googleTaskListDao.insertOrReplace(local); previousLists.remove(local.getId()); } // check for lists that aren't on remote server for(Long listId : previousLists) { - deleteList(storeObjectDao.getGtasksList(listId)); + deleteList(googleTaskListDao.getById(listId)); } localBroadcastManager.broadcastRefreshList(); } - public void deleteList(GtasksList gtasksList) { + public void deleteList(GoogleTaskList gtasksList) { List tasks = taskListDataProvider .constructCursor(new GtasksFilter(gtasksList), Task.PROPERTIES) .toList(); @@ -107,14 +108,14 @@ public class GtasksListService { taskDeleter.delete(task); } googleTaskDao.deleteList(gtasksList.getRemoteId()); - storeObjectDao.delete(gtasksList.getId()); + googleTaskListDao.deleteById(gtasksList.getId()); } - public List getListsToUpdate(List remoteLists) { - List listsToUpdate = newArrayList(); + public List getListsToUpdate(List remoteLists) { + List listsToUpdate = newArrayList(); for (TaskList remoteList : remoteLists) { - GtasksList localList = getList(remoteList.getId()); - String listName = localList.getName(); + GoogleTaskList localList = getList(remoteList.getId()); + String listName = localList.getTitle(); Long lastSync = localList.getLastSync(); long lastUpdate = remoteList.getUpdated().getValue(); if (lastSync < lastUpdate) { @@ -127,8 +128,8 @@ public class GtasksListService { return listsToUpdate; } - public GtasksList getList(String listId) { - for(GtasksList list : getLists()) { + public GoogleTaskList getList(String listId) { + for(GoogleTaskList list : getLists()) { if (list != null && list.getRemoteId().equals(listId)) { return list; } diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java index a34c493fb..a7ccc7775 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java @@ -18,6 +18,7 @@ import org.tasks.R; import org.tasks.analytics.Tracker; import org.tasks.analytics.Tracking; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.dialogs.DialogBuilder; import org.tasks.gtasks.GoogleTaskListSelectionHandler; import org.tasks.gtasks.PlayServicesAvailability; @@ -99,13 +100,13 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go .show(getFragmentManager(), FRAG_TAG_GOOGLE_TASK_LIST_SELECTION); return false; }); - GtasksList defaultList = getDefaultList(); + GoogleTaskList defaultList = getDefaultList(); if (defaultList != null) { - defaultListPreference.setSummary(defaultList.getName()); + defaultListPreference.setSummary(defaultList.getTitle()); } } - private GtasksList getDefaultList() { + private GoogleTaskList getDefaultList() { return gtasksListService.getList(gtasksPreferenceService.getDefaultList()); } @@ -157,11 +158,10 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go } @Override - public void selectedList(GtasksList list) { + public void selectedList(GoogleTaskList list) { tracker.reportEvent(Tracking.Events.GTASK_DEFAULT_LIST); String listId = list.getRemoteId(); gtasksPreferenceService.setDefaultList(listId); - findPreference(R.string.p_gtasks_default_list).setSummary(list.getName()); + findPreference(R.string.p_gtasks_default_list).setSummary(list.getTitle()); } - } diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksSubtaskListFragment.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksSubtaskListFragment.java index 6a3492724..741e6d787 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksSubtaskListFragment.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksSubtaskListFragment.java @@ -17,6 +17,7 @@ import com.todoroo.astrid.api.GtasksFilter; import com.todoroo.astrid.data.Task; import org.tasks.data.GoogleTask; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.ForApplication; import org.tasks.injection.FragmentComponent; import org.tasks.tasklist.GtasksListFragment; @@ -29,7 +30,7 @@ import javax.inject.Inject; public class GtasksSubtaskListFragment extends GtasksListFragment { - public static TaskListFragment newGtasksSubtaskListFragment(GtasksFilter filter, GtasksList list) { + public static TaskListFragment newGtasksSubtaskListFragment(GtasksFilter filter, GoogleTaskList list) { GtasksSubtaskListFragment fragment = new GtasksSubtaskListFragment(); fragment.filter = filter; fragment.list = list; diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java index 25b0a007d..f05b7ee38 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java @@ -12,6 +12,7 @@ import com.todoroo.astrid.gtasks.sync.GtasksSyncService; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.ApplicationScope; import java.util.ArrayList; @@ -56,7 +57,7 @@ public class GtasksTaskListUpdater { return googleTaskDao.getByTaskId(taskId); } - private void iterateThroughList(GtasksList list, OrderedListIterator iterator) { + private void iterateThroughList(GoogleTaskList list, OrderedListIterator iterator) { String listId = list.getRemoteId(); gtasksSyncService.iterateThroughList(listId, iterator, 0, false); } @@ -85,7 +86,7 @@ public class GtasksTaskListUpdater { } } - void updateParentSiblingMapsFor(GtasksList list) { + void updateParentSiblingMapsFor(GoogleTaskList list) { final AtomicLong previousTask = new AtomicLong(Task.NO_ID); final AtomicInteger previousIndent = new AtomicInteger(-1); @@ -130,7 +131,7 @@ public class GtasksTaskListUpdater { /** * Indent a task and all its children */ - public void indent(final GtasksList list, final long targetTaskId, final int delta) { + public void indent(final GoogleTaskList list, final long targetTaskId, final int delta) { if(list == null) { return; } @@ -184,7 +185,7 @@ public class GtasksTaskListUpdater { * Helper function to iterate through a list and compute a new parent for the target task * based on the target parent's indent */ - private long computeNewParent(GtasksList list, long targetTaskId, int targetParentIndent) { + private long computeNewParent(GoogleTaskList list, long targetTaskId, int targetParentIndent) { final AtomicInteger desiredParentIndent = new AtomicInteger(targetParentIndent); final AtomicLong targetTask = new AtomicLong(targetTaskId); final AtomicLong lastPotentialParent = new AtomicLong(Task.NO_ID); @@ -213,7 +214,7 @@ public class GtasksTaskListUpdater { * Move a task and all its children to the position right above * taskIdToMoveto. Will change the indent level to match taskIdToMoveTo. */ - void moveTo(GtasksList list, final long targetTaskId, + void moveTo(GoogleTaskList list, final long targetTaskId, final long moveBeforeTaskId) { if(list == null) { return; @@ -269,7 +270,7 @@ public class GtasksTaskListUpdater { } } - private void traverseTreeAndWriteValues(GtasksList list, Node node, AtomicLong order, int indent) { + private void traverseTreeAndWriteValues(GoogleTaskList list, Node node, AtomicLong order, int indent) { if(node.taskId != Task.NO_ID) { GoogleTask googleTask = getTaskMetadata(node.taskId); if(googleTask == null) { @@ -306,7 +307,7 @@ public class GtasksTaskListUpdater { return null; } - private Node buildTreeModel(GtasksList list) { + private Node buildTreeModel(GoogleTaskList list) { final Node root = new Node(Task.NO_ID, null); final AtomicInteger previoustIndent = new AtomicInteger(-1); final AtomicReference currentNode = new AtomicReference<>(root); @@ -354,7 +355,7 @@ public class GtasksTaskListUpdater { /** * Apply an operation only to the children of the task */ - void applyToChildren(GtasksList list, long targetTaskId, + void applyToChildren(GoogleTaskList list, long targetTaskId, OrderedListNodeVisitor visitor) { Node root = buildTreeModel(list); @@ -377,7 +378,7 @@ public class GtasksTaskListUpdater { /** * Removes a task from the order hierarchy and un-indent children */ - void onDeleteTask(GtasksList list, final long targetTaskId) { + void onDeleteTask(GoogleTaskList list, final long targetTaskId) { if(list == null) { return; } diff --git a/app/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java b/app/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java index 22e1b5c87..c7ee385f9 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java +++ b/app/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java @@ -19,6 +19,7 @@ import com.todoroo.astrid.data.Task; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import java.util.ArrayList; import java.util.Collections; @@ -38,7 +39,7 @@ class OrderedMetadataListFragmentHelper { private DraggableTaskAdapter taskAdapter; private TaskListFragment fragment; - private GtasksList list; + private GoogleTaskList list; @Inject OrderedMetadataListFragmentHelper(TaskDao taskDao, GtasksTaskListUpdater updater, GoogleTaskDao googleTaskDao) { @@ -168,7 +169,7 @@ class OrderedMetadataListFragmentHelper { } } - public void setList(GtasksList list) { + public void setList(GoogleTaskList list) { this.list = list; } diff --git a/app/src/googleplay/java/com/todoroo/astrid/service/SyncV2Service.java b/app/src/googleplay/java/com/todoroo/astrid/service/SyncV2Service.java index 75ddb67bb..a5ff31cf1 100644 --- a/app/src/googleplay/java/com/todoroo/astrid/service/SyncV2Service.java +++ b/app/src/googleplay/java/com/todoroo/astrid/service/SyncV2Service.java @@ -5,10 +5,10 @@ */ package com.todoroo.astrid.service; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.sync.GtasksSyncService; import com.todoroo.astrid.sync.SyncResultCallback; +import org.tasks.data.GoogleTaskList; import org.tasks.gtasks.SyncAdapterHelper; import org.tasks.sync.SyncExecutor; @@ -38,7 +38,7 @@ public class SyncV2Service { this.gtasksSyncService = gtasksSyncService; } - public void clearCompleted(final GtasksList list, final SyncResultCallback callback) { + public void clearCompleted(final GoogleTaskList list, final SyncResultCallback callback) { if (syncAdapterHelper.isEnabled()) { syncExecutor.execute(callback, () -> { callback.started(); diff --git a/app/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java b/app/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java index 58526ea62..0a7196bbc 100644 --- a/app/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java +++ b/app/src/googleplay/java/org/tasks/activities/GoogleTaskListSettingsActivity.java @@ -14,9 +14,10 @@ import android.widget.Toast; import com.google.api.services.tasks.model.TaskList; import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.api.GtasksFilter; -import org.tasks.data.StoreObjectDao; -import org.tasks.data.StoreObject; -import com.todoroo.astrid.gtasks.GtasksList; + +import org.tasks.data.GoogleTaskList; +import org.tasks.data.GoogleTaskListDao; + import com.todoroo.astrid.gtasks.GtasksListService; import org.tasks.R; @@ -61,10 +62,10 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi public static final String ACTION_RELOAD = "action_reload"; private boolean isNewList; - private GtasksList gtasksList; + private GoogleTaskList gtasksList; private int selectedTheme; - @Inject StoreObjectDao storeObjectDao; + @Inject GoogleTaskListDao googleTaskListDao; @Inject DialogBuilder dialogBuilder; @Inject Preferences preferences; @Inject GtasksListService gtasksListService; @@ -83,21 +84,21 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi setContentView(R.layout.activity_google_task_list_settings); ButterKnife.bind(this); - StoreObject storeObject = getIntent().getParcelableExtra(EXTRA_STORE_DATA); - if (storeObject == null) { + gtasksList = getIntent().getParcelableExtra(EXTRA_STORE_DATA); + if (gtasksList == null) { isNewList = true; - storeObject = new StoreObject(); - storeObject.setType(GtasksList.TYPE); + gtasksList = new GoogleTaskList(); } - gtasksList = new GtasksList(storeObject); + if (savedInstanceState == null) { - selectedTheme = gtasksList.getColor(); + Integer color = gtasksList.getColor(); + selectedTheme = color == null ? -1 : color; } else { selectedTheme = savedInstanceState.getInt(EXTRA_SELECTED_THEME); } final boolean backButtonSavesTask = preferences.backButtonSavesTask(); - toolbar.setTitle(isNewList ? getString(R.string.new_list) : gtasksList.getName()); + toolbar.setTitle(isNewList ? getString(R.string.new_list) : gtasksList.getTitle()); toolbar.setNavigationIcon(ContextCompat.getDrawable(this, backButtonSavesTask ? R.drawable.ic_close_24dp : R.drawable.ic_save_24dp)); toolbar.setNavigationOnClickListener(v -> { @@ -121,7 +122,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(name, InputMethodManager.SHOW_IMPLICIT); } else { - name.setText(gtasksList.getName()); + name.setText(gtasksList.getTitle()); } updateTheme(); @@ -173,7 +174,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi } else { if (colorChanged()) { gtasksList.setColor(selectedTheme); - storeObjectDao.persist(gtasksList); + googleTaskListDao.insertOrReplace(gtasksList); setResult(RESULT_OK, new Intent(ACTION_RELOAD).putExtra(TaskListActivity.OPEN_FILTER, new GtasksFilter(gtasksList))); } finish(); @@ -197,7 +198,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi } private void deleteTag() { - dialogBuilder.newMessageDialog(R.string.delete_tag_confirmation, gtasksList.getName()) + dialogBuilder.newMessageDialog(R.string.delete_tag_confirmation, gtasksList.getTitle()) .setPositiveButton(R.string.delete, (dialog, which) -> newDeleteListDialog(gtasksList.getRemoteId()) .show(getSupportFragmentManager(), FRAG_TAG_DELETE_LIST_DIALOG)) .setNegativeButton(android.R.string.cancel, null) @@ -241,16 +242,17 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi } private boolean nameChanged() { - return !getNewName().equals(gtasksList.getName()); + return !getNewName().equals(gtasksList.getTitle()); } @Override public void onListCreated(TaskList taskList) { tracker.reportEvent(Tracking.Events.GTASK_NEW_LIST); - gtasksList = new GtasksList(taskList.getId()); - gtasksList.setName(taskList.getTitle()); + gtasksList = new GoogleTaskList(); + gtasksList.setRemoteId(taskList.getId()); + gtasksList.setTitle(taskList.getTitle()); gtasksList.setColor(selectedTheme); - storeObjectDao.persist(gtasksList); + gtasksList.setId(googleTaskListDao.insertOrReplace(gtasksList)); setResult(RESULT_OK, new Intent().putExtra(TaskListActivity.OPEN_FILTER, new GtasksFilter(gtasksList))); finish(); } @@ -266,9 +268,9 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi @Override public void onListRenamed(TaskList taskList) { tracker.reportEvent(Tracking.Events.GTASK_RENAME_LIST); - gtasksList.setName(taskList.getTitle()); + gtasksList.setTitle(taskList.getTitle()); gtasksList.setColor(selectedTheme); - storeObjectDao.persist(gtasksList); + googleTaskListDao.insertOrReplace(gtasksList); setResult(RESULT_OK, new Intent(ACTION_RELOAD).putExtra(TaskListActivity.OPEN_FILTER, new GtasksFilter(gtasksList))); finish(); } diff --git a/app/src/googleplay/java/org/tasks/activities/NativeGoogleTaskListPicker.java b/app/src/googleplay/java/org/tasks/activities/NativeGoogleTaskListPicker.java index 6a0679e06..9e8b9fc61 100644 --- a/app/src/googleplay/java/org/tasks/activities/NativeGoogleTaskListPicker.java +++ b/app/src/googleplay/java/org/tasks/activities/NativeGoogleTaskListPicker.java @@ -4,10 +4,9 @@ import android.app.Activity; import android.app.Dialog; import android.os.Bundle; -import org.tasks.data.StoreObject; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; +import org.tasks.data.GoogleTaskList; import org.tasks.dialogs.DialogBuilder; import org.tasks.gtasks.GoogleTaskListSelectionHandler; import org.tasks.injection.InjectingNativeDialogFragment; @@ -21,11 +20,11 @@ import static org.tasks.activities.SupportGoogleTaskListPicker.createDialog; public class NativeGoogleTaskListPicker extends InjectingNativeDialogFragment { - public static NativeGoogleTaskListPicker newNativeGoogleTaskListPicker(GtasksList defaultList) { + public static NativeGoogleTaskListPicker newNativeGoogleTaskListPicker(GoogleTaskList defaultList) { NativeGoogleTaskListPicker dialog = new NativeGoogleTaskListPicker(); Bundle arguments = new Bundle(); if (defaultList != null) { - arguments.putParcelable(EXTRA_SELECTED, defaultList.getStoreObject()); + arguments.putParcelable(EXTRA_SELECTED, defaultList); } dialog.setArguments(arguments); return dialog; @@ -43,11 +42,7 @@ public class NativeGoogleTaskListPicker extends InjectingNativeDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle arguments = getArguments(); - StoreObject storeObject = arguments.getParcelable(EXTRA_SELECTED); - GtasksList selected = null; - if (storeObject != null) { - selected = new GtasksList(storeObject); - } + GoogleTaskList selected = arguments.getParcelable(EXTRA_SELECTED); return createDialog(getActivity(), themeCache, dialogBuilder, gtasksListService, selected, themeAccent, list -> handler.selectedList(list)); } diff --git a/app/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java b/app/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java index 63a609423..d3e01f051 100644 --- a/app/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java +++ b/app/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java @@ -7,11 +7,10 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; -import org.tasks.data.StoreObject; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; import org.tasks.R; +import org.tasks.data.GoogleTaskList; import org.tasks.dialogs.DialogBuilder; import org.tasks.gtasks.GoogleTaskListSelectionHandler; import org.tasks.injection.DialogFragmentComponent; @@ -28,11 +27,11 @@ import static com.google.common.collect.Lists.transform; public class SupportGoogleTaskListPicker extends InjectingDialogFragment { - public static SupportGoogleTaskListPicker newSupportGoogleTaskListPicker(GtasksList selected) { + public static SupportGoogleTaskListPicker newSupportGoogleTaskListPicker(GoogleTaskList selected) { SupportGoogleTaskListPicker dialog = new SupportGoogleTaskListPicker(); Bundle arguments = new Bundle(); if (selected != null) { - arguments.putParcelable(EXTRA_SELECTED, selected.getStoreObject()); + arguments.putParcelable(EXTRA_SELECTED, selected); } dialog.setArguments(arguments); return dialog; @@ -51,11 +50,7 @@ public class SupportGoogleTaskListPicker extends InjectingDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle arguments = getArguments(); - StoreObject storeObject = arguments.getParcelable(EXTRA_SELECTED); - GtasksList selected = null; - if (storeObject != null) { - selected = new GtasksList(storeObject); - } + GoogleTaskList selected = arguments == null ? null : arguments.getParcelable(EXTRA_SELECTED); return createDialog(getActivity(), themeCache, dialogBuilder, gtasksListService, selected, themeAccent, list -> handler.selectedList(list)); } @@ -69,10 +64,10 @@ public class SupportGoogleTaskListPicker extends InjectingDialogFragment { public static AlertDialog createDialog(Context context, ThemeCache themeCache, DialogBuilder dialogBuilder, GtasksListService gtasksListService, - GtasksList selected, ThemeAccent themeAccent, + GoogleTaskList selected, ThemeAccent themeAccent, final GoogleTaskListSelectionHandler handler) { - final List lists = gtasksListService.getLists(); - List listNames = transform(lists, GtasksList::getName); + final List lists = gtasksListService.getLists(); + List listNames = transform(lists, GoogleTaskList::getTitle); SingleCheckedArrayAdapter adapter = new SingleCheckedArrayAdapter(context, listNames, themeAccent) { @Override protected int getDrawable(int position) { @@ -81,7 +76,7 @@ public class SupportGoogleTaskListPicker extends InjectingDialogFragment { @Override protected int getDrawableColor(int position) { - GtasksList list = lists.get(position); + GoogleTaskList list = lists.get(position); int color = list.getColor(); return color >= 0 ? themeCache.getThemeColor(color).getPrimaryColor() @@ -89,7 +84,7 @@ public class SupportGoogleTaskListPicker extends InjectingDialogFragment { } }; if (selected != null) { - adapter.setChecked(selected.getName()); + adapter.setChecked(selected.getTitle()); } return dialogBuilder.newDialog() .setSingleChoiceItems(adapter, -1, (dialog, which) -> { diff --git a/app/src/googleplay/java/org/tasks/gtasks/GoogleTaskSyncAdapter.java b/app/src/googleplay/java/org/tasks/gtasks/GoogleTaskSyncAdapter.java index 9562aaff1..c2b5685bb 100644 --- a/app/src/googleplay/java/org/tasks/gtasks/GoogleTaskSyncAdapter.java +++ b/app/src/googleplay/java/org/tasks/gtasks/GoogleTaskSyncAdapter.java @@ -38,11 +38,9 @@ import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; -import org.tasks.data.StoreObjectDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksTaskListUpdater; @@ -58,6 +56,8 @@ import org.tasks.R; import org.tasks.analytics.Tracker; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; +import org.tasks.data.GoogleTaskListDao; import org.tasks.injection.InjectingAbstractThreadedSyncAdapter; import org.tasks.injection.SyncAdapterComponent; import org.tasks.notifications.NotificationManager; @@ -90,7 +90,7 @@ public class GoogleTaskSyncAdapter extends InjectingAbstractThreadedSyncAdapter @Inject GtasksPreferenceService gtasksPreferenceService; @Inject LocalBroadcastManager localBroadcastManager; - @Inject StoreObjectDao storeObjectDao; + @Inject GoogleTaskListDao googleTaskListDao; @Inject GtasksSyncService gtasksSyncService; @Inject GtasksListService gtasksListService; @Inject GtasksTaskListUpdater gtasksTaskListUpdater; @@ -181,7 +181,7 @@ public class GoogleTaskSyncAdapter extends InjectingAbstractThreadedSyncAdapter if (gtasksListService.getList(gtasksPreferenceService.getDefaultList()) == null) { gtasksPreferenceService.setDefaultList(null); } - for (final GtasksList list : gtasksListService.getListsToUpdate(gtaskLists)) { + for (final GoogleTaskList list : gtasksListService.getListsToUpdate(gtaskLists)) { fetchAndApplyRemoteChanges(list); } } @@ -305,7 +305,7 @@ public class GoogleTaskSyncAdapter extends InjectingAbstractThreadedSyncAdapter taskDao.saveExistingWithSqlConstraintCheck(task); } - private synchronized void fetchAndApplyRemoteChanges(GtasksList list) throws UserRecoverableAuthIOException { + private synchronized void fetchAndApplyRemoteChanges(GoogleTaskList list) throws UserRecoverableAuthIOException { String listId = list.getRemoteId(); long lastSyncDate = list.getLastSync(); @@ -337,7 +337,7 @@ public class GoogleTaskSyncAdapter extends InjectingAbstractThreadedSyncAdapter lastSyncDate = Math.max(lastSyncDate, container.getUpdateTime()); } list.setLastSync(lastSyncDate); - storeObjectDao.persist(list); + googleTaskListDao.insertOrReplace(list); gtasksTaskListUpdater.correctOrderAndIndentForList(listId); } } catch (UserRecoverableAuthIOException e) { diff --git a/app/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java b/app/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java index 550c068f3..a5908ff74 100644 --- a/app/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java +++ b/app/src/googleplay/java/org/tasks/tasklist/GtasksListFragment.java @@ -9,14 +9,13 @@ import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.GtasksFilter; -import org.tasks.data.StoreObject; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.service.SyncV2Service; import com.todoroo.astrid.sync.SyncResultCallback; import org.tasks.R; import org.tasks.activities.GoogleTaskListSettingsActivity; import org.tasks.analytics.Tracking; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.FragmentComponent; import javax.inject.Inject; @@ -25,7 +24,7 @@ import static android.app.Activity.RESULT_OK; public class GtasksListFragment extends TaskListFragment { - public static TaskListFragment newGtasksListFragment(GtasksFilter filter, GtasksList list) { + public static TaskListFragment newGtasksListFragment(GtasksFilter filter, GoogleTaskList list) { GtasksListFragment fragment = new GtasksListFragment(); fragment.filter = filter; fragment.list = list; @@ -37,15 +36,14 @@ public class GtasksListFragment extends TaskListFragment { @Inject SyncV2Service syncService; - protected GtasksList list; + protected GoogleTaskList list; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { - StoreObject storeObject = savedInstanceState.getParcelable(EXTRA_STORE_OBJECT); - list = new GtasksList(storeObject); + list = savedInstanceState.getParcelable(EXTRA_STORE_OBJECT); } } @@ -60,7 +58,7 @@ public class GtasksListFragment extends TaskListFragment { switch(item.getItemId()) { case R.id.menu_gtasks_list_settings: Intent intent = new Intent(getActivity(), GoogleTaskListSettingsActivity.class); - intent.putExtra(GoogleTaskListSettingsActivity.EXTRA_STORE_DATA, list.getStoreObject()); + intent.putExtra(GoogleTaskListSettingsActivity.EXTRA_STORE_DATA, list); startActivityForResult(intent, REQUEST_LIST_SETTINGS); return true; default: @@ -108,7 +106,7 @@ public class GtasksListFragment extends TaskListFragment { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putParcelable(EXTRA_STORE_OBJECT, list.getStoreObject()); + outState.putParcelable(EXTRA_STORE_OBJECT, list); } @Override diff --git a/app/src/googleplay/java/org/tasks/ui/GoogleTaskListFragment.java b/app/src/googleplay/java/org/tasks/ui/GoogleTaskListFragment.java index e0b420244..0e89bce0d 100644 --- a/app/src/googleplay/java/org/tasks/ui/GoogleTaskListFragment.java +++ b/app/src/googleplay/java/org/tasks/ui/GoogleTaskListFragment.java @@ -7,10 +7,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import org.tasks.data.StoreObject; import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; import com.todoroo.astrid.gtasks.GtasksPreferenceService; @@ -19,6 +17,7 @@ import org.tasks.analytics.Tracker; import org.tasks.analytics.Tracking; import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTaskDao; +import org.tasks.data.GoogleTaskList; import org.tasks.injection.FragmentComponent; import javax.inject.Inject; @@ -46,8 +45,8 @@ public class GoogleTaskListFragment extends TaskEditControlFragment { @Inject Tracker tracker; private long taskId; - @Nullable private GtasksList originalList; - @Nullable private GtasksList selectedList; + @Nullable private GoogleTaskList originalList; + @Nullable private GoogleTaskList selectedList; @Nullable @Override @@ -56,14 +55,8 @@ public class GoogleTaskListFragment extends TaskEditControlFragment { if (savedInstanceState != null) { taskId = savedInstanceState.getLong(EXTRA_TASK_ID); - StoreObject originalStoreObject = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST); - if (originalStoreObject != null) { - originalList = new GtasksList(originalStoreObject); - } - StoreObject selectedStoreObject = savedInstanceState.getParcelable(EXTRA_SELECTED_LIST); - if (selectedStoreObject != null) { - selectedList = new GtasksList(selectedStoreObject); - } + originalList = savedInstanceState.getParcelable(EXTRA_ORIGINAL_LIST); + selectedList = savedInstanceState.getParcelable(EXTRA_SELECTED_LIST); } else { GoogleTask googleTask = googleTaskDao.getByTaskId(taskId); if (googleTask != null) { @@ -85,10 +78,10 @@ public class GoogleTaskListFragment extends TaskEditControlFragment { outState.putLong(EXTRA_TASK_ID, taskId); if (originalList != null) { - outState.putParcelable(EXTRA_ORIGINAL_LIST, originalList.getStoreObject()); + outState.putParcelable(EXTRA_ORIGINAL_LIST, originalList); } if (selectedList != null) { - outState.putParcelable(EXTRA_SELECTED_LIST, selectedList.getStoreObject()); + outState.putParcelable(EXTRA_SELECTED_LIST, selectedList); } } @@ -146,14 +139,14 @@ public class GoogleTaskListFragment extends TaskEditControlFragment { component.inject(this); } - public void setList(GtasksList list) { + public void setList(GoogleTaskList list) { this.selectedList = list; refreshView(); } private void refreshView() { if (selectedList != null) { - textView.setText(selectedList.getName()); + textView.setText(selectedList.getTitle()); } } } diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 202e05141..2a370f4e4 100755 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -22,11 +22,12 @@ import android.widget.LinearLayout; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.dao.TaskDao; + +import org.tasks.data.GoogleTaskList; import org.tasks.data.UserActivityDao; import com.todoroo.astrid.data.Task; import org.tasks.data.UserActivity; import com.todoroo.astrid.files.FilesControlSet; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.notes.CommentsController; import com.todoroo.astrid.repeats.RepeatControlSet; import com.todoroo.astrid.service.TaskDeleter; @@ -321,7 +322,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar getEditTitleControlSet().repeatChanged(repeat); } - public void onGoogleTaskListChanged(GtasksList list) { + public void onGoogleTaskListChanged(GoogleTaskList list) { getGoogleTaskListFragment().setList(list); } diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java b/app/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java index 272ed9df6..ef3a15911 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java @@ -23,11 +23,12 @@ import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.GtasksFilter; import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.TagFilter; + +import org.tasks.data.GoogleTaskList; import org.tasks.data.TagDataDao; import com.todoroo.astrid.dao.TaskDao; import org.tasks.data.TagData; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; import com.todoroo.astrid.gtasks.GtasksSubtaskListFragment; import com.todoroo.astrid.repeats.RepeatControlSet; @@ -317,7 +318,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements } } else if (filter instanceof GtasksFilter) { GtasksFilter gtasksFilter = (GtasksFilter) filter; - GtasksList list = gtasksListService.getList(gtasksFilter.getStoreId()); + GoogleTaskList list = gtasksListService.getList(gtasksFilter.getStoreId()); if (list != null) { return preferences.getBoolean(R.string.p_manual_sort, false) ? GtasksSubtaskListFragment.newGtasksSubtaskListFragment(gtasksFilter, list) @@ -503,7 +504,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements } @Override - public void selectedList(GtasksList list) { + public void selectedList(GoogleTaskList list) { getTaskEditFragment().onGoogleTaskListChanged(list); } diff --git a/app/src/main/java/com/todoroo/astrid/api/GtasksFilter.java b/app/src/main/java/com/todoroo/astrid/api/GtasksFilter.java index 135b957e8..6bf46595f 100644 --- a/app/src/main/java/com/todoroo/astrid/api/GtasksFilter.java +++ b/app/src/main/java/com/todoroo/astrid/api/GtasksFilter.java @@ -9,10 +9,10 @@ import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import org.tasks.R; import org.tasks.data.GoogleTask; +import org.tasks.data.GoogleTaskList; import java.util.HashMap; import java.util.Map; @@ -27,10 +27,12 @@ public class GtasksFilter extends Filter { super(); } - public GtasksFilter(GtasksList list) { - super(list.getName(), getQueryTemplate(list), getValuesForNewTasks(list)); + public GtasksFilter(GoogleTaskList list) { + super(list.getTitle(), getQueryTemplate(list), getValuesForNewTasks(list)); storeId = list.getId(); - tint = list.getColor(); + if (list.hasColor()) { + tint = list.getColor(); + } icon = CLOUD; } @@ -46,7 +48,7 @@ public class GtasksFilter extends Filter { return storeId; } - private static QueryTemplate getQueryTemplate(GtasksList list) { + private static QueryTemplate getQueryTemplate(GoogleTaskList list) { return new QueryTemplate() .join(Join.left(GoogleTask.TABLE, Task.ID.eq(Field.field("google_tasks.task")))) .where(Criterion.and( @@ -54,7 +56,7 @@ public class GtasksFilter extends Filter { Field.field("list_id").eq(list.getRemoteId()))); } - private static Map getValuesForNewTasks(GtasksList list) { + private static Map getValuesForNewTasks(GoogleTaskList list) { Map values = new HashMap<>(); values.put(GoogleTask.KEY, list.getRemoteId()); return values; diff --git a/app/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java b/app/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java index 18501c20f..0492e3a39 100644 --- a/app/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java +++ b/app/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java @@ -36,7 +36,6 @@ import com.todoroo.astrid.data.Task; import org.tasks.R; import org.tasks.data.FilterDao; -import org.tasks.data.StoreObjectDao; import org.tasks.dialogs.DialogBuilder; import org.tasks.filters.FilterCriteriaProvider; import org.tasks.injection.ActivityComponent; @@ -137,7 +136,6 @@ public class CustomFilterActivity extends ThemedInjectingAppCompatActivity imple @Inject Database database; @Inject FilterDao filterDao; - @Inject StoreObjectDao storeObjectDao; @Inject DialogBuilder dialogBuilder; @Inject FilterCriteriaProvider filterCriteriaProvider; @Inject Locale locale; diff --git a/app/src/main/java/com/todoroo/astrid/dao/Database.java b/app/src/main/java/com/todoroo/astrid/dao/Database.java index e8987dd15..8a5a25d3a 100644 --- a/app/src/main/java/com/todoroo/astrid/dao/Database.java +++ b/app/src/main/java/com/todoroo/astrid/dao/Database.java @@ -18,9 +18,9 @@ import com.todoroo.andlib.utility.AndroidUtilities; import org.tasks.data.Filter; import org.tasks.data.FilterDao; -import org.tasks.data.StoreObject; +import org.tasks.data.GoogleTaskList; +import org.tasks.data.GoogleTaskListDao; -import org.tasks.data.StoreObjectDao; import org.tasks.data.TagData; import com.todoroo.astrid.data.Task; import org.tasks.data.TaskAttachment; @@ -59,15 +59,15 @@ import timber.log.Timber; UserActivity.class, TaskAttachment.class, TaskListMetadata.class, - StoreObject.class, Task.class, Alarm.class, Location.class, Tag.class, GoogleTask.class, - Filter.class + Filter.class, + GoogleTaskList.class }, - version = 51) + version = 52) public abstract class Database extends RoomDatabase { public abstract NotificationDao notificationDao(); @@ -75,12 +75,12 @@ public abstract class Database extends RoomDatabase { public abstract UserActivityDao getUserActivityDao(); public abstract TaskAttachmentDao getTaskAttachmentDao(); public abstract TaskListMetadataDao getTaskListMetadataDao(); - public abstract StoreObjectDao getStoreObjectDao(); public abstract AlarmDao getAlarmDao(); public abstract LocationDao getLocationDao(); public abstract TagDao getTagDao(); public abstract GoogleTaskDao getGoogleTaskDao(); public abstract FilterDao getFilterDao(); + public abstract GoogleTaskListDao getGoogleTaskListDao(); public static final String NAME = "database"; diff --git a/app/src/main/java/com/todoroo/astrid/gtasks/GtasksList.java b/app/src/main/java/com/todoroo/astrid/gtasks/GtasksList.java deleted file mode 100644 index d05259c6b..000000000 --- a/app/src/main/java/com/todoroo/astrid/gtasks/GtasksList.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.gtasks; - -import com.google.common.base.Strings; -import org.tasks.data.StoreObject; - -/** - * {@link StoreObject} entries for a GTasks List - * - * @author Tim Su - */ -public class GtasksList { - - private StoreObject storeObject; - - public GtasksList(final String remoteId) { - this(newStoreObject()); - setLastSync(0L); - setRemoteId(remoteId); - } - - private static StoreObject newStoreObject() { - StoreObject storeObject = new StoreObject(); - storeObject.setType(GtasksList.TYPE); - return storeObject; - } - - public GtasksList(StoreObject storeObject) { - if (!storeObject.getType().equals(TYPE)) { - throw new RuntimeException("Type is not " + TYPE); - } - this.storeObject = storeObject; - } - - /** - * type - */ - public static final String TYPE = "gtasks-list"; //$NON-NLS-1$ - - public Long getId() { - return storeObject.getId(); - } - - public String getRemoteId() { - return storeObject.getItem(); - } - - private void setRemoteId(String remoteId) { - storeObject.setItem(remoteId); - } - - public String getName() { - return storeObject.getValue(); - } - - public void setName(String name) { - storeObject.setValue(name); - } - - public void setOrder(int order) { - storeObject.setValue2(Integer.toString(order)); - } - - public int getColor() { - String color = storeObject.getValue4(); - return Strings.isNullOrEmpty(color) ? -1 : Integer.parseInt(storeObject.getValue4()); - } - - public void setColor(int color) { - storeObject.setValue4(Integer.toString(color)); - } - - public long getLastSync() { - String lastSync = storeObject.getValue3(); - return Strings.isNullOrEmpty(lastSync) ? 0 : Long.parseLong(lastSync); - } - - public void setLastSync(long timestamp) { - storeObject.setValue3(Long.toString(timestamp)); - } - - public StoreObject getStoreObject() { - return storeObject; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof GtasksList)) return false; - - GtasksList that = (GtasksList) o; - - return storeObject != null ? storeObject.equals(that.storeObject) : that.storeObject == null; - } - - @Override - public int hashCode() { - return storeObject != null ? storeObject.hashCode() : 0; - } - - @Override - public String toString() { - return "GtasksList{" + - "storeObject=" + storeObject + - '}'; - } -} diff --git a/app/src/main/java/org/tasks/data/GoogleTaskList.java b/app/src/main/java/org/tasks/data/GoogleTaskList.java new file mode 100644 index 000000000..022885f64 --- /dev/null +++ b/app/src/main/java/org/tasks/data/GoogleTaskList.java @@ -0,0 +1,178 @@ +package org.tasks.data; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.Ignore; +import android.arch.persistence.room.PrimaryKey; +import android.os.Parcel; +import android.os.Parcelable; + +@Entity(tableName = "google_task_lists") +public class GoogleTaskList implements Parcelable { + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "_id") + private long id; + + @ColumnInfo(name = "remote_id") + private String remoteId; + + @ColumnInfo(name = "title") + private String title; + + @ColumnInfo(name = "remote_order") + private int remoteOrder; + + @ColumnInfo(name = "last_sync") + private long lastSync; + + @ColumnInfo(name = "deleted") + private long deleted; + + @ColumnInfo(name = "color") + private Integer color; + + public GoogleTaskList() { + + } + + @Ignore + public GoogleTaskList(Parcel parcel) { + id = parcel.readLong(); + remoteId = parcel.readString(); + title = parcel.readString(); + remoteOrder = parcel.readInt(); + lastSync = parcel.readLong(); + deleted = parcel.readLong(); + color = parcel.readInt(); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getRemoteId() { + return remoteId; + } + + public void setRemoteId(String remoteId) { + this.remoteId = remoteId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getRemoteOrder() { + return remoteOrder; + } + + public void setRemoteOrder(int remoteOrder) { + this.remoteOrder = remoteOrder; + } + + public long getLastSync() { + return lastSync; + } + + public void setLastSync(long lastSync) { + this.lastSync = lastSync; + } + + public long getDeleted() { + return deleted; + } + + public void setDeleted(long deleted) { + this.deleted = deleted; + } + + public boolean hasColor() { + return color != null; + } + + public Integer getColor() { + return color; + } + + public void setColor(Integer color) { + this.color = color; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof GoogleTaskList)) return false; + + GoogleTaskList that = (GoogleTaskList) o; + + if (id != that.id) return false; + if (remoteOrder != that.remoteOrder) return false; + if (lastSync != that.lastSync) return false; + if (deleted != that.deleted) return false; + if (remoteId != null ? !remoteId.equals(that.remoteId) : that.remoteId != null) + return false; + if (title != null ? !title.equals(that.title) : that.title != null) return false; + return color != null ? color.equals(that.color) : that.color == null; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (remoteId != null ? remoteId.hashCode() : 0); + result = 31 * result + (title != null ? title.hashCode() : 0); + result = 31 * result + remoteOrder; + result = 31 * result + (int) (lastSync ^ (lastSync >>> 32)); + result = 31 * result + (int) (deleted ^ (deleted >>> 32)); + result = 31 * result + (color != null ? color.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "GoogleTaskList{" + + "id=" + id + + ", remoteId='" + remoteId + '\'' + + ", title='" + title + '\'' + + ", remoteOrder=" + remoteOrder + + ", lastSync=" + lastSync + + ", deleted=" + deleted + + ", color=" + color + + '}'; + } + + public static Creator CREATOR = new Creator() { + @Override + public GoogleTaskList createFromParcel(Parcel parcel) { + return new GoogleTaskList(parcel); + } + + @Override + public GoogleTaskList[] newArray(int size) { + return new GoogleTaskList[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeLong(id); + parcel.writeString(remoteId); + parcel.writeString(title); + parcel.writeInt(remoteOrder); + parcel.writeLong(lastSync); + parcel.writeLong(deleted); + parcel.writeInt(color); + } +} diff --git a/app/src/main/java/org/tasks/data/GoogleTaskListDao.java b/app/src/main/java/org/tasks/data/GoogleTaskListDao.java new file mode 100644 index 000000000..b063233bf --- /dev/null +++ b/app/src/main/java/org/tasks/data/GoogleTaskListDao.java @@ -0,0 +1,24 @@ +package org.tasks.data; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +@Dao +public interface GoogleTaskListDao { + + @Query("SELECT * FROM google_task_lists WHERE _id = :id") + GoogleTaskList getById(long id); + + @Query("SELECT * FROM google_task_lists WHERE deleted = 0 ORDER BY title ASC") + List getActiveLists(); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + long insertOrReplace(GoogleTaskList googleTaskList); + + @Query("DELETE FROM google_task_lists WHERE _id = :id") + void deleteById(long id); +} diff --git a/app/src/main/java/org/tasks/data/StoreObject.java b/app/src/main/java/org/tasks/data/StoreObject.java deleted file mode 100644 index 712acc205..000000000 --- a/app/src/main/java/org/tasks/data/StoreObject.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.tasks.data; - - -import android.arch.persistence.room.ColumnInfo; -import android.arch.persistence.room.Entity; -import android.arch.persistence.room.Ignore; -import android.arch.persistence.room.Index; -import android.arch.persistence.room.PrimaryKey; -import android.os.Parcel; -import android.os.Parcelable; - -@Entity(tableName = "store", - indices = @Index(name = "so_id", value = {"type", "item"})) -public class StoreObject implements Parcelable{ - - @PrimaryKey(autoGenerate = true) - @ColumnInfo(name = "_id") - private Long id; - - @ColumnInfo(name = "type") - private String type; - - @ColumnInfo(name = "item") - private String item; - - @ColumnInfo(name = "value") - private String value; - - @ColumnInfo(name = "value2") - private String value2; - - @ColumnInfo(name = "value3") - private String value3; - - @ColumnInfo(name = "value4") - private String value4; - - @ColumnInfo(name = "deleted") - private Long deleted = 0L; - - public StoreObject() { - - } - - @Ignore - public StoreObject(Parcel source) { - id = source.readLong(); - type = source.readString(); - item = source.readString(); - value = source.readString(); - value2 = source.readString(); - value3 = source.readString(); - value4 = source.readString(); - deleted = source.readLong(); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getItem() { - return item; - } - - public void setItem(String item) { - this.item = item; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String getValue2() { - return value2; - } - - public void setValue2(String value2) { - this.value2 = value2; - } - - public String getValue3() { - return value3; - } - - public void setValue3(String value3) { - this.value3 = value3; - } - - public String getValue4() { - return value4; - } - - public void setValue4(String value4) { - this.value4 = value4; - } - - public Long getDeleted() { - return deleted; - } - - public void setDeleted(Long deleted) { - this.deleted = deleted; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof StoreObject)) return false; - - StoreObject that = (StoreObject) o; - - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (type != null ? !type.equals(that.type) : that.type != null) return false; - if (item != null ? !item.equals(that.item) : that.item != null) return false; - if (value != null ? !value.equals(that.value) : that.value != null) return false; - if (value2 != null ? !value2.equals(that.value2) : that.value2 != null) return false; - if (value3 != null ? !value3.equals(that.value3) : that.value3 != null) return false; - if (value4 != null ? !value4.equals(that.value4) : that.value4 != null) return false; - return deleted != null ? deleted.equals(that.deleted) : that.deleted == null; - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (item != null ? item.hashCode() : 0); - result = 31 * result + (value != null ? value.hashCode() : 0); - result = 31 * result + (value2 != null ? value2.hashCode() : 0); - result = 31 * result + (value3 != null ? value3.hashCode() : 0); - result = 31 * result + (value4 != null ? value4.hashCode() : 0); - result = 31 * result + (deleted != null ? deleted.hashCode() : 0); - return result; - } - - public static Creator CREATOR = new Creator() { - @Override - public StoreObject createFromParcel(Parcel source) { - return new StoreObject(source); - } - - @Override - public StoreObject[] newArray(int size) { - return new StoreObject[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(id); - dest.writeString(type); - dest.writeString(item); - dest.writeString(value); - dest.writeString(value2); - dest.writeString(value3); - dest.writeString(value4); - dest.writeLong(deleted); - } - - @Override - public String toString() { - return "StoreObject{" + - "id=" + id + - ", type='" + type + '\'' + - ", item='" + item + '\'' + - ", value='" + value + '\'' + - ", value2='" + value2 + '\'' + - ", value3='" + value3 + '\'' + - ", value4='" + value4 + '\'' + - ", deleted=" + deleted + - '}'; - } -} diff --git a/app/src/main/java/org/tasks/data/StoreObjectDao.java b/app/src/main/java/org/tasks/data/StoreObjectDao.java deleted file mode 100644 index 0ed88d731..000000000 --- a/app/src/main/java/org/tasks/data/StoreObjectDao.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.tasks.data; - -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.OnConflictStrategy; -import android.arch.persistence.room.Query; -import android.arch.persistence.room.Update; - -import com.todoroo.astrid.gtasks.GtasksList; - -import java.util.List; - -@Dao -public abstract class StoreObjectDao { - - @Query("SELECT * FROM store WHERE _id = :id LIMIT 1") - abstract StoreObject getById(long id); - - public GtasksList getGtasksList(long id) { - StoreObject result = getById(id); - if (result == null) { - throw new RuntimeException(String.format("No store object found [id=%s]", id)); - } else if (!result.getType().equals(GtasksList.TYPE)) { - throw new RuntimeException("Not a google task list"); - } - return new GtasksList(result); - } - - @Query("SELECT * FROM store WHERE deleted = 0 AND type = 'gtasks-list' ORDER BY value ASC") - public abstract List getGtasksLists(); - - @Insert(onConflict = OnConflictStrategy.REPLACE) - public abstract long insert(StoreObject storeObject); - - public boolean persist(StoreObject storeObject) { - long id = insert(storeObject); - if (id >= 0) { - storeObject.setId(id); - return true; - } - return false; - } - - public void persist(GtasksList list) { - persist(list.getStoreObject()); - } - - @Update - public abstract void update(StoreObject storeObject); - - @Query("DELETE FROM store WHERE _id = :id") - public abstract void delete(long id); -} - diff --git a/app/src/main/java/org/tasks/db/Migrations.java b/app/src/main/java/org/tasks/db/Migrations.java index ec704fd73..efba81499 100644 --- a/app/src/main/java/org/tasks/db/Migrations.java +++ b/app/src/main/java/org/tasks/db/Migrations.java @@ -83,6 +83,16 @@ public class Migrations { } }; + private static final Migration MIGRATION_51_52 = new Migration(51, 52) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE IF NOT EXISTS `google_task_lists` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remote_id` TEXT, `title` TEXT, `remote_order` INTEGER NOT NULL, `last_sync` INTEGER NOT NULL, `deleted` INTEGER NOT NULL, `color` INTEGER)"); + database.execSQL("INSERT INTO `google_task_lists` (`remote_id`, `title`, `remote_order`, `last_sync`, `color`, `deleted`) " + + "SELECT `item`, `value`, `value2`, `value3`, `value4`, `deleted` FROM `store` WHERE `type` = 'gtasks-list'"); + database.execSQL("DROP TABLE IF EXISTS `store`"); + } + }; + private static Migration NOOP(int from, int to) { return new Migration(from, to) { @Override @@ -97,17 +107,12 @@ public class Migrations { MIGRATION_36_37, MIGRATION_37_38, MIGRATION_38_39, - NOOP(39, 40), - NOOP(40, 41), - NOOP(41, 42), - NOOP(42, 43), - NOOP(43, 44), - NOOP(44, 45), - NOOP(45, 46), + NOOP(39, 46), MIGRATION_46_47, MIGRATION_47_48, MIGRATION_48_49, MIGRATION_49_50, - MIGRATION_50_51 + MIGRATION_50_51, + MIGRATION_51_52 }; } diff --git a/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java b/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java index 2022bdf1e..dd78617c2 100644 --- a/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java +++ b/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java @@ -12,15 +12,15 @@ import com.todoroo.astrid.api.MultipleSelectCriterion; import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.TextInputCriterion; import com.todoroo.astrid.dao.TaskDao; -import org.tasks.data.TagData; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.gtasks.GtasksList; import com.todoroo.astrid.gtasks.GtasksListService; import com.todoroo.astrid.tags.TagService; import org.tasks.R; import org.tasks.data.GoogleTask; +import org.tasks.data.GoogleTaskList; import org.tasks.data.Tag; +import org.tasks.data.TagData; import org.tasks.gtasks.SyncAdapterHelper; import org.tasks.injection.ForApplication; @@ -169,12 +169,12 @@ public class FilterCriteriaProvider { } private CustomFilterCriterion getGtasksFilterCriteria() { - List lists = gtasksListService.getLists(); + List lists = gtasksListService.getLists(); String[] listNames = new String[lists.size()]; String[] listIds = new String[lists.size()]; for (int i = 0; i < lists.size(); i++) { - listNames[i] = lists.get(i).getName(); + listNames[i] = lists.get(i).getTitle(); listIds[i] = lists.get(i).getRemoteId(); } diff --git a/app/src/main/java/org/tasks/gtasks/GoogleTaskListSelectionHandler.java b/app/src/main/java/org/tasks/gtasks/GoogleTaskListSelectionHandler.java index 1e26bd2d0..0f45dc17b 100644 --- a/app/src/main/java/org/tasks/gtasks/GoogleTaskListSelectionHandler.java +++ b/app/src/main/java/org/tasks/gtasks/GoogleTaskListSelectionHandler.java @@ -1,7 +1,7 @@ package org.tasks.gtasks; -import com.todoroo.astrid.gtasks.GtasksList; +import org.tasks.data.GoogleTaskList; public interface GoogleTaskListSelectionHandler { - void selectedList(GtasksList list); + void selectedList(GoogleTaskList list); } diff --git a/app/src/main/java/org/tasks/injection/ApplicationModule.java b/app/src/main/java/org/tasks/injection/ApplicationModule.java index 521c24915..633e5c778 100644 --- a/app/src/main/java/org/tasks/injection/ApplicationModule.java +++ b/app/src/main/java/org/tasks/injection/ApplicationModule.java @@ -6,7 +6,7 @@ import android.content.Context; import com.todoroo.astrid.dao.Database; import org.tasks.data.FilterDao; -import org.tasks.data.StoreObjectDao; +import org.tasks.data.GoogleTaskListDao; import org.tasks.data.TagDataDao; import org.tasks.data.TaskAttachmentDao; import org.tasks.data.TaskListMetadataDao; @@ -92,11 +92,6 @@ public class ApplicationModule { return database.getTaskListMetadataDao(); } - @Provides - public StoreObjectDao getStoreObjectDao(Database database) { - return database.getStoreObjectDao(); - } - @Provides public GoogleTaskDao getGoogleTaskDao(Database database) { return database.getGoogleTaskDao(); @@ -121,4 +116,9 @@ public class ApplicationModule { public FilterDao getFilterDao(Database database) { return database.getFilterDao(); } + + @Provides + public GoogleTaskListDao getGoogleTaskListDao(Database database) { + return database.getGoogleTaskListDao(); + } }