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

@ -5,9 +5,6 @@
*/ */
package com.todoroo.astrid.data; 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. * 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> * @author Andrey Marchenko <igendou@gmail.com>
* *
*/ */
public class UpdateApiDao extends ContentResolverDao<Update>{ //public class UpdateApiDao extends ContentResolverDao<Update>{
//
public UpdateApiDao(Context context) { // public UpdateApiDao(Context context) {
super(Update.class, context, Update.CONTENT_URI); // 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.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table; import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
@SuppressWarnings("nls") @SuppressWarnings("nls")
@ -41,7 +42,7 @@ public class UserActivity extends RemoteModel {
/** User ID (activity initiator) */ /** User ID (activity initiator) */
public static final StringProperty USER_UUID = new StringProperty( public static final StringProperty USER_UUID = new StringProperty(
TABLE, "user_uuid"); TABLE, "user_uuid", Property.PROP_FLAG_USER_ID);
/** Action */ /** Action */
public static final StringProperty ACTION = new StringProperty( public static final StringProperty ACTION = new StringProperty(
@ -71,6 +72,25 @@ public class UserActivity extends RemoteModel {
public static final LongProperty DELETED_AT = new LongProperty( public static final LongProperty DELETED_AT = new LongProperty(
TABLE, "created_at", Property.PROP_FLAG_DATE); 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 // --- helpers

@ -3,7 +3,6 @@ package com.timsu.astrid;
import java.io.IOException; import java.io.IOException;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification; import android.app.Notification;
import android.app.PendingIntent; 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.SyncFlags;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.reminders.Notifications; import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
@ -358,28 +356,25 @@ public class GCMIntentService extends GCMBaseIntentService {
FilterWithCustomIntent filter = (FilterWithCustomIntent)TagFilterExposer.filterFromTagData(context, tagData); FilterWithCustomIntent filter = (FilterWithCustomIntent)TagFilterExposer.filterFromTagData(context, tagData);
//filter.customExtras.putString(TagViewActivity.EXTRA_START_TAB, "updates"); //filter.customExtras.putString(TagViewActivity.EXTRA_START_TAB, "updates");
if(intent.hasExtra("activity_id")) { if(intent.hasExtra("activity_id")) {
try { // try {
Update update = new Update(); // UserActivity update = new UserActivity();
update.setValue(Update.UUID, intent.getStringExtra("activity_id")); // update.setValue(UserActivity.UUID, intent.getStringExtra("activity_id"));
update.setValue(Update.USER_ID, intent.getStringExtra("user_id")); // update.setValue(UserActivity.USER_UUID, intent.getStringExtra("user_id"));
JSONObject user = new JSONObject(); //
user.put("id", update.getValue(Update.USER_ID)); // update.setValue(Update.ACTION_CODE, "tag_comment");
user.put("name", intent.getStringExtra("user_name")); // update.setValue(Update.TARGET_NAME, intent.getStringExtra("title"));
update.setValue(Update.ACTION, "commented"); // String message = intent.getStringExtra("alert");
update.setValue(Update.ACTION_CODE, "tag_comment"); // if(message.contains(":"))
update.setValue(Update.TARGET_NAME, intent.getStringExtra("title")); // message = message.substring(message.indexOf(':') + 2);
String message = intent.getStringExtra("alert"); // update.setValue(Update.MESSAGE, message);
if(message.contains(":")) // update.setValue(Update.CREATION_DATE, DateUtilities.now());
message = message.substring(message.indexOf(':') + 2); // update.setValue(Update.TAGS, "," + intent.getStringExtra("tag_id") + ",");
update.setValue(Update.MESSAGE, message); // updateDao.createNew(update);
update.setValue(Update.CREATION_DATE, DateUtilities.now()); // } catch (JSONException e) {
update.setValue(Update.TAGS, "," + intent.getStringExtra("tag_id") + ","); // //
updateDao.createNew(update); // } catch (NumberFormatException e) {
} catch (JSONException e) { // //
// // }
} catch (NumberFormatException e) {
//
}
} }
Intent launchIntent = new Intent(context, TaskListActivity.class); 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.support.v4.view.MenuItem;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater; 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.AstridActivity;
import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.adapter.UpdateAdapter; import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.ImageDiskCache; import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
@ -72,7 +70,7 @@ public abstract class CommentsFragment extends ListFragment {
@Autowired ActFmSyncService actFmSyncService; @Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService; @Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired UpdateDao updateDao; @Autowired UserActivityDao userActivityDao;
public CommentsFragment() { public CommentsFragment() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
@ -105,7 +103,7 @@ public abstract class CommentsFragment extends ListFragment {
protected abstract void populateListHeader(ViewGroup header); protected abstract void populateListHeader(ViewGroup header);
protected abstract Update createUpdate(); protected abstract UserActivity createUpdate();
protected abstract String commentAddStatistic(); protected abstract String commentAddStatistic();
@ -321,34 +319,35 @@ public abstract class CommentsFragment extends ListFragment {
} }
} }
private String getPictureHashForUpdate(Update u) { private String getPictureHashForUpdate(UserActivity u) {
String s = u.getValue(Update.TASK_UUID) + u.getValue(Update.CREATION_DATE); String s = u.getValue(UserActivity.TARGET_ID) + u.getValue(UserActivity.CREATED_AT);
return s; return s;
} }
protected void addComment() { protected void addComment() {
Update update = createUpdate(); UserActivity update = createUpdate();
if (picture != null) { // TODO: Fix picture uploading
update.setValue(Update.PICTURE, Update.PICTURE_LOADING); // if (picture != null) {
try { // update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
String updateString = getPictureHashForUpdate(update); // try {
imageCache.put(updateString, picture); // String updateString = getPictureHashForUpdate(update);
update.setValue(Update.PICTURE, updateString); // 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$ // 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); // update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
userActivityDao.createNew(update);
final long updateId = update.getId(); //
final Bitmap tempPicture = picture; // final long updateId = update.getId();
new Thread() { // final Bitmap tempPicture = picture;
@Override // new Thread() {
public void run() { // @Override
actFmSyncService.pushUpdate(updateId, tempPicture); // public void run() {
} // actFmSyncService.pushUpdate(updateId, tempPicture);
}.start(); // }
// }.start();
addCommentField.setText(""); //$NON-NLS-1$ addCommentField.setText(""); //$NON-NLS-1$
picture = null; picture = null;

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

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

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

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

@ -27,7 +27,6 @@ import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; 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.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; 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.adapter.UpdateAdapter;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; 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.Metadata;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task; 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.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache; import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
@ -88,7 +85,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
@Autowired ActFmSyncService actFmSyncService; @Autowired ActFmSyncService actFmSyncService;
@Autowired ActFmPreferenceService actFmPreferenceService; @Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired MetadataService metadataService; @Autowired MetadataService metadataService;
@Autowired UpdateDao updateDao; @Autowired UserActivityDao userActivityDao;
private final ArrayList<NoteOrUpdate> items = new ArrayList<NoteOrUpdate>(); private final ArrayList<NoteOrUpdate> items = new ArrayList<NoteOrUpdate>();
private EditText commentField; private EditText commentField;
@ -286,16 +283,11 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
} }
TodorooCursor<Update> updates; TodorooCursor<UserActivity> updates = userActivityDao.query(Query.select(UserActivity.PROPERTIES)
if (!task.containsNonNullValue(Task.UUID)) { .where(UserActivity.TARGET_ID.eq(task.getUuid()))
updates = updateDao.query(Query.select(Update.PROPERTIES).where(Update.TASK_LOCAL.eq(task.getId())).orderBy(Order.desc(Update.CREATION_DATE))); .orderBy(Order.desc(UserActivity.CREATED_AT)));
}
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)));
}
try { try {
Update update = new Update(); UserActivity update = new UserActivity();
for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) { for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
update.readFromCursor(updates); update.readFromCursor(updates);
NoteOrUpdate noa = NoteOrUpdate.fromUpdate(update, linkColor); NoteOrUpdate noa = NoteOrUpdate.fromUpdate(update, linkColor);
@ -439,39 +431,38 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
if (TextUtils.isEmpty(message) && usePicture) { if (TextUtils.isEmpty(message) && usePicture) {
message = " "; message = " ";
} }
Update update = new Update(); UserActivity userActivity = new UserActivity();
update.setValue(Update.MESSAGE, message); userActivity.setValue(UserActivity.MESSAGE, message);
update.setValue(Update.ACTION_CODE, actionCode); userActivity.setValue(UserActivity.ACTION, actionCode);
update.setValue(Update.USER_ID, Task.USER_ID_SELF); userActivity.setValue(UserActivity.USER_UUID, Task.USER_ID_SELF);
if(task.containsNonNullValue(Task.UUID) && !RemoteModel.NO_UUID.equals(task.getValue(Task.UUID))) userActivity.setValue(UserActivity.TARGET_ID, task.getUuid());
update.setValue(Update.TASK_UUID, task.getValue(Task.UUID)); userActivity.setValue(UserActivity.TARGET_NAME, task.getValue(Task.TITLE));
update.setValue(Update.TASK_LOCAL, task.getId()); userActivity.setValue(UserActivity.CREATED_AT, DateUtilities.now());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, task.getValue(Task.TITLE)); // TODO: Fix picture uploading
// if (usePicture && pendingCommentPicture != null) {
if (usePicture && pendingCommentPicture != null) { // update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
update.setValue(Update.PICTURE, Update.PICTURE_LOADING); // try {
try { // String updateString = ImageDiskCache.getPictureHash(update);
String updateString = ImageDiskCache.getPictureHash(update); // imageCache.put(updateString, pendingCommentPicture);
imageCache.put(updateString, pendingCommentPicture); // update.setValue(Update.PICTURE, updateString);
update.setValue(Update.PICTURE, updateString); // }
} // catch (Exception e) {
catch (Exception e) { // Log.e("EditNoteActivity", "Failed to put image to disk...");
Log.e("EditNoteActivity", "Failed to put image to disk..."); // }
} // }
} // update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
update.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); userActivityDao.createNew(userActivity);
updateDao.createNew(update); //
// final long updateId = userActivity.getId();
final long updateId = update.getId(); // final Bitmap tempPicture = usePicture ? pendingCommentPicture : null;
final Bitmap tempPicture = usePicture ? pendingCommentPicture : null; // new Thread() {
new Thread() { // @Override
@Override // public void run() {
public void run() { // actFmSyncService.pushUpdate(updateId, tempPicture);
actFmSyncService.pushUpdate(updateId, tempPicture); //
// }
} // }.start();
}.start();
commentField.setText(""); //$NON-NLS-1$ commentField.setText(""); //$NON-NLS-1$
pendingCommentPicture = usePicture ? null : pendingCommentPicture; pendingCommentPicture = usePicture ? null : pendingCommentPicture;
@ -521,16 +512,16 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static NoteOrUpdate fromUpdate(Update u, String linkColor) { public static NoteOrUpdate fromUpdate(UserActivity u, String linkColor) {
JSONObject user = ActFmPreferenceService.userFromModel(u); 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); Spanned title = UpdateAdapter.getUpdateComment(null, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW);
return new NoteOrUpdate(user.optString("picture"), return new NoteOrUpdate(user.optString("picture"),
title, title,
commentPicture, 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.core.PluginServices;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task; 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.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache; import com.todoroo.astrid.helper.ImageDiskCache;
@ -130,7 +130,7 @@ public class UpdateAdapter extends CursorAdapter {
public View newView(Context context, Cursor cursor, ViewGroup parent) { public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewGroup view = (ViewGroup)inflater.inflate(resource, parent, false); ViewGroup view = (ViewGroup)inflater.inflate(resource, parent, false);
view.setTag(new Update()); view.setTag(new UserActivity());
// populate view content // populate view content
bindView(view, context, cursor); bindView(view, context, cursor);
@ -141,8 +141,8 @@ public class UpdateAdapter extends CursorAdapter {
/** Populates a view with content */ /** Populates a view with content */
@Override @Override
public void bindView(View view, Context context, Cursor c) { public void bindView(View view, Context context, Cursor c) {
TodorooCursor<Update> cursor = (TodorooCursor<Update>)c; TodorooCursor<UserActivity> cursor = (TodorooCursor<UserActivity>)c;
Update update = ((Update) view.getTag()); UserActivity update = ((UserActivity) view.getTag());
update.clear(); update.clear();
update.readFromCursor(cursor); update.readFromCursor(cursor);
@ -151,7 +151,7 @@ public class UpdateAdapter extends CursorAdapter {
/** Helper method to set the contents and visibility of each field */ /** Helper method to set the contents and visibility of each field */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public synchronized void setFieldContentsAndVisibility(View view, Update update) { public synchronized void setFieldContentsAndVisibility(View view, UserActivity update) {
JSONObject user = ActFmPreferenceService.userFromModel(update); JSONObject user = ActFmPreferenceService.userFromModel(update);
// picture // picture
@ -161,9 +161,9 @@ public class UpdateAdapter extends CursorAdapter {
} }
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); { 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, setupImagePopupForCommentView(view, commentPictureView, updatePicture,
update.getValue(Update.MESSAGE), fragment, imageCache); update.getValue(UserActivity.MESSAGE), fragment, imageCache);
} }
// name // name
@ -175,7 +175,7 @@ public class UpdateAdapter extends CursorAdapter {
// date // date
final TextView date = (TextView)view.findViewById(R.id.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, DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE); DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString); date.setText(dateString);
@ -235,25 +235,25 @@ public class UpdateAdapter extends CursorAdapter {
} }
@SuppressWarnings("nls") @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) if (user == null)
user = ActFmPreferenceService.userFromModel(update); user = ActFmPreferenceService.userFromModel(update);
JSONObject otherUser = null; JSONObject otherUser = null;
try { try {
otherUser = new JSONObject(update.getValue(Update.OTHER_USER)); otherUser = new JSONObject(update.getValue(UserActivity.OTHER_USER));
} catch (JSONException e) { } catch (JSONException e) {
otherUser = new JSONObject(); otherUser = new JSONObject();
} }
return getUpdateComment(activity, update, update.getValue(Update.ACTION_CODE), return getUpdateComment(activity, update, update.getValue(UserActivity.ACTION),
user.optString("name"), update.getValue(Update.TARGET_NAME), user.optString("name"), update.getValue(UserActivity.TARGET_NAME),
update.getValue(Update.MESSAGE), otherUser.optString("name"), update.getValue(UserActivity.MESSAGE), otherUser.optString("name"),
update.getValue(Update.ACTION), linkColor, fromView); linkColor, fromView);
} }
public static Spanned getUpdateComment (final AstridActivity activity, Update update, String actionCode, String user, String targetName, public static Spanned getUpdateComment (final AstridActivity activity, UserActivity update, String actionCode, String user, String targetName,
String message, String otherUser, String action, String linkColor, String fromView) { String message, String otherUser, String linkColor, String fromView) {
if (TextUtils.isEmpty(user)) { if (TextUtils.isEmpty(user)) {
user = ContextManager.getString(R.string.ENA_no_user); user = ContextManager.getString(R.string.ENA_no_user);
} }
@ -337,7 +337,7 @@ public class UpdateAdapter extends CursorAdapter {
String linkType = m.group(1); String linkType = m.group(1);
CharSequence link = getLinkSpan(activity, update, actionCode, user, CharSequence link = getLinkSpan(activity, update, actionCode, user,
targetName, message, otherUser, action, linkColor, linkType); targetName, message, otherUser, linkColor, linkType);
if (link != null) { if (link != null) {
builder.append(link); builder.append(link);
if (!m.hitEnd()) { if (!m.hitEnd()) {
@ -357,12 +357,12 @@ public class UpdateAdapter extends CursorAdapter {
return builder; return builder;
} }
private static CharSequence getLinkSpan(final AstridActivity activity, Update update, String actionCode, String user, String targetName, private static CharSequence getLinkSpan(final AstridActivity activity, UserActivity update, String actionCode, String user, String targetName,
String message, String otherUser, String action, String linkColor, String linkType) { String message, String otherUser, String linkColor, String linkType) {
if (TASK_LINK_TYPE.equals(linkType)) { if (TASK_LINK_TYPE.equals(linkType)) {
long taskId = update.getValue(Update.TASK_LOCAL); long taskId = update.getValue(UserActivity.TASK_LOCAL);
if (taskId <= 0) { 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) if (local != null)
taskId = local.getId(); taskId = local.getId();
} }

@ -22,7 +22,6 @@ import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.TagOutstanding; import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.data.UserActivityOutstanding; import com.todoroo.astrid.data.UserActivityOutstanding;
@ -132,34 +131,6 @@ public class Database extends AbstractDatabase {
database.execSQL(sql.toString()); database.execSQL(sql.toString());
sql.setLength(0); 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 "). sql.append("CREATE UNIQUE INDEX IF NOT EXISTS t_rid ON ").
append(Task.TABLE).append('('). append(Task.TABLE).append('(').
append(Task.UUID.name). append(Task.UUID.name).

@ -37,7 +37,7 @@ import android.util.Log;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Update; import com.todoroo.astrid.data.UserActivity;
/** /**
* <p> * <p>
@ -195,8 +195,8 @@ public class ImageDiskCache extends DiskCache<String, Bitmap> {
return !TextUtils.isEmpty(key) && key.startsWith(CACHED_IDENTIFIER) && super.contains(key); return !TextUtils.isEmpty(key) && key.startsWith(CACHED_IDENTIFIER) && super.contains(key);
} }
public static String getPictureHash(Update update) { public static String getPictureHash(UserActivity update) {
return String.format("%s%s%s", CACHED_IDENTIFIER, update.getValue(Update.TASK_UUID), update.getValue(Update.CREATION_DATE)); 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.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TaskDao; 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.Metadata;
import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao; import com.todoroo.astrid.data.TaskApiDao;
import com.todoroo.astrid.data.Update; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
/** /**
@ -103,7 +103,7 @@ public class Astrid3ContentProvider extends ContentProvider {
private StoreObjectDao storeObjectDao; private StoreObjectDao storeObjectDao;
@Autowired @Autowired
private UpdateDao updateDao; private UserActivityDao userActivityDao;
@Autowired @Autowired
private ExceptionService exceptionService; private ExceptionService exceptionService;
@ -122,7 +122,7 @@ public class Astrid3ContentProvider extends ContentProvider {
static { static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 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 authority = AstridApiConstants.API_PACKAGE;
String table = uri.toString(); String table = uri.toString();
@ -198,10 +198,10 @@ public class Astrid3ContentProvider extends ContentProvider {
helper.dao = storeObjectDao; helper.dao = storeObjectDao;
helper.dao.setDatabase(getDatabase()); helper.dao.setDatabase(getDatabase());
return helper; return helper;
} else if(uri.toString().startsWith(Update.CONTENT_URI.toString())) { } else if(uri.toString().startsWith(UserActivity.CONTENT_URI.toString())) {
UriHelper<Update> helper = new UriHelper<Update>(); UriHelper<UserActivity> helper = new UriHelper<UserActivity>();
helper.model = populateModel ? new Update() : null; helper.model = populateModel ? new UserActivity() : null;
helper.dao = updateDao; helper.dao = userActivityDao;
helper.dao.setDatabase(getDatabase()); helper.dao.setDatabase(getDatabase());
return helper; return helper;
} }

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

Loading…
Cancel
Save