diff --git a/api/src/com/todoroo/andlib/data/Property.java b/api/src/com/todoroo/andlib/data/Property.java index 358995c71..ef876110f 100644 --- a/api/src/com/todoroo/andlib/data/Property.java +++ b/api/src/com/todoroo/andlib/data/Property.java @@ -38,7 +38,13 @@ public abstract class Property extends Field implements Cloneable { public final String name; /** Can this field be null? */ - public boolean nullable = false; + public static final int PROP_FLAG_NULLABLE = 1 << 0; + /** Is this field a date? */ + public static final int PROP_FLAG_DATE = 1 << 1; + /** Is this field a user id? */ + public static final int PROP_FLAG_USER_ID = 1 << 2; + + public int flags = 0; /** * Create a property by table and column name. Uses the default property @@ -52,9 +58,9 @@ public abstract class Property extends Field implements Cloneable { * Create a property by table and column name. Uses the default property * expression which is derived from default table name */ - protected Property(Table table, String columnName, boolean nullable) { + protected Property(Table table, String columnName, int flags) { this(table, columnName, (table == null) ? (columnName) : (table.name() + "." + columnName)); - this.nullable = nullable; + this.flags = flags; } /** @@ -117,8 +123,8 @@ public abstract class Property extends Field implements Cloneable { super(table, name); } - public IntegerProperty(Table table, String name, boolean nullable) { - super(table, name, nullable); + public IntegerProperty(Table table, String name, int flags) { + super(table, name, flags); } protected IntegerProperty(Table table, String name, String expression) { @@ -144,8 +150,8 @@ public abstract class Property extends Field implements Cloneable { super(table, name); } - public StringProperty(Table table, String name, boolean nullable) { - super(table, name, nullable); + public StringProperty(Table table, String name, int flags) { + super(table, name, flags); } protected StringProperty(Table table, String name, String expression) { @@ -191,8 +197,8 @@ public abstract class Property extends Field implements Cloneable { super(table, name); } - public DoubleProperty(Table table, String name, boolean nullable) { - super(table, name, nullable); + public DoubleProperty(Table table, String name, int flags) { + super(table, name, flags); } protected DoubleProperty(Table table, String name, String expression) { @@ -219,8 +225,8 @@ public abstract class Property extends Field implements Cloneable { super(table, name); } - public LongProperty(Table table, String name, boolean nullable) { - super(table, name, nullable); + public LongProperty(Table table, String name, int flags) { + super(table, name, flags); } protected LongProperty(Table table, String name, String expression) { @@ -239,6 +245,10 @@ public abstract class Property extends Field implements Cloneable { } } + public boolean checkFlag(int flag) { + return (flags & flag) > 0; + } + public String getColumnName() { if (hasAlias()) return alias; diff --git a/api/src/com/todoroo/andlib/data/TodorooCursor.java b/api/src/com/todoroo/andlib/data/TodorooCursor.java index b4249cf4f..0f512911b 100644 --- a/api/src/com/todoroo/andlib/data/TodorooCursor.java +++ b/api/src/com/todoroo/andlib/data/TodorooCursor.java @@ -101,7 +101,7 @@ public class TodorooCursor extends CursorWrapper { public Object visitDouble(Property property, TodorooCursor cursor) { int column = columnIndex(property, cursor); - if(property.nullable && cursor.isNull(column)) + if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) return null; return cursor.getDouble(column); } @@ -109,14 +109,14 @@ public class TodorooCursor extends CursorWrapper { public Object visitInteger(Property property, TodorooCursor cursor) { int column = columnIndex(property, cursor); - if(property.nullable && cursor.isNull(column)) + if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) return null; return cursor.getInt(column); } public Object visitLong(Property property, TodorooCursor cursor) { int column = columnIndex(property, cursor); - if(property.nullable && cursor.isNull(column)) + if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) return null; return cursor.getLong(column); } @@ -124,7 +124,7 @@ public class TodorooCursor extends CursorWrapper { public Object visitString(Property property, TodorooCursor cursor) { int column = columnIndex(property, cursor); - if(property.nullable && cursor.isNull(column)) + if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) return null; return cursor.getString(column); } diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index 9c50b4d7b..32a2dd22b 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -47,7 +47,7 @@ public final class TagData extends RemoteModel { /** User id */ public static final LongProperty USER_ID = new LongProperty( - TABLE, USER_ID_PROPERTY_NAME); + TABLE, USER_ID_PROPERTY_NAME, Property.PROP_FLAG_USER_ID); /** User Object (JSON) */ public static final StringProperty USER = new StringProperty( @@ -79,19 +79,19 @@ public final class TagData extends RemoteModel { /** Unixtime Project was created */ public static final LongProperty CREATION_DATE = new LongProperty( - TABLE, "created"); + TABLE, "created", Property.PROP_FLAG_DATE); /** Unixtime Project was last touched */ public static final LongProperty MODIFICATION_DATE = new LongProperty( - TABLE, "modified"); + TABLE, "modified", Property.PROP_FLAG_DATE); /** Unixtime Project was completed. 0 means active */ public static final LongProperty COMPLETION_DATE = new LongProperty( - TABLE, "completed"); + TABLE, "completed", Property.PROP_FLAG_DATE); /** Unixtime Project was deleted. 0 means not deleted */ public static final LongProperty DELETION_DATE = new LongProperty( - TABLE, "deleted"); + TABLE, "deleted", Property.PROP_FLAG_DATE); /** Project picture thumbnail */ public static final StringProperty THUMB = new StringProperty( @@ -99,7 +99,7 @@ public final class TagData extends RemoteModel { /** Project last activity date */ public static final LongProperty LAST_ACTIVITY_DATE = new LongProperty( - TABLE, "lastActivityDate"); + TABLE, "lastActivityDate", Property.PROP_FLAG_DATE); /** Whether user is part of Tag team */ public static final IntegerProperty IS_TEAM = new IntegerProperty( @@ -119,7 +119,7 @@ public final class TagData extends RemoteModel { /** Pushed at date */ public static final LongProperty PUSHED_AT = new LongProperty( - TABLE, PUSHED_AT_PROPERTY_NAME); + TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE); /** UUID */ public static final StringProperty UUID = new StringProperty( diff --git a/api/src/com/todoroo/astrid/data/Task.java b/api/src/com/todoroo/astrid/data/Task.java index b95d380c4..73d999432 100644 --- a/api/src/com/todoroo/astrid/data/Task.java +++ b/api/src/com/todoroo/astrid/data/Task.java @@ -60,27 +60,27 @@ public final class Task extends RemoteModel { /** Unixtime Task is due, 0 if not set */ public static final LongProperty DUE_DATE = new LongProperty( - TABLE, "dueDate"); + TABLE, "dueDate", Property.PROP_FLAG_DATE); /** Unixtime Task should be hidden until, 0 if not set */ public static final LongProperty HIDE_UNTIL = new LongProperty( - TABLE, "hideUntil"); + TABLE, "hideUntil", Property.PROP_FLAG_DATE); /** Unixtime Task was created */ public static final LongProperty CREATION_DATE = new LongProperty( - TABLE, "created"); + TABLE, "created", Property.PROP_FLAG_DATE); /** Unixtime Task was last touched */ public static final LongProperty MODIFICATION_DATE = new LongProperty( - TABLE, "modified"); + TABLE, "modified", Property.PROP_FLAG_DATE); /** Unixtime Task was completed. 0 means active */ public static final LongProperty COMPLETION_DATE = new LongProperty( - TABLE, "completed"); + TABLE, "completed", Property.PROP_FLAG_DATE); /** Unixtime Task was deleted. 0 means not deleted */ public static final LongProperty DELETION_DATE = new LongProperty( - TABLE, "deleted"); + TABLE, "deleted", Property.PROP_FLAG_DATE); /** Cached Details Column - built from add-on detail exposers. A null * value means there is no value in the cache and it needs to be @@ -90,7 +90,7 @@ public final class Task extends RemoteModel { /** Date details were last updated */ public static final LongProperty DETAILS_DATE = new LongProperty( - TABLE, "detailsDate"); + TABLE, "detailsDate", Property.PROP_FLAG_DATE); public static final IntegerProperty FLAGS = new IntegerProperty( TABLE, "flags"); @@ -107,7 +107,7 @@ public final class Task extends RemoteModel { TABLE, "elapsedSeconds"); public static final LongProperty TIMER_START = new LongProperty( - TABLE, "timerStart"); + TABLE, "timerStart", Property.PROP_FLAG_DATE); public static final IntegerProperty POSTPONE_COUNT = new IntegerProperty( TABLE, "postponeCount"); @@ -118,11 +118,11 @@ public final class Task extends RemoteModel { /** Reminder period, in milliseconds. 0 means disabled */ public static final LongProperty REMINDER_PERIOD = new LongProperty( - TABLE, "notifications"); + TABLE, "notifications", Property.PROP_FLAG_DATE); /** Unixtime the last reminder was triggered */ public static final LongProperty REMINDER_LAST = new LongProperty( - TABLE, "lastNotified"); + TABLE, "lastNotified", Property.PROP_FLAG_DATE); /** What kind of reminder the last reminder was: private task, * social with no faces, social with faces */ @@ -131,13 +131,13 @@ public final class Task extends RemoteModel { /** Unixtime snooze is set (0 -> no snooze) */ public static final LongProperty REMINDER_SNOOZE = new LongProperty( - TABLE, "snoozeTime"); + TABLE, "snoozeTime", Property.PROP_FLAG_DATE); public static final StringProperty RECURRENCE = new StringProperty( TABLE, "recurrence"); public static final LongProperty REPEAT_UNTIL = new LongProperty( - TABLE, "repeatUntil"); + TABLE, "repeatUntil", Property.PROP_FLAG_DATE); public static final StringProperty CALENDAR_URI = new StringProperty( TABLE, "calendarUri"); @@ -146,11 +146,11 @@ public final class Task extends RemoteModel { /** Remote id */ public static final LongProperty REMOTE_ID = new LongProperty( - TABLE, REMOTE_ID_PROPERTY_NAME, true); + TABLE, REMOTE_ID_PROPERTY_NAME, Property.PROP_FLAG_NULLABLE); /** Assigned user id */ public static final LongProperty USER_ID = new LongProperty( - TABLE, USER_ID_PROPERTY_NAME); + TABLE, USER_ID_PROPERTY_NAME, Property.PROP_FLAG_USER_ID); /** User Object (JSON) */ public static final StringProperty USER = new StringProperty( @@ -158,22 +158,22 @@ public final class Task extends RemoteModel { /** Creator user id */ public static final LongProperty CREATOR_ID = new LongProperty( - TABLE, "creatorId"); + TABLE, "creatorId", Property.PROP_FLAG_USER_ID); public static final StringProperty SHARED_WITH = new StringProperty( TABLE, "sharedWith"); /** Last Sync date */ public static final LongProperty LAST_SYNC = new LongProperty( - TABLE, "lastSync"); + TABLE, "lastSync", Property.PROP_FLAG_DATE); /** Pushed at date */ public static final LongProperty PUSHED_AT = new LongProperty( - TABLE, PUSHED_AT_PROPERTY_NAME); + TABLE, PUSHED_AT_PROPERTY_NAME, Property.PROP_FLAG_DATE); /** UUID */ public static final StringProperty UUID = new StringProperty( - TABLE, UUID_PROPERTY_NAME, true); + TABLE, UUID_PROPERTY_NAME, Property.PROP_FLAG_NULLABLE); /** List of all properties for this model */ public static final Property[] PROPERTIES = generateProperties(Task.class); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index 265cc96d2..fe40ffbe0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -159,8 +159,10 @@ public class ChangesHappened property, OE data) { Long l = data.getMergedValues().getAsLong(OutstandingEntry.VALUE_STRING_PROPERTY.name); if (l != null) { - if (l == 0 && (property.name.contains(RemoteModel.USER_ID_PROPERTY.name) || property.name.equals(Task.CREATOR_ID.name))) + if (l == 0 && property.checkFlag(Property.PROP_FLAG_USER_ID)) return ActFmPreferenceService.userId(); + else if (property.checkFlag(Property.PROP_FLAG_DATE)) + return l.longValue() / 1000L; return l; } else { return getAsString(data); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java index ae15fa191..61f96c2f3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java @@ -16,6 +16,7 @@ import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.SyncFlags; @@ -111,6 +112,10 @@ public class MakeChanges extends ServerToClientMessage public Void visitLong(Property property, String key) { try { long value = data.getLong(key); + if (property.checkFlag(Property.PROP_FLAG_USER_ID) && value == ActFmPreferenceService.userId()) + value = 0; + else if (property.checkFlag(Property.PROP_FLAG_DATE)) + value = value * 1000L; model.setValue((LongProperty) property, value); } catch (JSONException e) { Log.e(ERROR_TAG, "Error reading long value with key " + key + " from JSON " + data, e); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java index be84ed7fd..522e53341 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java @@ -158,5 +158,4 @@ public class NameMaps { return mapColumnName(table, serverColumn, TASK_PROPERTIES_SERVER_TO_LOCAL, TAG_DATA_PROPERTIES_SERVER_TO_LOCAL); } - }