|
|
|
|
@ -8,6 +8,7 @@ import java.util.Set;
|
|
|
|
|
import com.todoroo.andlib.data.Property;
|
|
|
|
|
import com.todoroo.andlib.data.Table;
|
|
|
|
|
import com.todoroo.andlib.utility.AndroidUtilities;
|
|
|
|
|
import com.todoroo.astrid.data.History;
|
|
|
|
|
import com.todoroo.astrid.data.TagData;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
|
import com.todoroo.astrid.data.User;
|
|
|
|
|
@ -27,6 +28,7 @@ public class NameMaps {
|
|
|
|
|
public static final String TABLE_ID_TAGS = "tags";
|
|
|
|
|
public static final String TABLE_ID_USERS = "users";
|
|
|
|
|
public static final String TABLE_ID_USER_ACTIVITY = "user_activities";
|
|
|
|
|
public static final String TABLE_ID_HISTORY = "history";
|
|
|
|
|
|
|
|
|
|
private static final String PUSHED_AT_PREFIX = "pushed_at";
|
|
|
|
|
public static final String PUSHED_AT_TASKS = PUSHED_AT_PREFIX + "_" + TABLE_ID_TASKS;
|
|
|
|
|
@ -97,9 +99,9 @@ public class NameMaps {
|
|
|
|
|
private static final Set<String> TASK_PROPERTIES_EXCLUDED;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void putTaskPropertyToServerName(Property<?> property, String serverName, boolean excludedFromOutstanding) {
|
|
|
|
|
private static void putTaskPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
|
|
|
|
|
putPropertyToServerName(property, serverName, TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES,
|
|
|
|
|
TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, excludedFromOutstanding);
|
|
|
|
|
TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, writeable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
@ -143,9 +145,9 @@ public class NameMaps {
|
|
|
|
|
private static final Map<String, Property<?>> TAG_DATA_PROPERTIES_SERVER_TO_LOCAL;
|
|
|
|
|
private static final Set<String> TAG_PROPERTIES_EXCLUDED;
|
|
|
|
|
|
|
|
|
|
private static void putTagPropertyToServerName(Property<?> property, String serverName, boolean excludedFromOutstanding) {
|
|
|
|
|
private static void putTagPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
|
|
|
|
|
putPropertyToServerName(property, serverName, TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES,
|
|
|
|
|
TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, excludedFromOutstanding);
|
|
|
|
|
TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, writeable);
|
|
|
|
|
}
|
|
|
|
|
static {
|
|
|
|
|
// Hardcoded local columns mapped to corresponding server names
|
|
|
|
|
@ -181,9 +183,9 @@ public class NameMaps {
|
|
|
|
|
private static final Map<String, String> USER_COLUMNS_LOCAL_TO_SERVER;
|
|
|
|
|
private static final Map<String, Property<?>> USER_PROPERTIES_SERVER_TO_LOCAL;
|
|
|
|
|
|
|
|
|
|
private static void putUserPropertyToServerName(Property<?> property, String serverName, boolean excludedFromOutstanding) {
|
|
|
|
|
private static void putUserPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
|
|
|
|
|
putPropertyToServerName(property, serverName, USER_PROPERTIES_LOCAL_TO_SERVER, USER_COLUMN_NAMES_TO_PROPERTIES,
|
|
|
|
|
USER_COLUMNS_LOCAL_TO_SERVER, null, excludedFromOutstanding);
|
|
|
|
|
USER_COLUMNS_LOCAL_TO_SERVER, null, writeable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
@ -210,9 +212,9 @@ public class NameMaps {
|
|
|
|
|
private static final Map<String, Property<?>> USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL;
|
|
|
|
|
private static final Set<String> USER_ACTIVITY_PROPERTIES_EXCLUDED;
|
|
|
|
|
|
|
|
|
|
private static void putUserActivityPropertyToServerName(Property<?> property, String serverName, boolean excludedFromOutstanding) {
|
|
|
|
|
private static void putUserActivityPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
|
|
|
|
|
putPropertyToServerName(property, serverName, USER_ACTIVITY_PROPERTIES_LOCAL_TO_SERVER, USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES,
|
|
|
|
|
USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_PROPERTIES_EXCLUDED, excludedFromOutstanding);
|
|
|
|
|
USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_PROPERTIES_EXCLUDED, writeable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
@ -236,12 +238,43 @@ public class NameMaps {
|
|
|
|
|
USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(USER_ACTIVITY_PROPERTIES_LOCAL_TO_SERVER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
|
// History
|
|
|
|
|
// ----------
|
|
|
|
|
private static final Map<Property<?>, String> HISTORY_PROPERTIES_LOCAL_TO_SERVER;
|
|
|
|
|
private static final Map<String, Property<?>> HISTORY_COLUMN_NAMES_TO_PROPERTIES;
|
|
|
|
|
private static final Map<String, String> HISTORY_COLUMNS_LOCAL_TO_SERVER;
|
|
|
|
|
private static final Map<String, Property<?>> HISTORY_PROPERTIES_SERVER_TO_LOCAL;
|
|
|
|
|
private static final Set<String> HISTORY_PROPERTIES_EXCLUDED;
|
|
|
|
|
|
|
|
|
|
private static void putHistoryPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
|
|
|
|
|
putPropertyToServerName(property, serverName, HISTORY_PROPERTIES_LOCAL_TO_SERVER, HISTORY_COLUMN_NAMES_TO_PROPERTIES,
|
|
|
|
|
HISTORY_COLUMNS_LOCAL_TO_SERVER, HISTORY_PROPERTIES_EXCLUDED, writeable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
HISTORY_PROPERTIES_LOCAL_TO_SERVER = new HashMap<Property<?>, String>();
|
|
|
|
|
HISTORY_COLUMN_NAMES_TO_PROPERTIES = new HashMap<String, Property<?>>();
|
|
|
|
|
HISTORY_COLUMNS_LOCAL_TO_SERVER = new HashMap<String, String>();
|
|
|
|
|
HISTORY_PROPERTIES_EXCLUDED = new HashSet<String>();
|
|
|
|
|
|
|
|
|
|
putHistoryPropertyToServerName(History.UUID, "uuid", false);
|
|
|
|
|
putHistoryPropertyToServerName(History.CREATED_AT, "created_at", false);
|
|
|
|
|
putHistoryPropertyToServerName(History.USER_UUID, "user_id", false);
|
|
|
|
|
putHistoryPropertyToServerName(History.COLUMN, "column", false);
|
|
|
|
|
putHistoryPropertyToServerName(History.OLD_VALUE, "prev", false);
|
|
|
|
|
putHistoryPropertyToServerName(History.NEW_VALUE, "value", false);
|
|
|
|
|
|
|
|
|
|
// Reverse the mapping to construct the server to local map
|
|
|
|
|
HISTORY_PROPERTIES_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(USER_ACTIVITY_PROPERTIES_LOCAL_TO_SERVER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
|
// Mapping helpers
|
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
|
|
private static <A, B> B mapColumnName(String table, String col, Map<A, B> taskMap, Map<A, B> tagMap, Map<A, B> userMap, Map<A, B> userActivityMap) {
|
|
|
|
|
private static <A, B> B mapColumnName(String table, String col, Map<A, B> taskMap, Map<A, B> tagMap, Map<A, B> userMap, Map<A, B> userActivityMap, Map<A, B> historyMap) {
|
|
|
|
|
Map<A, B> map = null;
|
|
|
|
|
if (TABLE_ID_TASKS.equals(table))
|
|
|
|
|
map = taskMap;
|
|
|
|
|
@ -251,6 +284,8 @@ public class NameMaps {
|
|
|
|
|
map = userMap;
|
|
|
|
|
else if (TABLE_ID_USER_ACTIVITY.equals(table))
|
|
|
|
|
map = userActivityMap;
|
|
|
|
|
else if (TABLE_ID_HISTORY.equals(table))
|
|
|
|
|
map = historyMap;
|
|
|
|
|
|
|
|
|
|
if (map == null)
|
|
|
|
|
return null;
|
|
|
|
|
@ -273,15 +308,15 @@ public class NameMaps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String localColumnNameToServerColumnName(String table, String localColumn) {
|
|
|
|
|
return mapColumnName(table, localColumn, TASK_COLUMNS_LOCAL_TO_SERVER, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, USER_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER);
|
|
|
|
|
return mapColumnName(table, localColumn, TASK_COLUMNS_LOCAL_TO_SERVER, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, USER_COLUMNS_LOCAL_TO_SERVER, USER_ACTIVITY_COLUMNS_LOCAL_TO_SERVER, HISTORY_COLUMNS_LOCAL_TO_SERVER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Property<?> localColumnNameToProperty(String table, String localColumn) {
|
|
|
|
|
return mapColumnName(table, localColumn, TASK_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, USER_COLUMN_NAMES_TO_PROPERTIES, USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES);
|
|
|
|
|
return mapColumnName(table, localColumn, TASK_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, USER_COLUMN_NAMES_TO_PROPERTIES, USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES, HISTORY_COLUMN_NAMES_TO_PROPERTIES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Property<?> serverColumnNameToLocalProperty(String table, String serverColumn) {
|
|
|
|
|
return mapColumnName(table, serverColumn, TASK_PROPERTIES_SERVER_TO_LOCAL, TAG_DATA_PROPERTIES_SERVER_TO_LOCAL, USER_PROPERTIES_SERVER_TO_LOCAL, USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL);
|
|
|
|
|
return mapColumnName(table, serverColumn, TASK_PROPERTIES_SERVER_TO_LOCAL, TAG_DATA_PROPERTIES_SERVER_TO_LOCAL, USER_PROPERTIES_SERVER_TO_LOCAL, USER_ACTIVITY_PROPERTIES_SERVER_TO_LOCAL, HISTORY_PROPERTIES_SERVER_TO_LOCAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|