diff --git a/astrid/res/values/strings-updates.xml b/astrid/res/values/strings-updates.xml
index e60a3c2e9..1f52a0181 100644
--- a/astrid/res/values/strings-updates.xml
+++ b/astrid/res/values/strings-updates.xml
@@ -8,13 +8,13 @@
%1$s wants to be friends with you
%1$s has confirmed your friendship request
%1$s created this task
- %1$s created %2$s
- %1$s added %2$s to this list
- %1$s completed %2$s. Huzzah!
- %1$s un-completed %2$s.
- %1$s added %2$s to %4$s
- %1$s added %2$s to this list
- %1$s assigned %2$s to %4$s
+ %1$s created @task
+ %1$s added @task to this list
+ %1$s completed @task. Huzzah!
+ %1$s un-completed @task.
+ %1$s added @task to %4$s
+ %1$s added @task to this list
+ %1$s assigned @task to %4$s
%1$s commented: %3$s
%1$s Re: %2$s: %3$s
%1$s Re: %2$s: %3$s
diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java
index ccde95303..45eb4adce 100644
--- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java
+++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java
@@ -1,6 +1,7 @@
package com.todoroo.astrid.adapter;
import java.io.IOException;
+import java.util.regex.PatternSyntaxException;
import org.json.JSONException;
import org.json.JSONObject;
@@ -11,9 +12,13 @@ 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.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;
@@ -29,6 +34,8 @@ 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.core.PluginServices;
+import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache;
@@ -50,6 +57,7 @@ public class UpdateAdapter extends CursorAdapter {
private final String linkColor;
private final String fromView;
+ private static final String TASK_LINK_TOKEN = "@task"; //$NON-NLS-1$
private static final String UPDATE_FRIENDS = "friends"; //$NON-NLS-1$
private static final String UPDATE_REQUEST_FRIENDSHIP = "request_friendship"; //$NON-NLS-1$
@@ -151,6 +159,7 @@ public class UpdateAdapter extends CursorAdapter {
// name
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText(getUpdateComment(update, user, linkColor, fromView));
+ nameView.setMovementMethod(new LinkMovementMethod());
}
@@ -164,6 +173,11 @@ public class UpdateAdapter extends CursorAdapter {
}
+ @Override
+ public boolean isEnabled(int position) {
+ 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$
@@ -222,13 +236,20 @@ public class UpdateAdapter extends CursorAdapter {
otherUser = new JSONObject();
}
+ long taskId = update.getValue(Update.TASK_LOCAL);
+ if (taskId <= 0) {
+ Task local = PluginServices.getTaskService().fetchByRemoteId(update.getValue(Update.TASK), Task.ID);
+ if (local != null)
+ taskId = local.getId();
+ }
+
return getUpdateComment(update.getValue(Update.ACTION_CODE),
user.optString("name"), update.getValue(Update.TARGET_NAME),
update.getValue(Update.MESSAGE), otherUser.optString("name"),
- update.getValue(Update.ACTION), linkColor, fromView);
+ update.getValue(Update.ACTION), linkColor, fromView, taskId);
}
- public static Spanned getUpdateComment (String actionCode, String user, String targetName, String message, String otherUser, String action, String linkColor, String fromView) {
+ public static Spanned getUpdateComment (String actionCode, String user, String targetName, String message, String otherUser, String action, String linkColor, String fromView, final long taskId) {
if (TextUtils.isEmpty(user)) {
user = ContextManager.getString(R.string.ENA_no_user);
}
@@ -294,6 +315,52 @@ public class UpdateAdapter extends CursorAdapter {
return Html.fromHtml(String.format("%s %s", userLink, action)); //$NON-NLS-1$
}
- return Html.fromHtml(ContextManager.getString(commentResource, userLink, targetNameLink, message, otherUserLink));
+ String original = ContextManager.getString(commentResource, userLink, targetNameLink, message, otherUserLink);
+ int taskLinkIndex = original.indexOf(TASK_LINK_TOKEN);
+
+ if (taskLinkIndex < 0)
+ return Html.fromHtml(original);
+
+ if (taskId <= 0) {
+ original = original.replace(TASK_LINK_TOKEN, targetNameLink);
+ return Html.fromHtml(original);
+ }
+
+ try {
+ SpannableStringBuilder builder = new SpannableStringBuilder();
+ SpannableString taskSpan = new SpannableString(targetName);
+ taskSpan.setSpan(new ClickableSpan() {
+ @Override
+ public void onClick(View widget) {
+ System.err.println("Click " + taskId);
+ }
+ }, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+
+ String[] components = original.split(TASK_LINK_TOKEN);
+ if (components.length > 1) {
+ Spanned comp1 = Html.fromHtml(components[0]);
+ Spanned comp2 = Html.fromHtml(components[1]);
+
+ builder.append(comp1)
+ .append(taskSpan)
+ .append(' ')
+ .append(comp2);
+ } else if (original.endsWith(TASK_LINK_TOKEN)) {
+ Spanned startComp = Html.fromHtml(components[0]);
+ builder.append(startComp)
+ .append(taskSpan);
+ } else {
+ Spanned endComp = Html.fromHtml(components[0]);
+ builder.append(taskSpan)
+ .append(' ')
+ .append(endComp);
+
+ }
+
+ return builder;
+ } catch (PatternSyntaxException e) {
+ original = original.replace(TASK_LINK_TOKEN, targetNameLink);
+ return Html.fromHtml(original);
+ }
}
}
diff --git a/astrid/src/com/todoroo/astrid/service/TaskService.java b/astrid/src/com/todoroo/astrid/service/TaskService.java
index ae00dedc9..e44a72e37 100644
--- a/astrid/src/com/todoroo/astrid/service/TaskService.java
+++ b/astrid/src/com/todoroo/astrid/service/TaskService.java
@@ -88,6 +88,25 @@ public class TaskService {
return taskDao.fetch(id, properties);
}
+ /**
+ *
+ * @param remoteId
+ * @param properties
+ * @return item, or null if it doesn't exist
+ */
+ public Task fetchByRemoteId(long remoteId, Property>... properties) {
+ TodorooCursor task = query(Query.select(properties).where(Task.REMOTE_ID.eq(remoteId)));
+ try {
+ if (task.getCount() > 0) {
+ task.moveToFirst();
+ return new Task(task);
+ }
+ return null;
+ } finally {
+ task.close();
+ }
+ }
+
/**
* Mark the given task as completed and save it.
*