Implement BriefMe for fetching tasks for a user

pull/14/head
Sam Bosley 12 years ago
parent 5359797b82
commit 0f52169f74

@ -70,6 +70,10 @@ public final class User extends RemoteModel {
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, PUSHED_AT_PROPERTY_NAME);
/** Pushed at date */
public static final LongProperty TASKS_PUSHED_AT = new LongProperty(
TABLE, "tasks_pushed_at");
/** Friendship status. One of the STATUS constants below */
public static final StringProperty STATUS = new StringProperty(
TABLE, "status");
@ -94,6 +98,7 @@ public final class User extends RemoteModel {
defaultValues.put(EMAIL.name, "");
defaultValues.put(PICTURE.name, "");
defaultValues.put(PUSHED_AT.name, 0L);
defaultValues.put(TASKS_PUSHED_AT.name, 0L);
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(STATUS.name, "");
}

@ -16,6 +16,7 @@ public class BriefMe<TYPE extends RemoteModel> extends ClientToServerMessage<TYP
public static final String TASK_ID_KEY = "task_id"; //$NON-NLS-1$
public static final String TAG_ID_KEY = "tag_id"; //$NON-NLS-1$
public static final String USER_ID_KEY = "user_id"; //$NON-NLS-1$
public static <TYPE extends RemoteModel> BriefMe<TYPE> instantiateBriefMeForClass(Class<TYPE> cls, String pushedAtKey) {
long pushedAt = Preferences.getLong(pushedAtKey, 0);
@ -37,7 +38,7 @@ public class BriefMe<TYPE extends RemoteModel> extends ClientToServerMessage<TYP
@Override
protected boolean serializeExtrasToJSON(JSONObject serializeTo, MultipartEntity entity) throws JSONException {
if (extraParameters != null && extraParameters.length > 0) {
for (int i = 0; i < extraParameters.length - 1; i++) {
for (int i = 0; i < extraParameters.length - 1; i+=2) {
try {
String key = (String) extraParameters[i];
Object value = extraParameters[i + 1];

@ -14,6 +14,7 @@ import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
@SuppressWarnings("nls")
public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage {
@ -25,6 +26,7 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
private final String uuid;
private final String taskId;
private final String tagId;
private final String userId;
private long pushedAt;
public NowBriefed(JSONObject json, RemoteModelDao<TYPE> dao) {
@ -33,6 +35,7 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
this.uuid = json.optString("uuid");
this.taskId = json.optString(BriefMe.TASK_ID_KEY);
this.tagId = json.optString(BriefMe.TAG_ID_KEY);
this.userId = json.optString(BriefMe.USER_ID_KEY);
this.dao = dao;
try {
this.pushedAt = DateUtilities.parseIso8601(json.optString("pushed_at"));
@ -67,6 +70,12 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
if (template.getSetValues() != null)
PluginServices.getTagDataDao().update(TagData.UUID.eq(tagId), template);
} else if (!TextUtils.isEmpty(userId)) {
if (NameMaps.TABLE_ID_TASKS.equals(table)) {
User template = new User();
template.setValue(User.TASKS_PUSHED_AT, pushedAt);
PluginServices.getUserDao().update(User.UUID.eq(userId), template);
}
} else {
String pushedAtKey = null;
if (NameMaps.TABLE_ID_TASKS.equals(table))

@ -191,7 +191,10 @@ public class PersonViewFragment extends TaskListFragment {
return;
if (user != null) {
long pushedAt = user.getValue(User.PUSHED_AT);
if(DateUtilities.now() - pushedAt > DateUtilities.ONE_HOUR / 2)
long tasksPushedAt = user.getValue(User.TASKS_PUSHED_AT);
if((DateUtilities.now() - pushedAt > DateUtilities.ONE_HOUR / 2) ||
(DateUtilities.now() - tasksPushedAt > DateUtilities.ONE_HOUR / 2))
refreshData();
}
}
@ -226,14 +229,14 @@ public class PersonViewFragment extends TaskListFragment {
@Override
public void runOnErrors(List<JSONArray> errors) {/**/}
};
long pushedAt = user.getValue(User.PUSHED_AT);
long pushedAt = user.getValue(User.TASKS_PUSHED_AT);
JSONArray existingTasks = new JSONArray();
TodorooCursor<Task> tasksCursor = (TodorooCursor<Task>) taskAdapter.getCursor();
for (tasksCursor.moveToFirst(); !tasksCursor.isAfterLast(); tasksCursor.moveToNext()) {
existingTasks.put(tasksCursor.get(Task.UUID));
}
BriefMe<Task> briefMe = new BriefMe<Task>(Task.class, null, pushedAt, "user_id", user.getValue(User.UUID), "existing_tasks", existingTasks); //$NON-NLS-1$//$NON-NLS-2$
BriefMe<Task> briefMe = new BriefMe<Task>(Task.class, null, pushedAt, BriefMe.USER_ID_KEY, user.getValue(User.UUID), "existing_task_ids", existingTasks); //$NON-NLS-1$
ActFmSyncThread.getInstance().enqueueMessage(briefMe, callback);
}
}

@ -153,7 +153,7 @@ public class Database extends AbstractDatabase {
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE INDEX IF NOT EXISTS hist_tag_id ON ").
append(History.TABLE).append('(').
append(History.TAG_ID.name).
@ -394,6 +394,7 @@ public class Database extends AbstractDatabase {
case 32:
tryExecSQL("DROP TABLE " + History.TABLE.name);
tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES));
tryExecSQL(addColumnSql(User.TABLE, User.TASKS_PUSHED_AT, visitor, null));
return true;
}

Loading…
Cancel
Save