Removed several references to Update model

pull/14/head
Sam Bosley 13 years ago
parent d2e9b1407b
commit bf6af525a6

@ -6,16 +6,6 @@
package com.todoroo.astrid.data;
import android.content.ContentValues;
import android.net.Uri;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants;
/**
* Data Model which represents an update (e.g. a comment or data update event)
@ -23,162 +13,162 @@ import com.todoroo.astrid.api.AstridApiConstants;
* @author Tim Su <tim@todoroo.com>
*
*/
@SuppressWarnings("nls")
@Deprecated
public class Update extends RemoteModel {
// --- table
/** table for this model */
public static final Table TABLE = new Table("updates", Update.class);
/** content uri for this model */
public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.API_PACKAGE + "/" +
TABLE.name);
// --- properties
/** ID */
public static final LongProperty ID = new LongProperty(
TABLE, ID_PROPERTY_NAME);
/** Remote ID */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** Associated Task remote-id (if any) */
@Deprecated // We changed uuids to strings
public static final LongProperty TASK = new LongProperty(
TABLE, "task");
/** Associated Task uuidid (if any) */
public static final StringProperty TASK_UUID = new StringProperty(
TABLE, "taskUuid");
/** Associated Task local-id (if any) */
public static final LongProperty TASK_LOCAL = new LongProperty(
TABLE, "taskLocal");
/** Associated Tag remote-ids (comma separated list with leading and trailing commas) */
public static final StringProperty TAGS = new StringProperty(
TABLE, "tag");
/** Associated Tag local-ids (comma separated list with leading and trailing commas) */
public static final StringProperty TAGS_LOCAL = new StringProperty(
TABLE, "tagsLocal");
/** From user id */
public static final StringProperty USER_ID = new StringProperty(
TABLE, USER_ID_PROPERTY_NAME);
/** From User Object (JSON) */
@Deprecated public static final StringProperty USER = new StringProperty(
TABLE, USER_JSON_PROPERTY_NAME);
/** Other user id */
public static final StringProperty OTHER_USER_ID = new StringProperty(
TABLE, "other_user_id");
/** Other User Object (JSON) */
public static final StringProperty OTHER_USER = new StringProperty(
TABLE, "other_user");
/** Action text */
public static final StringProperty ACTION = new StringProperty(
TABLE, "action");
/** Action code */
public static final StringProperty ACTION_CODE = new StringProperty(
TABLE, "actionCode");
/** Message */
public static final StringProperty MESSAGE = new StringProperty(
TABLE, "message");
/** Target Object Name */
public static final StringProperty TARGET_NAME = new StringProperty(
TABLE, "targetName");
/** From User Object (JSON) */
public static final StringProperty PICTURE = new StringProperty(
TABLE, "picture");
/** Unixtime Metadata was created */
public static final LongProperty CREATION_DATE = new LongProperty(
TABLE, "created");
/** Pushed at date */
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, PUSHED_AT_PROPERTY_NAME);
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(Update.class);
// --- constants
public static final String PICTURE_LOADING = "<loading>";
// --- defaults
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
@Override
public ContentValues getDefaultValues() {
return defaultValues;
}
static {
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(TASK.name, 0);
defaultValues.put(TASK_UUID.name, NO_UUID);
defaultValues.put(TASK_LOCAL.name, 0);
defaultValues.put(TAGS.name, "");
defaultValues.put(TAGS_LOCAL.name, 0);
defaultValues.put(USER_ID.name, "0");
defaultValues.put(USER.name, "");
defaultValues.put(OTHER_USER_ID.name, "0");
defaultValues.put(OTHER_USER.name, "");
defaultValues.put(ACTION.name, "");
defaultValues.put(ACTION_CODE.name, "");
defaultValues.put(MESSAGE.name, "");
defaultValues.put(TARGET_NAME.name, "");
defaultValues.put(PICTURE.name, "");
defaultValues.put(PUSHED_AT.name, 0L);
}
// --- data access boilerplate
public Update() {
super();
}
public Update(TodorooCursor<Update> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Update> cursor) {
super.readPropertiesFromCursor(cursor);
}
@Override
public long getId() {
return getIdHelper(ID);
}
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers
private static final Creator<Update> CREATOR = new ModelCreator<Update>(Update.class);
@Override
protected Creator<? extends AbstractModel> getCreator() {
return CREATOR;
}
}
//@SuppressWarnings("nls")
//@Deprecated
//public class Update extends RemoteModel {
//
// // --- table
//
// /** table for this model */
// public static final Table TABLE = new Table("updates", Update.class);
//
// /** content uri for this model */
// public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.API_PACKAGE + "/" +
// TABLE.name);
//
// // --- properties
//
// /** ID */
// public static final LongProperty ID = new LongProperty(
// TABLE, ID_PROPERTY_NAME);
//
// /** Remote ID */
// public static final StringProperty UUID = new StringProperty(
// TABLE, UUID_PROPERTY_NAME);
//
// /** Associated Task remote-id (if any) */
// @Deprecated // We changed uuids to strings
// public static final LongProperty TASK = new LongProperty(
// TABLE, "task");
//
// /** Associated Task uuidid (if any) */
// public static final StringProperty TASK_UUID = new StringProperty(
// TABLE, "taskUuid");
//
// /** Associated Task local-id (if any) */
// public static final LongProperty TASK_LOCAL = new LongProperty(
// TABLE, "taskLocal");
//
// /** Associated Tag remote-ids (comma separated list with leading and trailing commas) */
// public static final StringProperty TAGS = new StringProperty(
// TABLE, "tag");
//
// /** Associated Tag local-ids (comma separated list with leading and trailing commas) */
// public static final StringProperty TAGS_LOCAL = new StringProperty(
// TABLE, "tagsLocal");
//
// /** From user id */
// public static final StringProperty USER_ID = new StringProperty(
// TABLE, USER_ID_PROPERTY_NAME);
//
// /** From User Object (JSON) */
// @Deprecated public static final StringProperty USER = new StringProperty(
// TABLE, USER_JSON_PROPERTY_NAME);
//
// /** Other user id */
// public static final StringProperty OTHER_USER_ID = new StringProperty(
// TABLE, "other_user_id");
//
// /** Other User Object (JSON) */
// public static final StringProperty OTHER_USER = new StringProperty(
// TABLE, "other_user");
//
// /** Action text */
// public static final StringProperty ACTION = new StringProperty(
// TABLE, "action");
//
// /** Action code */
// public static final StringProperty ACTION_CODE = new StringProperty(
// TABLE, "actionCode");
//
// /** Message */
// public static final StringProperty MESSAGE = new StringProperty(
// TABLE, "message");
//
// /** Target Object Name */
// public static final StringProperty TARGET_NAME = new StringProperty(
// TABLE, "targetName");
//
// /** From User Object (JSON) */
// public static final StringProperty PICTURE = new StringProperty(
// TABLE, "picture");
//
// /** Unixtime Metadata was created */
// public static final LongProperty CREATION_DATE = new LongProperty(
// TABLE, "created");
//
// /** Pushed at date */
// public static final LongProperty PUSHED_AT = new LongProperty(
// TABLE, PUSHED_AT_PROPERTY_NAME);
//
// /** List of all properties for this model */
// public static final Property<?>[] PROPERTIES = generateProperties(Update.class);
//
// // --- constants
//
// public static final String PICTURE_LOADING = "<loading>";
//
// // --- defaults
//
// /** Default values container */
// private static final ContentValues defaultValues = new ContentValues();
//
// @Override
// public ContentValues getDefaultValues() {
// return defaultValues;
// }
//
// static {
// defaultValues.put(UUID.name, NO_UUID);
// defaultValues.put(TASK.name, 0);
// defaultValues.put(TASK_UUID.name, NO_UUID);
// defaultValues.put(TASK_LOCAL.name, 0);
// defaultValues.put(TAGS.name, "");
// defaultValues.put(TAGS_LOCAL.name, 0);
// defaultValues.put(USER_ID.name, "0");
// defaultValues.put(USER.name, "");
// defaultValues.put(OTHER_USER_ID.name, "0");
// defaultValues.put(OTHER_USER.name, "");
// defaultValues.put(ACTION.name, "");
// defaultValues.put(ACTION_CODE.name, "");
// defaultValues.put(MESSAGE.name, "");
// defaultValues.put(TARGET_NAME.name, "");
// defaultValues.put(PICTURE.name, "");
// defaultValues.put(PUSHED_AT.name, 0L);
// }
//
// // --- data access boilerplate
//
// public Update() {
// super();
// }
//
// public Update(TodorooCursor<Update> cursor) {
// this();
// readPropertiesFromCursor(cursor);
// }
//
// public void readFromCursor(TodorooCursor<Update> cursor) {
// super.readPropertiesFromCursor(cursor);
// }
//
// @Override
// public long getId() {
// return getIdHelper(ID);
// }
//
// @Override
// public String getUuid() {
// return getUuidHelper(UUID);
// }
//
// // --- parcelable helpers
//
// private static final Creator<Update> CREATOR = new ModelCreator<Update>(Update.class);
//
// @Override
// protected Creator<? extends AbstractModel> getCreator() {
// return CREATOR;
// }
//}

@ -5,9 +5,6 @@
*/
package com.todoroo.astrid.data;
import android.content.Context;
import com.todoroo.andlib.data.ContentResolverDao;
/**
* Data access object for accessing Astrid's {@link Update} table.
@ -15,10 +12,10 @@ import com.todoroo.andlib.data.ContentResolverDao;
* @author Andrey Marchenko <igendou@gmail.com>
*
*/
public class UpdateApiDao extends ContentResolverDao<Update>{
public UpdateApiDao(Context context) {
super(Update.class, context, Update.CONTENT_URI);
}
}
//public class UpdateApiDao extends ContentResolverDao<Update>{
//
// public UpdateApiDao(Context context) {
// super(Update.class, context, Update.CONTENT_URI);
// }
//
//}

@ -8,6 +8,7 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants;
@SuppressWarnings("nls")
@ -41,7 +42,7 @@ public class UserActivity extends RemoteModel {
/** User ID (activity initiator) */
public static final StringProperty USER_UUID = new StringProperty(
TABLE, "user_uuid");
TABLE, "user_uuid", Property.PROP_FLAG_USER_ID);
/** Action */
public static final StringProperty ACTION = new StringProperty(
@ -71,6 +72,25 @@ public class UserActivity extends RemoteModel {
public static final LongProperty DELETED_AT = new LongProperty(
TABLE, "created_at", Property.PROP_FLAG_DATE);
public UserActivity() {
super();
}
// --- Action codes
public static final String ACTION_TASK_COMMENT = "task_comment";
public static final String ACTION_TAG_COMMENT = "tag_comment";
public static final String ACTION_REQUEST_FRIENDSHIP = "request_friendship";
public static final String ACTION_CONFIRM_FRIENDSHIP = "confirm_friendship";
public static final String ACTION_ACHIEVEMENT_REACHED = "achievement_reached";
public UserActivity(TodorooCursor<UserActivity> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<UserActivity> cursor) {
super.readPropertiesFromCursor(cursor);
}
// --- helpers

@ -3,7 +3,6 @@ package com.timsu.astrid;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.PendingIntent;
@ -41,7 +40,6 @@ import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TagDataService;
@ -358,28 +356,25 @@ public class GCMIntentService extends GCMBaseIntentService {
FilterWithCustomIntent filter = (FilterWithCustomIntent)TagFilterExposer.filterFromTagData(context, tagData);
//filter.customExtras.putString(TagViewActivity.EXTRA_START_TAB, "updates");
if(intent.hasExtra("activity_id")) {
try {
Update update = new Update();
update.setValue(Update.UUID, intent.getStringExtra("activity_id"));
update.setValue(Update.USER_ID, intent.getStringExtra("user_id"));
JSONObject user = new JSONObject();
user.put("id", update.getValue(Update.USER_ID));
user.put("name", intent.getStringExtra("user_name"));
update.setValue(Update.ACTION, "commented");
update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.TARGET_NAME, intent.getStringExtra("title"));
String message = intent.getStringExtra("alert");
if(message.contains(":"))
message = message.substring(message.indexOf(':') + 2);
update.setValue(Update.MESSAGE, message);
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TAGS, "," + intent.getStringExtra("tag_id") + ",");
updateDao.createNew(update);
} catch (JSONException e) {
//
} catch (NumberFormatException e) {
//
}
// try {
// UserActivity update = new UserActivity();
// update.setValue(UserActivity.UUID, intent.getStringExtra("activity_id"));
// update.setValue(UserActivity.USER_UUID, intent.getStringExtra("user_id"));
//
// update.setValue(Update.ACTION_CODE, "tag_comment");
// update.setValue(Update.TARGET_NAME, intent.getStringExtra("title"));
// String message = intent.getStringExtra("alert");
// if(message.contains(":"))
// message = message.substring(message.indexOf(':') + 2);
// update.setValue(Update.MESSAGE, message);
// update.setValue(Update.CREATION_DATE, DateUtilities.now());
// update.setValue(Update.TAGS, "," + intent.getStringExtra("tag_id") + ",");
// updateDao.createNew(update);
// } catch (JSONException e) {
// //
// } catch (NumberFormatException e) {
// //
// }
}
Intent launchIntent = new Intent(context, TaskListActivity.class);

@ -16,7 +16,6 @@ import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuInflater;
@ -42,9 +41,8 @@ import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsService;
@ -72,7 +70,7 @@ public abstract class CommentsFragment extends ListFragment {
@Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired UpdateDao updateDao;
@Autowired UserActivityDao userActivityDao;
public CommentsFragment() {
DependencyInjectionService.getInstance().inject(this);
@ -105,7 +103,7 @@ public abstract class CommentsFragment extends ListFragment {
protected abstract void populateListHeader(ViewGroup header);
protected abstract Update createUpdate();
protected abstract UserActivity createUpdate();
protected abstract String commentAddStatistic();
@ -321,34 +319,35 @@ public abstract class CommentsFragment extends ListFragment {
}
}
private String getPictureHashForUpdate(Update u) {
String s = u.getValue(Update.TASK_UUID) + u.getValue(Update.CREATION_DATE);
private String getPictureHashForUpdate(UserActivity u) {
String s = u.getValue(UserActivity.TARGET_ID) + u.getValue(UserActivity.CREATED_AT);
return s;
}
protected void addComment() {
Update update = createUpdate();
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
try {
String updateString = getPictureHashForUpdate(update);
imageCache.put(updateString, picture);
update.setValue(Update.PICTURE, updateString);
}
catch (Exception e) {
Log.e("CommentFragment", "Failed to put image to disk...", e); //$NON-NLS-1$//$NON-NLS-2$
}
}
update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
UserActivity update = createUpdate();
// TODO: Fix picture uploading
// if (picture != null) {
// update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
// try {
// String updateString = getPictureHashForUpdate(update);
// imageCache.put(updateString, picture);
// update.setValue(Update.PICTURE, updateString);
// }
// catch (Exception e) {
// Log.e("CommentFragment", "Failed to put image to disk...", e); //$NON-NLS-1$//$NON-NLS-2$
// }
// }
// update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
userActivityDao.createNew(update);
//
// final long updateId = update.getId();
// final Bitmap tempPicture = picture;
// new Thread() {
// @Override
// public void run() {
// actFmSyncService.pushUpdate(updateId, tempPicture);
// }
// }.start();
addCommentField.setText(""); //$NON-NLS-1$
picture = null;

@ -23,7 +23,7 @@ import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.TagDataService;
@ -116,16 +116,15 @@ public class TagCommentsFragment extends CommentsFragment {
@Override
@SuppressWarnings("nls")
protected Update createUpdate() {
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.USER_ID, Task.USER_ID_SELF);
update.setValue(Update.TAGS, "," + tagData.getValue(TagData.UUID) + ",");
update.setValue(Update.TAGS_LOCAL, "," + tagData.getId() + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, tagData.getValue(TagData.NAME));
return update;
protected UserActivity createUpdate() {
UserActivity userActivity = new UserActivity();
userActivity.setValue(UserActivity.MESSAGE, addCommentField.getText().toString());
userActivity.setValue(UserActivity.ACTION, UserActivity.ACTION_TAG_COMMENT);
userActivity.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
userActivity.setValue(UserActivity.TARGET_ID, tagData.getUuid());
userActivity.setValue(UserActivity.TARGET_NAME, tagData.getValue(TagData.NAME));
userActivity.setValue(UserActivity.CREATED_AT, DateUtilities.now());
return userActivity;
}
@Override

@ -62,8 +62,8 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.TagDataService;
@ -299,7 +299,7 @@ public class TagViewFragment extends TaskListFragment {
if (tagData != null) {
long lastViewedComments = Preferences.getLong(CommentsFragment.UPDATES_LAST_VIEWED + tagData.getValue(TagData.UUID), 0);
int unreadCount = 0;
TodorooCursor<Update> commentCursor = tagDataService.getUpdatesWithExtraCriteria(tagData, Update.CREATION_DATE.gt(lastViewedComments));
TodorooCursor<UserActivity> commentCursor = tagDataService.getUpdatesWithExtraCriteria(tagData, UserActivity.CREATED_AT.gt(lastViewedComments));
try {
unreadCount = commentCursor.getCount();
} finally {

@ -7,14 +7,12 @@ import android.widget.ListView;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.service.StatisticsConstants;
public class TaskCommentsFragment extends CommentsFragment {
@ -55,11 +53,7 @@ public class TaskCommentsFragment extends CommentsFragment {
@Override
protected Cursor getCursor() {
if (!task.containsNonNullValue(Task.UUID))
return updateDao.query(Query.select(Update.PROPERTIES).where(Update.TASK_LOCAL.eq(task.getId())).orderBy(Order.desc(Update.CREATION_DATE)));
else
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.or(
Update.TASK.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId()))).orderBy(Order.desc(Update.CREATION_DATE)));
return userActivityDao.query(Query.select(UserActivity.PROPERTIES).where(UserActivity.TARGET_ID.eq(task.getUuid())));
}
@Override
@ -84,16 +78,14 @@ public class TaskCommentsFragment extends CommentsFragment {
}
@Override
protected Update createUpdate() {
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, UpdateAdapter.UPDATE_TASK_COMMENT);
update.setValue(Update.USER_ID, Task.USER_ID_SELF);
if (task.containsNonNullValue(Task.UUID))
update.setValue(Update.TASK_UUID, task.getValue(Task.UUID));
update.setValue(Update.TASK_LOCAL, task.getId());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, task.getValue(Task.TITLE));
protected UserActivity createUpdate() {
UserActivity update = new UserActivity();
update.setValue(UserActivity.MESSAGE, addCommentField.getText().toString());
update.setValue(UserActivity.ACTION, UpdateAdapter.UPDATE_TASK_COMMENT);
update.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
update.setValue(UserActivity.TARGET_ID, task.getUuid());
update.setValue(UserActivity.TARGET_NAME, task.getValue(Task.TITLE));
update.setValue(UserActivity.CREATED_AT, DateUtilities.now());
return update;
}

@ -61,12 +61,10 @@ import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.files.FileMetadata;
import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
@ -175,25 +173,25 @@ public final class ActFmSyncService {
}
});
updateDao.addListener(new ModelUpdateListener<Update>() {
@Override
public void onModelUpdated(final Update model, boolean outstandingEntries) {
if(model.checkAndClearTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC))
return;
if (actFmPreferenceService.isOngoing())
return;
final ContentValues setValues = model.getSetValues();
if(setValues == null || !checkForToken() || RemoteModel.isValidUuid(model.getValue(Update.UUID)))
return;
new Thread(new Runnable() {
@Override
public void run() {
pushUpdateOnSave(model, setValues, null);
}
}).start();
}
});
// updateDao.addListener(new ModelUpdateListener<Update>() {
// @Override
// public void onModelUpdated(final Update model, boolean outstandingEntries) {
// if(model.checkAndClearTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC))
// return;
// if (actFmPreferenceService.isOngoing())
// return;
// final ContentValues setValues = model.getSetValues();
// if(setValues == null || !checkForToken() || RemoteModel.isValidUuid(model.getValue(Update.UUID)))
// return;
//
// new Thread(new Runnable() {
// @Override
// public void run() {
// pushUpdateOnSave(model, setValues, null);
// }
// }).start();
// }
// });
tagDataDao.addListener(new ModelUpdateListener<TagData>() {
@Override
@ -242,9 +240,9 @@ public final class ActFmSyncService {
case PUSH_TYPE_TAG:
pushTag(pushOp.itemId);
break;
case PUSH_TYPE_UPDATE:
pushUpdate(pushOp.itemId);
break;
// case PUSH_TYPE_UPDATE:
// pushUpdate(pushOp.itemId);
// break;
}
}
}
@ -304,58 +302,58 @@ public final class ActFmSyncService {
// --- data push methods
/**
* Synchronize with server when data changes
*/
public void pushUpdateOnSave(Update update, ContentValues values, Bitmap imageData) {
if(!values.containsKey(Update.MESSAGE.name))
return;
ArrayList<Object> params = new ArrayList<Object>();
params.add("message"); params.add(update.getValue(Update.MESSAGE));
if(update.getValue(Update.TAGS).length() > 0) {
String tagId = update.getValue(Update.TAGS);
tagId = tagId.substring(1, tagId.indexOf(',', 1));
params.add("tag_id"); params.add(tagId);
}
if(!RemoteModel.NO_UUID.equals(update.getValue(Update.TASK_UUID))) {
params.add("task_id"); params.add(update.getValue(Update.TASK_UUID));
}
MultipartEntity picture = null;
if (imageData != null) {
picture = buildPictureData(imageData);
}
if(!checkForToken())
return;
try {
params.add("token"); params.add(token);
JSONObject result;
if (picture == null)
result = actFmInvoker.invoke("comment_add", params.toArray(new Object[params.size()]));
else
result = actFmInvoker.post("comment_add", picture, params.toArray(new Object[params.size()]));
update.setValue(Update.UUID, Long.toString(result.optLong("id")));
ImageDiskCache imageCache = ImageDiskCache.getInstance();
//TODO figure out a way to replace local image files with the url
String commentPicture = result.optString("picture");
if (!TextUtils.isEmpty(commentPicture)) {
String cachedPicture = update.getValue(Update.PICTURE);
if (!TextUtils.isEmpty(cachedPicture) && imageCache.contains(cachedPicture)) {
imageCache.move(update.getValue(Update.PICTURE), commentPicture);
}
update.setValue(Update.PICTURE, result.optString("picture"));
}
updateDao.saveExisting(update);
} catch (IOException e) {
if (notPermanentError(e))
addFailedPush(new FailedPush(PUSH_TYPE_UPDATE, update.getId()));
handleException("task-save", e);
}
}
// /**
// * Synchronize with server when data changes
// */
// public void pushUpdateOnSave(Update update, ContentValues values, Bitmap imageData) {
// if(!values.containsKey(Update.MESSAGE.name))
// return;
//
// ArrayList<Object> params = new ArrayList<Object>();
// params.add("message"); params.add(update.getValue(Update.MESSAGE));
//
// if(update.getValue(Update.TAGS).length() > 0) {
// String tagId = update.getValue(Update.TAGS);
// tagId = tagId.substring(1, tagId.indexOf(',', 1));
// params.add("tag_id"); params.add(tagId);
// }
//
// if(!RemoteModel.NO_UUID.equals(update.getValue(Update.TASK_UUID))) {
// params.add("task_id"); params.add(update.getValue(Update.TASK_UUID));
// }
// MultipartEntity picture = null;
// if (imageData != null) {
// picture = buildPictureData(imageData);
// }
// if(!checkForToken())
// return;
//
// try {
// params.add("token"); params.add(token);
// JSONObject result;
// if (picture == null)
// result = actFmInvoker.invoke("comment_add", params.toArray(new Object[params.size()]));
// else
// result = actFmInvoker.post("comment_add", picture, params.toArray(new Object[params.size()]));
// update.setValue(Update.UUID, Long.toString(result.optLong("id")));
// ImageDiskCache imageCache = ImageDiskCache.getInstance();
// //TODO figure out a way to replace local image files with the url
// String commentPicture = result.optString("picture");
// if (!TextUtils.isEmpty(commentPicture)) {
// String cachedPicture = update.getValue(Update.PICTURE);
// if (!TextUtils.isEmpty(cachedPicture) && imageCache.contains(cachedPicture)) {
// imageCache.move(update.getValue(Update.PICTURE), commentPicture);
// }
// update.setValue(Update.PICTURE, result.optString("picture"));
// }
//
// updateDao.saveExisting(update);
// } catch (IOException e) {
// if (notPermanentError(e))
// addFailedPush(new FailedPush(PUSH_TYPE_UPDATE, update.getId()));
// handleException("task-save", e);
// }
// }
private boolean notPermanentError(Exception e) {
return !(e instanceof ActFmServiceException);
@ -567,24 +565,24 @@ public final class ActFmSyncService {
pushTagDataOnSave(tagData, tagData.getMergedValues());
}
/**
* Synchronize complete update with server
* @param update id
*/
public void pushUpdate(long updateId) {
Update update = updateDao.fetch(updateId, Update.PROPERTIES);
if (update != null)
pushUpdateOnSave(update, update.getMergedValues(), null);
}
/**
* Push complete update with new image to server (used for new comments)
*/
public void pushUpdate(long updateId, Bitmap imageData) {
Update update = updateDao.fetch(updateId, Update.PROPERTIES);
pushUpdateOnSave(update, update.getMergedValues(), imageData);
}
// /**
// * Synchronize complete update with server
// * @param update id
// */
// public void pushUpdate(long updateId) {
// Update update = updateDao.fetch(updateId, Update.PROPERTIES);
// if (update != null)
// pushUpdateOnSave(update, update.getMergedValues(), null);
// }
//
// /**
// * Push complete update with new image to server (used for new comments)
// */
//
// public void pushUpdate(long updateId, Bitmap imageData) {
// Update update = updateDao.fetch(updateId, Update.PROPERTIES);
// pushUpdateOnSave(update, update.getMergedValues(), imageData);
// }
//----------------- Push ordering
public void pushTagOrderingOnSave(long tagDataId) {
@ -1273,53 +1271,53 @@ public final class ActFmSyncService {
// TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion));
// pushQueuedUpdates(cursor);
// }
private void pushQueuedUpdatesForTask(Task task) {
Criterion criterion = null;
if (task.containsNonNullValue(Task.UUID)) {
criterion = Criterion.and(Update.UUID.eq(0),
Criterion.or(Update.TASK_UUID.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId())));
} else
return;
Update template = new Update();
template.setValue(Update.TASK_UUID, task.getValue(Task.UUID)); //$NON-NLS-1$
updateDao.update(criterion, template);
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion));
pushQueuedUpdates(cursor);
}
private void pushAllQueuedUpdates() {
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(Update.UUID.eq(0)));
pushQueuedUpdates(cursor);
}
private void pushQueuedUpdates( TodorooCursor<Update> cursor) {
try {
final ImageDiskCache imageCache = ImageDiskCache.getInstance();
for(int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
final Update update = new Update(cursor);
new Thread(new Runnable() {
public void run() {
Bitmap picture = null;
if(imageCache != null && imageCache.contains(update.getValue(Update.PICTURE))) {
try {
picture = imageCache.get(update.getValue(Update.PICTURE));
} catch (IOException e) {
e.printStackTrace();
}
}
pushUpdate(update.getId(), picture);
}
}).start();
}
} finally {
cursor.close();
}
}
//
// private void pushQueuedUpdatesForTask(Task task) {
// Criterion criterion = null;
// if (task.containsNonNullValue(Task.UUID)) {
// criterion = Criterion.and(Update.UUID.eq(0),
// Criterion.or(Update.TASK_UUID.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId())));
// } else
// return;
//
// Update template = new Update();
// template.setValue(Update.TASK_UUID, task.getValue(Task.UUID)); //$NON-NLS-1$
// updateDao.update(criterion, template);
//
// TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion));
// pushQueuedUpdates(cursor);
// }
//
// private void pushAllQueuedUpdates() {
// TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(Update.UUID.eq(0)));
// pushQueuedUpdates(cursor);
// }
//
// private void pushQueuedUpdates( TodorooCursor<Update> cursor) {
//
// try {
// final ImageDiskCache imageCache = ImageDiskCache.getInstance();
// for(int i = 0; i < cursor.getCount(); i++) {
// cursor.moveToNext();
// final Update update = new Update(cursor);
// new Thread(new Runnable() {
// public void run() {
// Bitmap picture = null;
// if(imageCache != null && imageCache.contains(update.getValue(Update.PICTURE))) {
// try {
// picture = imageCache.get(update.getValue(Update.PICTURE));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// pushUpdate(update.getId(), picture);
// }
// }).start();
// }
// } finally {
// cursor.close();
// }
// }
// private class UpdateListItemProcessor extends ListItemProcessor<Update> {
// @Override

@ -27,7 +27,6 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
@ -46,7 +45,6 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
@ -60,12 +58,11 @@ import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
@ -88,7 +85,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
@Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired MetadataService metadataService;
@Autowired UpdateDao updateDao;
@Autowired UserActivityDao userActivityDao;
private final ArrayList<NoteOrUpdate> items = new ArrayList<NoteOrUpdate>();
private EditText commentField;
@ -286,16 +283,11 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
TodorooCursor<Update> updates;
if (!task.containsNonNullValue(Task.UUID)) {
updates = updateDao.query(Query.select(Update.PROPERTIES).where(Update.TASK_LOCAL.eq(task.getId())).orderBy(Order.desc(Update.CREATION_DATE)));
}
else {
updates = updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.or(
Update.TASK_UUID.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId()))).orderBy(Order.desc(Update.CREATION_DATE)));
}
TodorooCursor<UserActivity> updates = userActivityDao.query(Query.select(UserActivity.PROPERTIES)
.where(UserActivity.TARGET_ID.eq(task.getUuid()))
.orderBy(Order.desc(UserActivity.CREATED_AT)));
try {
Update update = new Update();
UserActivity update = new UserActivity();
for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
update.readFromCursor(updates);
NoteOrUpdate noa = NoteOrUpdate.fromUpdate(update, linkColor);
@ -439,39 +431,38 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
if (TextUtils.isEmpty(message) && usePicture) {
message = " ";
}
Update update = new Update();
update.setValue(Update.MESSAGE, message);
update.setValue(Update.ACTION_CODE, actionCode);
update.setValue(Update.USER_ID, Task.USER_ID_SELF);
if(task.containsNonNullValue(Task.UUID) && !RemoteModel.NO_UUID.equals(task.getValue(Task.UUID)))
update.setValue(Update.TASK_UUID, task.getValue(Task.UUID));
update.setValue(Update.TASK_LOCAL, task.getId());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, task.getValue(Task.TITLE));
if (usePicture && pendingCommentPicture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
try {
String updateString = ImageDiskCache.getPictureHash(update);
imageCache.put(updateString, pendingCommentPicture);
update.setValue(Update.PICTURE, updateString);
}
catch (Exception e) {
Log.e("EditNoteActivity", "Failed to put image to disk...");
}
}
update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = usePicture ? pendingCommentPicture : null;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
UserActivity userActivity = new UserActivity();
userActivity.setValue(UserActivity.MESSAGE, message);
userActivity.setValue(UserActivity.ACTION, actionCode);
userActivity.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
userActivity.setValue(UserActivity.TARGET_ID, task.getUuid());
userActivity.setValue(UserActivity.TARGET_NAME, task.getValue(Task.TITLE));
userActivity.setValue(UserActivity.CREATED_AT, DateUtilities.now());
// TODO: Fix picture uploading
// if (usePicture && pendingCommentPicture != null) {
// update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
// try {
// String updateString = ImageDiskCache.getPictureHash(update);
// imageCache.put(updateString, pendingCommentPicture);
// update.setValue(Update.PICTURE, updateString);
// }
// catch (Exception e) {
// Log.e("EditNoteActivity", "Failed to put image to disk...");
// }
// }
// update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
userActivityDao.createNew(userActivity);
//
// final long updateId = userActivity.getId();
// final Bitmap tempPicture = usePicture ? pendingCommentPicture : null;
// new Thread() {
// @Override
// public void run() {
// actFmSyncService.pushUpdate(updateId, tempPicture);
//
// }
// }.start();
commentField.setText(""); //$NON-NLS-1$
pendingCommentPicture = usePicture ? null : pendingCommentPicture;
@ -521,16 +512,16 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
@SuppressWarnings("nls")
public static NoteOrUpdate fromUpdate(Update u, String linkColor) {
public static NoteOrUpdate fromUpdate(UserActivity u, String linkColor) {
JSONObject user = ActFmPreferenceService.userFromModel(u);
String commentPicture = u.getPictureUrl(Update.PICTURE, RemoteModel.PICTURE_MEDIUM);
String commentPicture = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM);
Spanned title = UpdateAdapter.getUpdateComment(null, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW);
return new NoteOrUpdate(user.optString("picture"),
title,
commentPicture,
u.getValue(Update.CREATION_DATE));
u.getValue(UserActivity.CREATED_AT));
}
}

@ -45,7 +45,7 @@ import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache;
@ -130,7 +130,7 @@ public class UpdateAdapter extends CursorAdapter {
public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewGroup view = (ViewGroup)inflater.inflate(resource, parent, false);
view.setTag(new Update());
view.setTag(new UserActivity());
// populate view content
bindView(view, context, cursor);
@ -141,8 +141,8 @@ public class UpdateAdapter extends CursorAdapter {
/** Populates a view with content */
@Override
public void bindView(View view, Context context, Cursor c) {
TodorooCursor<Update> cursor = (TodorooCursor<Update>)c;
Update update = ((Update) view.getTag());
TodorooCursor<UserActivity> cursor = (TodorooCursor<UserActivity>)c;
UserActivity update = ((UserActivity) view.getTag());
update.clear();
update.readFromCursor(cursor);
@ -151,7 +151,7 @@ public class UpdateAdapter extends CursorAdapter {
/** Helper method to set the contents and visibility of each field */
@SuppressWarnings("nls")
public synchronized void setFieldContentsAndVisibility(View view, Update update) {
public synchronized void setFieldContentsAndVisibility(View view, UserActivity update) {
JSONObject user = ActFmPreferenceService.userFromModel(update);
// picture
@ -161,9 +161,9 @@ public class UpdateAdapter extends CursorAdapter {
}
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
final String updatePicture = update.getPictureUrl(Update.PICTURE, RemoteModel.PICTURE_THUMB);
final String updatePicture = update.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_THUMB);
setupImagePopupForCommentView(view, commentPictureView, updatePicture,
update.getValue(Update.MESSAGE), fragment, imageCache);
update.getValue(UserActivity.MESSAGE), fragment, imageCache);
}
// name
@ -175,7 +175,7 @@ public class UpdateAdapter extends CursorAdapter {
// date
final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(update.getValue(Update.CREATION_DATE),
CharSequence dateString = DateUtils.getRelativeTimeSpanString(update.getValue(UserActivity.CREATED_AT),
DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString);
@ -235,25 +235,25 @@ public class UpdateAdapter extends CursorAdapter {
}
@SuppressWarnings("nls")
public static Spanned getUpdateComment (final AstridActivity activity, Update update, JSONObject user, String linkColor, String fromView) {
public static Spanned getUpdateComment (final AstridActivity activity, UserActivity update, JSONObject user, String linkColor, String fromView) {
if (user == null)
user = ActFmPreferenceService.userFromModel(update);
JSONObject otherUser = null;
try {
otherUser = new JSONObject(update.getValue(Update.OTHER_USER));
otherUser = new JSONObject(update.getValue(UserActivity.OTHER_USER));
} catch (JSONException e) {
otherUser = new JSONObject();
}
return getUpdateComment(activity, update, update.getValue(Update.ACTION_CODE),
user.optString("name"), update.getValue(Update.TARGET_NAME),
update.getValue(Update.MESSAGE), otherUser.optString("name"),
update.getValue(Update.ACTION), linkColor, fromView);
return getUpdateComment(activity, update, update.getValue(UserActivity.ACTION),
user.optString("name"), update.getValue(UserActivity.TARGET_NAME),
update.getValue(UserActivity.MESSAGE), otherUser.optString("name"),
linkColor, fromView);
}
public static Spanned getUpdateComment (final AstridActivity activity, Update update, String actionCode, String user, String targetName,
String message, String otherUser, String action, String linkColor, String fromView) {
public static Spanned getUpdateComment (final AstridActivity activity, UserActivity update, String actionCode, String user, String targetName,
String message, String otherUser, String linkColor, String fromView) {
if (TextUtils.isEmpty(user)) {
user = ContextManager.getString(R.string.ENA_no_user);
}
@ -337,7 +337,7 @@ public class UpdateAdapter extends CursorAdapter {
String linkType = m.group(1);
CharSequence link = getLinkSpan(activity, update, actionCode, user,
targetName, message, otherUser, action, linkColor, linkType);
targetName, message, otherUser, linkColor, linkType);
if (link != null) {
builder.append(link);
if (!m.hitEnd()) {
@ -357,12 +357,12 @@ public class UpdateAdapter extends CursorAdapter {
return builder;
}
private static CharSequence getLinkSpan(final AstridActivity activity, Update update, String actionCode, String user, String targetName,
String message, String otherUser, String action, String linkColor, String linkType) {
private static CharSequence getLinkSpan(final AstridActivity activity, UserActivity update, String actionCode, String user, String targetName,
String message, String otherUser, String linkColor, String linkType) {
if (TASK_LINK_TYPE.equals(linkType)) {
long taskId = update.getValue(Update.TASK_LOCAL);
long taskId = update.getValue(UserActivity.TASK_LOCAL);
if (taskId <= 0) {
Task local = PluginServices.getTaskService().fetchByUUID(update.getValue(Update.TASK_UUID), Task.ID);
Task local = PluginServices.getTaskService().fetchByUUID(update.getValue(UserActivity.TASK_UUID), Task.ID);
if (local != null)
taskId = local.getId();
}

@ -22,7 +22,6 @@ import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.data.UserActivityOutstanding;
@ -132,34 +131,6 @@ public class Database extends AbstractDatabase {
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE INDEX IF NOT EXISTS up_tid ON ").
append(Update.TABLE).append('(').
append(Update.TASK_UUID.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE INDEX IF NOT EXISTS up_pid ON ").
append(Update.TABLE).append('(').
append(Update.TAGS.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE INDEX IF NOT EXISTS up_tkid ON ").
append(Update.TABLE).append('(').
append(Update.TASK_LOCAL.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE INDEX IF NOT EXISTS up_tgl ON ").
append(Update.TABLE).append('(').
append(Update.TAGS_LOCAL.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
sql.append("CREATE UNIQUE INDEX IF NOT EXISTS t_rid ON ").
append(Task.TABLE).append('(').
append(Task.UUID.name).

@ -37,7 +37,7 @@ import android.util.Log;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
/**
* <p>
@ -195,8 +195,8 @@ public class ImageDiskCache extends DiskCache<String, Bitmap> {
return !TextUtils.isEmpty(key) && key.startsWith(CACHED_IDENTIFIER) && super.contains(key);
}
public static String getPictureHash(Update update) {
return String.format("%s%s%s", CACHED_IDENTIFIER, update.getValue(Update.TASK_UUID), update.getValue(Update.CREATION_DATE));
public static String getPictureHash(UserActivity update) {
return String.format("%s%s%s", CACHED_IDENTIFIER, update.getValue(UserActivity.TARGET_ID), update.getValue(UserActivity.CREATED_AT));
}

@ -32,12 +32,12 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.service.AstridDependencyInjector;
/**
@ -103,7 +103,7 @@ public class Astrid3ContentProvider extends ContentProvider {
private StoreObjectDao storeObjectDao;
@Autowired
private UpdateDao updateDao;
private UserActivityDao userActivityDao;
@Autowired
private ExceptionService exceptionService;
@ -122,7 +122,7 @@ public class Astrid3ContentProvider extends ContentProvider {
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
for(Uri uri : new Uri[] { Task.CONTENT_URI, Metadata.CONTENT_URI, StoreObject.CONTENT_URI, Update.CONTENT_URI }) {
for(Uri uri : new Uri[] { Task.CONTENT_URI, Metadata.CONTENT_URI, StoreObject.CONTENT_URI, UserActivity.CONTENT_URI }) {
String authority = AstridApiConstants.API_PACKAGE;
String table = uri.toString();
@ -198,10 +198,10 @@ public class Astrid3ContentProvider extends ContentProvider {
helper.dao = storeObjectDao;
helper.dao.setDatabase(getDatabase());
return helper;
} else if(uri.toString().startsWith(Update.CONTENT_URI.toString())) {
UriHelper<Update> helper = new UriHelper<Update>();
helper.model = populateModel ? new Update() : null;
helper.dao = updateDao;
} else if(uri.toString().startsWith(UserActivity.CONTENT_URI.toString())) {
UriHelper<UserActivity> helper = new UriHelper<UserActivity>();
helper.model = populateModel ? new UserActivity() : null;
helper.dao = userActivityDao;
helper.dao.setDatabase(getDatabase());
return helper;
}

@ -16,10 +16,10 @@ import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.UserActivity;
/**
* Service layer for {@link TagData}-centered activities.
@ -31,7 +31,7 @@ public class TagDataService {
@Autowired TagDataDao tagDataDao;
@Autowired TaskDao taskDao;
@Autowired UpdateDao updateDao;
@Autowired UserActivityDao userActivityDao;
public TagDataService() {
DependencyInjectionService.getInstance().inject(this);
@ -136,24 +136,24 @@ public class TagDataService {
* Get updates for this tagData
* @return
*/
public TodorooCursor<Update> getUpdates(TagData tagData) {
public TodorooCursor<UserActivity> getUpdates(TagData tagData) {
return getUpdatesWithExtraCriteria(tagData, Criterion.all);
}
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdatesWithExtraCriteria(TagData tagData, Criterion criterion) {
public TodorooCursor<UserActivity> getUpdatesWithExtraCriteria(TagData tagData, Criterion criterion) {
if (tagData == null)
return updateDao.query(Query.select(Update.PROPERTIES).where(
return updateDao.query(Query.select(UserActivity.PROPERTIES).where(
criterion).
orderBy(Order.desc(Update.CREATION_DATE)));
orderBy(Order.desc(UserActivity.CREATED_AT)));
if(RemoteModel.NO_UUID.equals(tagData.getValue(TagData.UUID)))
return updateDao.query(Query.select(Update.PROPERTIES).where(Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")).orderBy(Order.desc(Update.CREATION_DATE)));
return updateDao.query(Query.select(UserActivity.PROPERTIES).where(Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")).orderBy(Order.desc(Update.CREATION_DATE)));
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.and(criterion,
return updateDao.query(Query.select(UserActivity.PROPERTIES).where(Criterion.and(criterion,
Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"),
Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))).
orderBy(Order.desc(Update.CREATION_DATE)));
orderBy(Order.desc(UserActivity.CREATED_AT)));
}
/**
@ -161,19 +161,19 @@ public class TagDataService {
* @param tagData
* @return
*/
public Update getLatestUpdate(TagData tagData) {
public UserActivity getLatestUpdate(TagData tagData) {
if(RemoteModel.NO_UUID.equals(tagData.getValue(TagData.UUID)))
return null;
@SuppressWarnings("nls")
TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%")).
TodorooCursor<UserActivity> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
UserActivity.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%")).
orderBy(Order.desc(Update.CREATION_DATE)).limit(1));
try {
if(updates.getCount() == 0)
return null;
updates.moveToFirst();
return new Update(updates);
return new UserActivity(updates);
} finally {
updates.close();
}

Loading…
Cancel
Save