Introduce a property flag to indicate if an integer represents a boolean, use it to use the correct types when communicating flags to/from server

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

@ -43,6 +43,8 @@ public abstract class Property<TYPE> extends Field implements Cloneable {
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;
/** Is this field a boolean? */
public static final int PROP_FLAG_BOOLEAN = 1 << 3;
public int flags = 0;

@ -96,10 +96,10 @@ public final class Task extends RemoteModel {
TABLE, "flags");
public static final IntegerProperty IS_PUBLIC = new IntegerProperty(
TABLE, "is_public");
TABLE, "is_public", Property.PROP_FLAG_BOOLEAN);
public static final IntegerProperty IS_READONLY = new IntegerProperty(
TABLE, "is_readonly");
TABLE, "is_readonly", Property.PROP_FLAG_BOOLEAN);
// --- non-core task metadata

@ -139,6 +139,8 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
public Object visitInteger(Property<Integer> property, OE data) {
Integer i = data.getMergedValues().getAsInteger(OutstandingEntry.VALUE_STRING_PROPERTY.name);
if (i != null) {
if (property.checkFlag(Property.PROP_FLAG_BOOLEAN))
return i > 0;
return i;
} else {
return getAsString(data);

@ -33,7 +33,16 @@ public class JSONChangeToPropertyVisitor implements PropertyVisitor<Void, String
@Override
public Void visitInteger(Property<Integer> property, String key) {
try {
int value = data.getInt(key);
int value;
if (property.checkFlag(Property.PROP_FLAG_BOOLEAN)) {
try {
value = data.getBoolean(key) ? 1 : 0;
} catch (JSONException e) {
value = data.getInt(key);
}
} else {
value = data.getInt(key);
}
model.setValue((IntegerProperty) property, value);
} catch (JSONException e) {
Log.e(ERROR_TAG, "Error reading int value with key " + key + " from JSON " + data, e);

@ -91,6 +91,8 @@ public class NameMaps {
putPropertyToServerName(Task.CREATOR_ID, "creator_id", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true);
putPropertyToServerName(Task.UUID, "uuid", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true);
putPropertyToServerName(Task.PUSHED_AT, "pushed_at", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true);
putPropertyToServerName(Task.IS_PUBLIC, "public", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false);
putPropertyToServerName(Task.IS_READONLY, "read_only", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true);
TASK_PROPERTIES_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(TASK_PROPERTIES_LOCAL_TO_SERVER);
}

@ -68,11 +68,11 @@ public class DateUtilitiesTest extends TodorooTestCase {
public void testParseISO8601() {
String withTime = "2013-01-28T13:17:02+00:00";
Date date = new Date();
long date;
Calendar cal = Calendar.getInstance();
try {
date = DateUtilities.parseIso8601(withTime);
cal.setTime(date);
cal.setTimeInMillis(date);
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
} catch (ParseException e) {
e.printStackTrace();
@ -88,11 +88,11 @@ public class DateUtilitiesTest extends TodorooTestCase {
public void testParseISO8601NoTime() {
String withTime = "2013-01-28";
Date date = new Date();
long date;
Calendar cal = Calendar.getInstance();
try {
date = DateUtilities.parseIso8601(withTime);
cal.setTime(date);
cal.setTimeInMillis(date);
} catch (ParseException e) {
e.printStackTrace();
fail("Parse exception");

Loading…
Cancel
Save