Migration to separate columns for task flags

pull/14/head
Sam Bosley 12 years ago
parent cd813a41de
commit 1fd38dc245

@ -134,9 +134,6 @@ public final class TagData extends RemoteModel {
// --- flags // --- flags
/** whether tag is publicly visible */
public static final int FLAG_PUBLIC = 1 << 0;
/** whether user should not be notified of tag activity */ /** whether user should not be notified of tag activity */
public static final int FLAG_SILENT = 1 << 1; public static final int FLAG_SILENT = 1 << 1;

@ -95,6 +95,12 @@ public final class Task extends RemoteModel {
public static final IntegerProperty FLAGS = new IntegerProperty( public static final IntegerProperty FLAGS = new IntegerProperty(
TABLE, "flags"); 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 // --- non-core task metadata
public static final StringProperty NOTES = new StringProperty( 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; public static final int FLAG_REPEAT_AFTER_COMPLETION = 1 << 1;
/** whether task is read-only */ /** 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 */ /** 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 // --- user id special values
@ -277,6 +283,8 @@ public final class Task extends RemoteModel {
defaultValues.put(TIMER_START.name, 0); defaultValues.put(TIMER_START.name, 0);
defaultValues.put(DETAILS.name, (String)null); defaultValues.put(DETAILS.name, (String)null);
defaultValues.put(DETAILS_DATE.name, 0); 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.put(LAST_SYNC.name, 0);
defaultValues.putNull(REMOTE_ID.name); defaultValues.putNull(REMOTE_ID.name);
@ -488,8 +496,8 @@ public final class Task extends RemoteModel {
} }
public boolean isEditable() { public boolean isEditable() {
return !getFlag(Task.FLAGS, Task.FLAG_IS_READONLY) && return (getValue(Task.IS_READONLY) == 0) &&
!(getFlag(Task.FLAGS, Task.FLAG_PUBLIC) && getValue(Task.USER_ID) != Task.USER_ID_SELF); !(getValue(Task.IS_PUBLIC) == 1 && getValue(Task.USER_ID) != Task.USER_ID_SELF);
} }
/** /**

@ -12,7 +12,6 @@ import android.database.SQLException;
import com.todoroo.andlib.data.ContentResolverDao; import com.todoroo.andlib.data.ContentResolverDao;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
@ -100,15 +99,13 @@ public class TaskApiDao extends ContentResolverDao<Task> {
return Criterion.and(Task.COMPLETION_DATE.eq(0), return Criterion.and(Task.COMPLETION_DATE.eq(0),
Task.DELETION_DATE.eq(0), Task.DELETION_DATE.eq(0),
Task.HIDE_UNTIL.lt(Functions.now()), Task.HIDE_UNTIL.lt(Functions.now()),
Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ Task.IS_READONLY.eq(0),
Task.FLAG_IS_READONLY).eq(0),
Task.USER_ID.eq(0)); Task.USER_ID.eq(0));
} }
/** Check if a given task belongs to someone else & is read-only */ /** Check if a given task belongs to someone else & is read-only */
public static Criterion ownedByMe() { public static Criterion ownedByMe() {
return Criterion.and(Field.field(Task.FLAGS.name+ " & " + //$NON-NLS-1$ return Criterion.and(Task.IS_READONLY.eq(0),
Task.FLAG_IS_READONLY).eq(0),
Task.USER_ID.eq(0)); Task.USER_ID.eq(0));
} }

@ -1839,7 +1839,7 @@ public final class ActFmSyncService {
model.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, false); model.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, false);
String privacy = json.optString("privacy"); 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.NOTES, json.optString("notes", ""));
model.setValue(Task.DETAILS_DATE, 0L); model.setValue(Task.DETAILS_DATE, 0L);
model.setValue(Task.LAST_SYNC, DateUtilities.now() + 1000L); model.setValue(Task.LAST_SYNC, DateUtilities.now() + 1000L);

@ -210,9 +210,9 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
if(remote.pdvTask.getValue(ProducteevTask.CREATOR_ID) != userId && if(remote.pdvTask.getValue(ProducteevTask.CREATOR_ID) != userId &&
remote.pdvTask.getValue(ProducteevTask.RESPONSIBLE_ID) != userId) remote.pdvTask.getValue(ProducteevTask.RESPONSIBLE_ID) != userId)
remote.task.setFlag(Task.FLAGS, Task.FLAG_IS_READONLY, true); remote.task.setValue(Task.IS_READONLY, 1);
else else
remote.task.setFlag(Task.FLAGS, Task.FLAG_IS_READONLY, false); remote.task.setValue(Task.IS_READONLY, 0);
// update reminder flags for incoming remote tasks to prevent annoying // update reminder flags for incoming remote tasks to prevent annoying
if(remote.task.hasDueDate() && remote.task.getValue(Task.DUE_DATE) < DateUtilities.now()) if(remote.task.hasDueDate() && remote.task.getValue(Task.DUE_DATE) < DateUtilities.now())

@ -79,8 +79,21 @@ public class AstridNewSyncMigrator {
Query tagsWithoutUUIDQuery = Query.select(TagData.ID, TagData.REMOTE_ID).where(Criterion.all); Query tagsWithoutUUIDQuery = Query.select(TagData.ID, TagData.REMOTE_ID).where(Criterion.all);
assertUUIDsExist(tagsWithoutUUIDQuery, new TagData(), tagDataDao, null); assertUUIDsExist(tagsWithoutUUIDQuery, new TagData(), tagDataDao, null);
Query tasksWithoutUUIDQuery = Query.select(Task.ID, Task.REMOTE_ID).where(Criterion.all); Query tasksWithoutUUIDQuery = Query.select(Task.ID, Task.REMOTE_ID, Task.FLAGS).where(Criterion.all);
assertUUIDsExist(tasksWithoutUUIDQuery, new Task(), taskDao, null); assertUUIDsExist(tasksWithoutUUIDQuery, new Task(), taskDao, new UUIDAssertionExtras<Task>() {
@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); Query updatesWithoutUUIDQuery = Query.select(Update.ID, Update.REMOTE_ID, Update.TASK).where(Criterion.all);
assertUUIDsExist(updatesWithoutUUIDQuery, new Update(), updateDao, new UUIDAssertionExtras<Update>() { assertUUIDsExist(updatesWithoutUUIDQuery, new Update(), updateDao, new UUIDAssertionExtras<Update>() {

@ -1121,7 +1121,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo;
Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task; Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task;
if (task.getFlag(Task.FLAGS, Task.FLAG_IS_READONLY)) if (task.getValue(Task.IS_READONLY) > 0)
return; return;
int id = (int) task.getId(); int id = (int) task.getId();

@ -125,6 +125,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
Task.ID, Task.ID,
Task.TITLE, Task.TITLE,
Task.FLAGS, Task.FLAGS,
Task.IS_READONLY,
Task.IS_PUBLIC,
Task.IMPORTANCE, Task.IMPORTANCE,
Task.DUE_DATE, Task.DUE_DATE,
Task.COMPLETION_DATE, Task.COMPLETION_DATE,
@ -148,6 +150,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
Task.ID, Task.ID,
Task.TITLE, Task.TITLE,
Task.FLAGS, Task.FLAGS,
Task.IS_READONLY,
Task.IS_PUBLIC,
Task.IMPORTANCE, Task.IMPORTANCE,
Task.RECURRENCE, Task.RECURRENCE,
Task.COMPLETION_DATE, Task.COMPLETION_DATE,

@ -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.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(Task.TABLE, Task.UUID, 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.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(TagData.TABLE, TagData.UUID, visitor, null)); database.execSQL(addColumnSql(TagData.TABLE, TagData.UUID, visitor, null));
database.execSQL(addColumnSql(Update.TABLE, Update.PUSHED_AT, visitor, null)); database.execSQL(addColumnSql(Update.TABLE, Update.PUSHED_AT, visitor, null));

@ -17,7 +17,6 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
@ -85,8 +84,7 @@ public class TaskDao extends RemoteModelDao<Task> {
return Criterion.and(Task.COMPLETION_DATE.eq(0), return Criterion.and(Task.COMPLETION_DATE.eq(0),
Task.DELETION_DATE.eq(0), Task.DELETION_DATE.eq(0),
Task.HIDE_UNTIL.lt(Functions.now()), Task.HIDE_UNTIL.lt(Functions.now()),
Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ Task.IS_READONLY.eq(0),
Task.FLAG_IS_READONLY).eq(0),
Task.USER_ID.eq(0)); Task.USER_ID.eq(0));
} }

Loading…
Cancel
Save