Removed several more references to Update model

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

@ -5,6 +5,17 @@
*/
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;
/**
@ -13,162 +24,162 @@ package com.todoroo.astrid.data;
* @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;
}
}

@ -36,7 +36,6 @@ import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
@ -93,9 +92,6 @@ public class GCMIntentService extends GCMBaseIntentService {
@Autowired
private TagDataService tagDataService;
@Autowired
private UpdateDao updateDao;
public GCMIntentService() {
super();
DependencyInjectionService.getInstance().inject(this);

@ -53,7 +53,6 @@ import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.MetadataApiDao.MetadataCriteria;
@ -94,7 +93,6 @@ public final class ActFmSyncService {
@Autowired ActFmDataService actFmDataService;
@Autowired TaskDao taskDao;
@Autowired TagDataDao tagDataDao;
@Autowired UpdateDao updateDao;
@Autowired UserDao userDao;
@Autowired MetadataDao metadataDao;
@Autowired ABTestEventReportingService abTestEventReportingService;

@ -380,7 +380,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
// picture
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.commentPicture, item.title.toString(), fragment, imageCache);
// UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.commentPicture, item.title.toString(), fragment, imageCache);
}
}
@ -517,7 +517,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
String commentPicture = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM);
Spanned title = UpdateAdapter.getUpdateComment(null, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW);
Spanned title = null; //UpdateAdapter.getUpdateComment(null, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW);
return new NoteOrUpdate(user.optString("picture"),
title,
commentPicture,

@ -5,48 +5,21 @@
*/
package com.todoroo.astrid.adapter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.CursorAdapter;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
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.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache;
/**
@ -150,36 +123,35 @@ public class UpdateAdapter extends CursorAdapter {
}
/** Helper method to set the contents and visibility of each field */
@SuppressWarnings("nls")
public synchronized void setFieldContentsAndVisibility(View view, UserActivity update) {
JSONObject user = ActFmPreferenceService.userFromModel(update);
// picture
final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture); {
String pictureUrl = user.optString("picture");
pictureView.setUrl(pictureUrl);
}
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
final String updatePicture = update.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_THUMB);
setupImagePopupForCommentView(view, commentPictureView, updatePicture,
update.getValue(UserActivity.MESSAGE), fragment, imageCache);
}
// name
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText(getUpdateComment((AstridActivity)fragment.getActivity(), update, user, linkColor, fromView));
nameView.setMovementMethod(new LinkMovementMethod());
}
// date
final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(update.getValue(UserActivity.CREATED_AT),
DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString);
}
// JSONObject user = ActFmPreferenceService.userFromModel(update);
//
// // picture
// final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture); {
// String pictureUrl = user.optString("picture");
// pictureView.setUrl(pictureUrl);
// }
//
// final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
// final String updatePicture = update.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_THUMB);
// setupImagePopupForCommentView(view, commentPictureView, updatePicture,
// update.getValue(UserActivity.MESSAGE), fragment, imageCache);
// }
//
// // name
// final TextView nameView = (TextView)view.findViewById(R.id.title); {
// nameView.setText(getUpdateComment((AstridActivity)fragment.getActivity(), update, user, linkColor, fromView));
// nameView.setMovementMethod(new LinkMovementMethod());
// }
//
//
// // date
// final TextView date = (TextView)view.findViewById(R.id.date); {
// CharSequence dateString = DateUtils.getRelativeTimeSpanString(update.getValue(UserActivity.CREATED_AT),
// DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS,
// DateUtils.FORMAT_ABBREV_RELATIVE);
// date.setText(dateString);
// }
}
@ -188,207 +160,207 @@ public class UpdateAdapter extends CursorAdapter {
return false;
}
public static void setupImagePopupForCommentView(View view, AsyncImageView commentPictureView, final String updatePicture,
final String message, final Fragment fragment, ImageDiskCache imageCache) {
if (!TextUtils.isEmpty(updatePicture) && !"null".equals(updatePicture)) { //$NON-NLS-1$
commentPictureView.setVisibility(View.VISIBLE);
commentPictureView.setUrl(updatePicture);
if(imageCache.contains(updatePicture)) {
try {
commentPictureView.setDefaultImageBitmap(imageCache.get(updatePicture));
} catch (IOException e) {
e.printStackTrace();
}
}
else {
commentPictureView.setUrl(updatePicture);
}
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create();
AsyncImageView imageView = new AsyncImageView(fragment.getActivity());
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
imageView.setDefaultImageResource(android.R.drawable.ic_menu_gallery);
imageView.setUrl(updatePicture);
image.setView(imageView);
image.setMessage(message);
image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
image.show();
}
});
} else {
commentPictureView.setVisibility(View.GONE);
}
}
public static String linkify (String string, String linkColor) {
return String.format("<font color=%s>%s</font>", linkColor, string); //$NON-NLS-1$
}
@SuppressWarnings("nls")
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(UserActivity.OTHER_USER));
} catch (JSONException e) {
otherUser = new JSONObject();
}
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, 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);
}
String userLink = user; //linkify(user, linkColor);
String targetNameLink = targetName; //linkify(targetName, linkColor);
String otherUserLink = otherUser; //linkify(otherUser, linkColor);
int commentResource = 0;
if (actionCode.equals(UPDATE_FRIENDS)) {
commentResource = R.string.update_string_friends;
}
else if (actionCode.equals(UPDATE_REQUEST_FRIENDSHIP)) {
commentResource = R.string.update_string_request_friendship;
}
else if (actionCode.equals(UPDATE_CONFIRMED_FRIENDSHIP)) {
commentResource = R.string.update_string_confirmed_friendship;
}
else if (actionCode.equals(UPDATE_TASK_CREATED)) {
if (fromView.equals(FROM_TAG_VIEW))
commentResource = R.string.update_string_task_created_on_list;
else if (fromView.equals(FROM_RECENT_ACTIVITY_VIEW))
commentResource = R.string.update_string_task_created_global;
else
commentResource = R.string.update_string_task_created;
}
else if (actionCode.equals(UPDATE_TASK_COMPLETED)) {
commentResource = R.string.update_string_task_completed;
}
else if (actionCode.equals(UPDATE_TASK_UNCOMPLETED)) {
commentResource = R.string.update_string_task_uncompleted;
}
else if (actionCode.equals(UPDATE_TASK_TAGGED) && !TextUtils.isEmpty(otherUser)) {
if (fromView.equals(FROM_TAG_VIEW))
commentResource = R.string.update_string_task_tagged_list;
else
commentResource = R.string.update_string_task_tagged;
}
else if (actionCode.equals(UPDATE_TASK_ASSIGNED) && !TextUtils.isEmpty(otherUser)) {
commentResource = R.string.update_string_task_assigned;
}
else if (actionCode.equals(UPDATE_TASK_COMMENT)) {
if (fromView.equals(FROM_TASK_VIEW) || TextUtils.isEmpty(targetName))
commentResource = R.string.update_string_default_comment;
else
commentResource = R.string.update_string_task_comment;
}
else if (actionCode.equals(UPDATE_TAG_COMMENT)) {
if (fromView.equals(FROM_TAG_VIEW) || TextUtils.isEmpty(targetName))
commentResource = R.string.update_string_default_comment;
else
commentResource = R.string.update_string_tag_comment;
}
else if (actionCode.equals(UPDATE_TAG_CREATED)) {
if (fromView.equals(FROM_RECENT_ACTIVITY_VIEW))
commentResource = R.string.update_string_tag_created_global;
else
commentResource = R.string.update_string_tag_created;
}
if (commentResource == 0) {
return Html.fromHtml(String.format("%s %s", userLink, action)); //$NON-NLS-1$
}
String original = ContextManager.getString(commentResource, userLink, targetNameLink, message, otherUserLink);
int taskLinkIndex = original.indexOf(TARGET_LINK_PREFIX);
if (taskLinkIndex < 0)
return Html.fromHtml(original);
String[] components = original.split(" "); //$NON-NLS-1$
SpannableStringBuilder builder = new SpannableStringBuilder();
StringBuilder htmlStringBuilder = new StringBuilder();
for (String comp : components) {
Matcher m = TARGET_LINK_PATTERN.matcher(comp);
if (m.find()) {
builder.append(Html.fromHtml(htmlStringBuilder.toString()));
htmlStringBuilder.setLength(0);
String linkType = m.group(1);
CharSequence link = getLinkSpan(activity, update, actionCode, user,
targetName, message, otherUser, linkColor, linkType);
if (link != null) {
builder.append(link);
if (!m.hitEnd()) {
builder.append(comp.substring(m.end()));
}
builder.append(' ');
}
} else {
htmlStringBuilder.append(comp);
htmlStringBuilder.append(' ');
}
}
if (htmlStringBuilder.length() > 0)
builder.append(Html.fromHtml(htmlStringBuilder.toString()));
return builder;
}
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(UserActivity.TASK_LOCAL);
if (taskId <= 0) {
Task local = PluginServices.getTaskService().fetchByUUID(update.getValue(UserActivity.TASK_UUID), Task.ID);
if (local != null)
taskId = local.getId();
}
final long taskIdToUse = taskId;
if (taskId > 0) {
SpannableString taskSpan = new SpannableString(targetName);
taskSpan.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
if (activity != null) // TODO: This shouldn't happen, but sometimes does
activity.onTaskListItemClicked(taskIdToUse);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return taskSpan;
} else {
return Html.fromHtml(linkify(targetName, linkColor));
}
}
return null;
}
// public static void setupImagePopupForCommentView(View view, AsyncImageView commentPictureView, final String updatePicture,
// final String message, final Fragment fragment, ImageDiskCache imageCache) {
// if (!TextUtils.isEmpty(updatePicture) && !"null".equals(updatePicture)) { //$NON-NLS-1$
// commentPictureView.setVisibility(View.VISIBLE);
// commentPictureView.setUrl(updatePicture);
//
// if(imageCache.contains(updatePicture)) {
// try {
// commentPictureView.setDefaultImageBitmap(imageCache.get(updatePicture));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// else {
// commentPictureView.setUrl(updatePicture);
// }
//
// view.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create();
// AsyncImageView imageView = new AsyncImageView(fragment.getActivity());
// imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// imageView.setDefaultImageResource(android.R.drawable.ic_menu_gallery);
// imageView.setUrl(updatePicture);
// image.setView(imageView);
//
// image.setMessage(message);
// image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// return;
// }
// });
// image.show();
// }
// });
// } else {
// commentPictureView.setVisibility(View.GONE);
// }
// }
//
// public static String linkify (String string, String linkColor) {
// return String.format("<font color=%s>%s</font>", linkColor, string); //$NON-NLS-1$
// }
//
// @SuppressWarnings("nls")
// 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(UserActivity.OTHER_USER));
// } catch (JSONException e) {
// otherUser = new JSONObject();
// }
//
// 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, 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);
// }
//
// String userLink = user; //linkify(user, linkColor);
// String targetNameLink = targetName; //linkify(targetName, linkColor);
// String otherUserLink = otherUser; //linkify(otherUser, linkColor);
//
// int commentResource = 0;
// if (actionCode.equals(UPDATE_FRIENDS)) {
// commentResource = R.string.update_string_friends;
// }
// else if (actionCode.equals(UPDATE_REQUEST_FRIENDSHIP)) {
// commentResource = R.string.update_string_request_friendship;
// }
// else if (actionCode.equals(UPDATE_CONFIRMED_FRIENDSHIP)) {
// commentResource = R.string.update_string_confirmed_friendship;
// }
// else if (actionCode.equals(UPDATE_TASK_CREATED)) {
// if (fromView.equals(FROM_TAG_VIEW))
// commentResource = R.string.update_string_task_created_on_list;
// else if (fromView.equals(FROM_RECENT_ACTIVITY_VIEW))
// commentResource = R.string.update_string_task_created_global;
// else
// commentResource = R.string.update_string_task_created;
// }
// else if (actionCode.equals(UPDATE_TASK_COMPLETED)) {
// commentResource = R.string.update_string_task_completed;
// }
// else if (actionCode.equals(UPDATE_TASK_UNCOMPLETED)) {
// commentResource = R.string.update_string_task_uncompleted;
// }
// else if (actionCode.equals(UPDATE_TASK_TAGGED) && !TextUtils.isEmpty(otherUser)) {
// if (fromView.equals(FROM_TAG_VIEW))
// commentResource = R.string.update_string_task_tagged_list;
// else
// commentResource = R.string.update_string_task_tagged;
// }
// else if (actionCode.equals(UPDATE_TASK_ASSIGNED) && !TextUtils.isEmpty(otherUser)) {
// commentResource = R.string.update_string_task_assigned;
// }
// else if (actionCode.equals(UPDATE_TASK_COMMENT)) {
// if (fromView.equals(FROM_TASK_VIEW) || TextUtils.isEmpty(targetName))
// commentResource = R.string.update_string_default_comment;
// else
// commentResource = R.string.update_string_task_comment;
// }
// else if (actionCode.equals(UPDATE_TAG_COMMENT)) {
// if (fromView.equals(FROM_TAG_VIEW) || TextUtils.isEmpty(targetName))
// commentResource = R.string.update_string_default_comment;
// else
// commentResource = R.string.update_string_tag_comment;
//
// }
// else if (actionCode.equals(UPDATE_TAG_CREATED)) {
// if (fromView.equals(FROM_RECENT_ACTIVITY_VIEW))
// commentResource = R.string.update_string_tag_created_global;
// else
// commentResource = R.string.update_string_tag_created;
// }
//
// if (commentResource == 0) {
// return Html.fromHtml(String.format("%s %s", userLink, action)); //$NON-NLS-1$
// }
//
// String original = ContextManager.getString(commentResource, userLink, targetNameLink, message, otherUserLink);
// int taskLinkIndex = original.indexOf(TARGET_LINK_PREFIX);
//
// if (taskLinkIndex < 0)
// return Html.fromHtml(original);
//
// String[] components = original.split(" "); //$NON-NLS-1$
// SpannableStringBuilder builder = new SpannableStringBuilder();
// StringBuilder htmlStringBuilder = new StringBuilder();
//
// for (String comp : components) {
// Matcher m = TARGET_LINK_PATTERN.matcher(comp);
// if (m.find()) {
// builder.append(Html.fromHtml(htmlStringBuilder.toString()));
// htmlStringBuilder.setLength(0);
//
// String linkType = m.group(1);
// CharSequence link = getLinkSpan(activity, update, actionCode, user,
// targetName, message, otherUser, linkColor, linkType);
// if (link != null) {
// builder.append(link);
// if (!m.hitEnd()) {
// builder.append(comp.substring(m.end()));
// }
// builder.append(' ');
// }
// } else {
// htmlStringBuilder.append(comp);
// htmlStringBuilder.append(' ');
// }
// }
//
// if (htmlStringBuilder.length() > 0)
// builder.append(Html.fromHtml(htmlStringBuilder.toString()));
//
// return builder;
// }
//
// 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(UserActivity.TASK_LOCAL);
// if (taskId <= 0) {
// Task local = PluginServices.getTaskService().fetchByUUID(update.getValue(UserActivity.TASK_UUID), Task.ID);
// if (local != null)
// taskId = local.getId();
// }
//
// final long taskIdToUse = taskId;
//
// if (taskId > 0) {
// SpannableString taskSpan = new SpannableString(targetName);
// taskSpan.setSpan(new ClickableSpan() {
// @Override
// public void onClick(View widget) {
// if (activity != null) // TODO: This shouldn't happen, but sometimes does
// activity.onTaskListItemClicked(taskIdToUse);
// }
//
// @Override
// public void updateDrawState(TextPaint ds) {
// super.updateDrawState(ds);
// ds.setUnderlineText(false);
// }
// }, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
// return taskSpan;
// } else {
// return Html.fromHtml(linkify(targetName, linkColor));
// }
// }
// return null;
// }
}

@ -22,6 +22,7 @@ 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;

@ -9,12 +9,14 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.data.Update;
/**
* Data Access layer for {@link Update}-related operations.
*
* @author Tim Su <tim@todoroo.com>
*
*/
@Deprecated
public class UpdateDao extends RemoteModelDao<Update> {
@Autowired Database database;

@ -14,12 +14,15 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.tags.TaskToTagMetadata;
/**
* Service layer for {@link TagData}-centered activities.
@ -140,20 +143,21 @@ public class TagDataService {
return getUpdatesWithExtraCriteria(tagData, Criterion.all);
}
@SuppressWarnings("nls")
private static Query queryForTagData(TagData tagData) {
return Query.select(UserActivity.PROPERTIES).where(Criterion.or(
Criterion.and(UserActivity.ACTION.eq(UserActivity.ACTION_TAG_COMMENT), UserActivity.TARGET_ID.eq(tagData.getUuid())),
Criterion.and(UserActivity.ACTION.eq(UserActivity.ACTION_TASK_COMMENT),
UserActivity.TARGET_ID.in(Query.select(TaskToTagMetadata.TASK_UUID)
.from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(tagData.getUuid())))))));
}
public TodorooCursor<UserActivity> getUpdatesWithExtraCriteria(TagData tagData, Criterion criterion) {
if (tagData == null)
return updateDao.query(Query.select(UserActivity.PROPERTIES).where(
return userActivityDao.query(Query.select(UserActivity.PROPERTIES).where(
criterion).
orderBy(Order.desc(UserActivity.CREATED_AT)));
if(RemoteModel.NO_UUID.equals(tagData.getValue(TagData.UUID)))
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(UserActivity.PROPERTIES).where(Criterion.and(criterion,
Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"),
Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))).
orderBy(Order.desc(UserActivity.CREATED_AT)));
return userActivityDao.query(queryForTagData(tagData).orderBy(Order.desc(UserActivity.CREATED_AT)));
}
/**
@ -165,10 +169,7 @@ public class TagDataService {
if(RemoteModel.NO_UUID.equals(tagData.getValue(TagData.UUID)))
return null;
@SuppressWarnings("nls")
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));
TodorooCursor<UserActivity> updates = userActivityDao.query(queryForTagData(tagData).orderBy(Order.desc(UserActivity.CREATED_AT)).limit(1));
try {
if(updates.getCount() == 0)
return null;

Loading…
Cancel
Save