|
|
|
@ -4,6 +4,7 @@ import greendroid.widget.AsyncImageView;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
@ -12,8 +13,11 @@ import android.content.DialogInterface;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
|
|
|
|
import android.text.Html;
|
|
|
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
@ -24,6 +28,7 @@ import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
|
|
@ -45,7 +50,23 @@ public class UpdateAdapter extends CursorAdapter {
|
|
|
|
private final int resource;
|
|
|
|
private final int resource;
|
|
|
|
private final LayoutInflater inflater;
|
|
|
|
private final LayoutInflater inflater;
|
|
|
|
private final ImageDiskCache imageCache;
|
|
|
|
private final ImageDiskCache imageCache;
|
|
|
|
|
|
|
|
private final String linkColor;
|
|
|
|
|
|
|
|
private final String fromView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String UPDATE_FRIENDS = "friends"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
private static final String UPDATE_REQUEST_FRIENDSHIP = "request_friendship"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
private static final String UPDATE_CONFIRMED_FRIENDSHIP = "confirmed_friendship"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_CREATED = "task_created";
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_COMPLETED = "task_completed";
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_UNCOMPLETED = "task_uncompleted";
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_TAGGED = "task_tagged";
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_ASSIGNED = "task_assigned";
|
|
|
|
|
|
|
|
private static final String UPDATE_TASK_COMMENT = "task_comment";
|
|
|
|
|
|
|
|
private static final String UPDATE_TAG_COMMENT = "tag_comment";
|
|
|
|
|
|
|
|
public static final String FROM_TAG_VIEW = "from_tag";
|
|
|
|
|
|
|
|
public static final String FROM_TASK_VIEW = "from_task";
|
|
|
|
|
|
|
|
public static final String FROM_RECENT_ACTIVITY_VIEW = "from_recent_activity";
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -61,16 +82,26 @@ public class UpdateAdapter extends CursorAdapter {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public UpdateAdapter(Fragment fragment, int resource,
|
|
|
|
public UpdateAdapter(Fragment fragment, int resource,
|
|
|
|
Cursor c, boolean autoRequery,
|
|
|
|
Cursor c, boolean autoRequery,
|
|
|
|
OnCompletedTaskListener onCompletedTaskListener) {
|
|
|
|
OnCompletedTaskListener onCompletedTaskListener, String fromView) {
|
|
|
|
super(fragment.getActivity(), c, autoRequery);
|
|
|
|
super(fragment.getActivity(), c, autoRequery);
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
linkColor = getLinkColor(fragment);
|
|
|
|
|
|
|
|
|
|
|
|
inflater = (LayoutInflater) fragment.getActivity().getSystemService(
|
|
|
|
inflater = (LayoutInflater) fragment.getActivity().getSystemService(
|
|
|
|
Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
imageCache = ImageDiskCache.getInstance();
|
|
|
|
imageCache = ImageDiskCache.getInstance();
|
|
|
|
|
|
|
|
this.fromView = fromView;
|
|
|
|
|
|
|
|
|
|
|
|
this.resource = resource;
|
|
|
|
this.resource = resource;
|
|
|
|
this.fragment = fragment;
|
|
|
|
this.fragment = fragment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getLinkColor(Fragment f) {
|
|
|
|
|
|
|
|
TypedValue colorType = new TypedValue();
|
|
|
|
|
|
|
|
f.getActivity().getTheme().resolveAttribute(R.attr.asDetailsColor, colorType, false);
|
|
|
|
|
|
|
|
return "#" + Integer.toHexString(colorType.data).substring(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
/* ======================================================================
|
|
|
|
@ -158,29 +189,9 @@ public class UpdateAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
// name
|
|
|
|
// name
|
|
|
|
final TextView nameView = (TextView)view.findViewById(R.id.title); {
|
|
|
|
final TextView nameView = (TextView)view.findViewById(R.id.title); {
|
|
|
|
String nameValue = user.optString("name");
|
|
|
|
nameView.setText(getUpdateComment(update, user, linkColor, fromView));
|
|
|
|
if(update.getValue(Update.ACTION_CODE).equals("task_comment"))
|
|
|
|
|
|
|
|
nameValue = r.getString(R.string.UAd_title_comment, nameValue,
|
|
|
|
|
|
|
|
update.getValue(Update.TARGET_NAME));
|
|
|
|
|
|
|
|
if(TextUtils.isEmpty(nameValue)){
|
|
|
|
|
|
|
|
nameView.setText(fragment.getActivity().getString(R.string.ENA_no_user));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
nameView.setText(nameValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// description
|
|
|
|
|
|
|
|
final TextView descriptionView = (TextView)view.findViewById(R.id.description); {
|
|
|
|
|
|
|
|
String description = update.getValue(Update.ACTION);
|
|
|
|
|
|
|
|
String message = update.getValue(Update.MESSAGE);
|
|
|
|
|
|
|
|
if(update.getValue(Update.ACTION_CODE).equals("task_comment") ||
|
|
|
|
|
|
|
|
update.getValue(Update.ACTION_CODE).equals("tag_comment"))
|
|
|
|
|
|
|
|
description = message;
|
|
|
|
|
|
|
|
else if(!TextUtils.isEmpty(message))
|
|
|
|
|
|
|
|
description += " " + message;
|
|
|
|
|
|
|
|
descriptionView.setText(description);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// date
|
|
|
|
// date
|
|
|
|
final TextView date = (TextView)view.findViewById(R.id.date); {
|
|
|
|
final TextView date = (TextView)view.findViewById(R.id.date); {
|
|
|
|
@ -192,4 +203,84 @@ public class UpdateAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String linkify (String string, String linkColor) {
|
|
|
|
|
|
|
|
return String.format("<font color=%s>%s</font>", linkColor, string); //$NON-NLS-1$
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Spanned getUpdateComment (Update update, JSONObject user, String linkColor, String fromView) {
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
user = ActFmPreferenceService.userFromModel(update);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject otherUser = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
otherUser = new JSONObject(update.getValue(Update.OTHER_USER));
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
otherUser = new JSONObject();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Spanned getUpdateComment (String actionCode, String user, String targetName, String message, String otherUser, String action, String linkColor, String fromView) {
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(user)) {
|
|
|
|
|
|
|
|
user = ContextManager.getString(R.string.ENA_no_user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String userLink = linkify(user, linkColor);
|
|
|
|
|
|
|
|
String targetNameLink = linkify(targetName, linkColor);
|
|
|
|
|
|
|
|
String otherUserLink = 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
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
commentResource = R.string.update_string_default_comment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
commentResource = R.string.update_string_tag_comment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (commentResource == 0) {
|
|
|
|
|
|
|
|
return Html.fromHtml(String.format("%s %s", userLink, action)); //$NON-NLS-1$
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Html.fromHtml(ContextManager.getString(commentResource, userLink, targetNameLink, message, otherUserLink));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|