From 1fd38dc245218d4396a902fe7b8502f114c4d36b Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 18 Jan 2013 14:44:57 -0800 Subject: [PATCH] Migration to separate columns for task flags --- api/src/com/todoroo/astrid/data/TagData.java | 3 --- api/src/com/todoroo/astrid/data/Task.java | 16 ++++++++++++---- api/src/com/todoroo/astrid/data/TaskApiDao.java | 7 ++----- .../astrid/actfm/sync/ActFmSyncService.java | 2 +- .../producteev/sync/ProducteevSyncProvider.java | 4 ++-- .../astrid/tags/AstridNewSyncMigrator.java | 17 +++++++++++++++-- .../astrid/activity/TaskListFragment.java | 2 +- .../com/todoroo/astrid/adapter/TaskAdapter.java | 4 ++++ astrid/src/com/todoroo/astrid/dao/Database.java | 2 ++ astrid/src/com/todoroo/astrid/dao/TaskDao.java | 6 ++---- 10 files changed, 41 insertions(+), 22 deletions(-) diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index 32a2dd22b..2aee67af7 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -134,9 +134,6 @@ public final class TagData extends RemoteModel { // --- flags - /** whether tag is publicly visible */ - public static final int FLAG_PUBLIC = 1 << 0; - /** whether user should not be notified of tag activity */ public static final int FLAG_SILENT = 1 << 1; diff --git a/api/src/com/todoroo/astrid/data/Task.java b/api/src/com/todoroo/astrid/data/Task.java index 73d999432..797f5611f 100644 --- a/api/src/com/todoroo/astrid/data/Task.java +++ b/api/src/com/todoroo/astrid/data/Task.java @@ -95,6 +95,12 @@ public final class Task extends RemoteModel { public static final IntegerProperty FLAGS = new IntegerProperty( TABLE, "flags"); + public static final IntegerProperty IS_PUBLIC = new IntegerProperty( + TABLE, "is_public"); + + public static final IntegerProperty IS_READONLY = new IntegerProperty( + TABLE, "is_readonly"); + // --- non-core task metadata public static final StringProperty NOTES = new StringProperty( @@ -184,10 +190,10 @@ public final class Task extends RemoteModel { public static final int FLAG_REPEAT_AFTER_COMPLETION = 1 << 1; /** whether task is read-only */ - public static final int FLAG_IS_READONLY = 1 << 2; + @Deprecated public static final int FLAG_IS_READONLY = 1 << 2; /** whether a task is public */ - public static final int FLAG_PUBLIC = 1 << 3; + @Deprecated public static final int FLAG_PUBLIC = 1 << 3; // --- user id special values @@ -277,6 +283,8 @@ public final class Task extends RemoteModel { defaultValues.put(TIMER_START.name, 0); defaultValues.put(DETAILS.name, (String)null); defaultValues.put(DETAILS_DATE.name, 0); + defaultValues.put(IS_PUBLIC.name, 0); + defaultValues.put(IS_READONLY.name, 0); defaultValues.put(LAST_SYNC.name, 0); defaultValues.putNull(REMOTE_ID.name); @@ -488,8 +496,8 @@ public final class Task extends RemoteModel { } public boolean isEditable() { - return !getFlag(Task.FLAGS, Task.FLAG_IS_READONLY) && - !(getFlag(Task.FLAGS, Task.FLAG_PUBLIC) && getValue(Task.USER_ID) != Task.USER_ID_SELF); + return (getValue(Task.IS_READONLY) == 0) && + !(getValue(Task.IS_PUBLIC) == 1 && getValue(Task.USER_ID) != Task.USER_ID_SELF); } /** diff --git a/api/src/com/todoroo/astrid/data/TaskApiDao.java b/api/src/com/todoroo/astrid/data/TaskApiDao.java index b1fc183ae..5dab47aaa 100644 --- a/api/src/com/todoroo/astrid/data/TaskApiDao.java +++ b/api/src/com/todoroo/astrid/data/TaskApiDao.java @@ -12,7 +12,6 @@ import android.database.SQLException; import com.todoroo.andlib.data.ContentResolverDao; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Query; import com.todoroo.astrid.api.PermaSql; @@ -100,15 +99,13 @@ public class TaskApiDao extends ContentResolverDao { return Criterion.and(Task.COMPLETION_DATE.eq(0), Task.DELETION_DATE.eq(0), Task.HIDE_UNTIL.lt(Functions.now()), - Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ - Task.FLAG_IS_READONLY).eq(0), + Task.IS_READONLY.eq(0), Task.USER_ID.eq(0)); } /** Check if a given task belongs to someone else & is read-only */ public static Criterion ownedByMe() { - return Criterion.and(Field.field(Task.FLAGS.name+ " & " + //$NON-NLS-1$ - Task.FLAG_IS_READONLY).eq(0), + return Criterion.and(Task.IS_READONLY.eq(0), Task.USER_ID.eq(0)); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index f516902d0..c2a2ebe6b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -1839,7 +1839,7 @@ public final class ActFmSyncService { model.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, false); String privacy = json.optString("privacy"); - model.setFlag(Task.FLAGS, Task.FLAG_PUBLIC, privacy.equals("public")); + model.setValue(Task.IS_PUBLIC, privacy.equals("public") ? 1 : 0); model.setValue(Task.NOTES, json.optString("notes", "")); model.setValue(Task.DETAILS_DATE, 0L); model.setValue(Task.LAST_SYNC, DateUtilities.now() + 1000L); diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java index d10bfcf1b..21882d1b7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevSyncProvider.java @@ -210,9 +210,9 @@ public class ProducteevSyncProvider extends SyncProvider() { + @Override + public void beforeSave(Task instance) { + if (instance.getFlag(Task.FLAGS, Task.FLAG_IS_READONLY)) { + instance.setFlag(Task.FLAGS, Task.FLAG_IS_READONLY, false); + instance.setValue(Task.IS_READONLY, 1); + } + + if (instance.getFlag(Task.FLAGS, Task.FLAG_PUBLIC)) { + instance.setFlag(Task.FLAGS, Task.FLAG_PUBLIC, false); + instance.setValue(Task.IS_PUBLIC, 1); + } + } + }); Query updatesWithoutUUIDQuery = Query.select(Update.ID, Update.REMOTE_ID, Update.TASK).where(Criterion.all); assertUUIDsExist(updatesWithoutUUIDQuery, new Update(), updateDao, new UUIDAssertionExtras() { diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index d860a04fa..c89b7d8ea 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -1121,7 +1121,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, ContextMenuInfo menuInfo) { AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo; Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task; - if (task.getFlag(Task.FLAGS, Task.FLAG_IS_READONLY)) + if (task.getValue(Task.IS_READONLY) > 0) return; int id = (int) task.getId(); diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 59fbb657b..a352225ea 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -125,6 +125,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable { Task.ID, Task.TITLE, Task.FLAGS, + Task.IS_READONLY, + Task.IS_PUBLIC, Task.IMPORTANCE, Task.DUE_DATE, Task.COMPLETION_DATE, @@ -148,6 +150,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable { Task.ID, Task.TITLE, Task.FLAGS, + Task.IS_READONLY, + Task.IS_PUBLIC, Task.IMPORTANCE, Task.RECURRENCE, Task.COMPLETION_DATE, diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index 3f8a0a6ed..fe8e4d764 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -362,6 +362,8 @@ public class Database extends AbstractDatabase { database.execSQL(addColumnSql(Task.TABLE, Task.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(Task.TABLE, Task.UUID, visitor, null)); + database.execSQL(addColumnSql(Task.TABLE, Task.IS_PUBLIC, visitor, "0")); + database.execSQL(addColumnSql(Task.TABLE, Task.IS_READONLY, visitor, "0")); database.execSQL(addColumnSql(TagData.TABLE, TagData.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(TagData.TABLE, TagData.UUID, visitor, null)); database.execSQL(addColumnSql(Update.TABLE, Update.PUSHED_AT, visitor, null)); diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 9aab29228..7597902b8 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -17,7 +17,6 @@ import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; @@ -85,9 +84,8 @@ public class TaskDao extends RemoteModelDao { return Criterion.and(Task.COMPLETION_DATE.eq(0), Task.DELETION_DATE.eq(0), Task.HIDE_UNTIL.lt(Functions.now()), - Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ - Task.FLAG_IS_READONLY).eq(0), - Task.USER_ID.eq(0)); + Task.IS_READONLY.eq(0), + Task.USER_ID.eq(0)); } /** @return tasks that have not yet been completed or deleted */