diff --git a/api/src/com/todoroo/astrid/data/RemoteModel.java b/api/src/com/todoroo/astrid/data/RemoteModel.java index fc81feaf3..62e403aeb 100644 --- a/api/src/com/todoroo/astrid/data/RemoteModel.java +++ b/api/src/com/todoroo/astrid/data/RemoteModel.java @@ -5,6 +5,9 @@ */ package com.todoroo.astrid.data; +import org.json.JSONException; +import org.json.JSONObject; + import android.text.TextUtils; import com.todoroo.andlib.data.AbstractModel; @@ -71,4 +74,18 @@ abstract public class RemoteModel extends AbstractModel { public static boolean isUuidEmpty(String uuid) { return NO_UUID.equals(uuid) || TextUtils.isEmpty(uuid); } + + public static final String PICTURE_THUMB = "thumb"; //$NON-NLS-1$ + public static final String PICTURE_MEDIUM = "medium"; //$NON-NLS-1$ + public static final String PICTURE_LARGE = "large"; //$NON-NLS-1$ + + public String getPictureUrl(StringProperty pictureProperty, String size) { + String value = getValue(pictureProperty); + try { + JSONObject pictureJson = new JSONObject(value); + return pictureJson.optString(size); + } catch (JSONException e) { + return value; + } + } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java index 0586b63ae..e831cfac2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagCommentsFragment.java @@ -20,6 +20,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.adapter.UpdateAdapter; +import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; @@ -104,7 +105,7 @@ public class TagCommentsFragment extends CommentsFragment { AsyncImageView imageView = (AsyncImageView) header.findViewById(R.id.tag_picture); imageView.setDefaultImageResource(TagService.getDefaultImageIDForTag(tagName)); - imageView.setUrl(tagData.getValue(TagData.PICTURE)); + imageView.setUrl(tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_MEDIUM)); } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java index cdf0c112c..efc14a7ca 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagSettingsActivity.java @@ -417,7 +417,7 @@ public class TagSettingsActivity extends FragmentActivity { setTitle(getString(R.string.tag_settings_title)); } } - picture.setUrl(tagData.getValue(TagData.PICTURE)); + picture.setUrl(tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_MEDIUM)); if (!isNewTag) { ImageView shortcut = (ImageView) findViewById(R.id.create_shortcut); shortcut.setImageBitmap(FilterListFragment.superImposeListIcon(this, picture.getImageBitmap(), tagData.getValue(TagData.NAME))); @@ -452,7 +452,7 @@ public class TagSettingsActivity extends FragmentActivity { try { String url = actFmSyncService.setTagPicture(tagData.getValue(TagData.UUID), bitmap); if (TextUtils.isEmpty(url)) return; - if (imageCache.contains(tagData.getValue(TagData.PICTURE))) { + if (imageCache.contains(tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_MEDIUM))) { imageCache.move(tagData.getValue(TagData.PICTURE), url); } tagData.setValue(TagData.PICTURE, url); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index f81bf2cbd..c415ffe1d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -1694,19 +1694,11 @@ public final class ActFmSyncService { return item.optLong(key, 0) * 1000L; } - public static void userFromJson(JSONObject json, User model) throws JSONException { - model.setValue(User.REMOTE_ID, json.getLong("id")); - model.setValue(User.NAME, json.optString("name")); - model.setValue(User.EMAIL, json.optString("email")); - model.setValue(User.PICTURE, json.optString("picture")); - model.setValue(User.STATUS, json.optString("status")); - } - public static void jsonFromUser(JSONObject json, User model) throws JSONException { json.put("id", model.getValue(User.UUID)); json.put("name", model.getDisplayName()); json.put("email", model.getValue(User.EMAIL)); - json.put("picture", model.getValue(User.PICTURE)); + json.put("picture", model.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_MEDIUM)); } public static void updateFromJson(JSONObject json, Update model) throws JSONException { diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index 56b418e32..da591d62c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -522,7 +522,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene public static NoteOrUpdate fromUpdate(Update u, String linkColor) { JSONObject user = ActFmPreferenceService.userFromModel(u); - String commentPicture = u.getValue(Update.PICTURE); + String commentPicture = u.getPictureUrl(Update.PICTURE, RemoteModel.PICTURE_MEDIUM); Spanned title = UpdateAdapter.getUpdateComment(null, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW); return new NoteOrUpdate(user.optString("picture"), diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java index 545ef6ade..48ba889f1 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterExposer.java @@ -35,6 +35,7 @@ import com.todoroo.astrid.api.FilterWithUpdate; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; +import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.User; @@ -102,7 +103,7 @@ public class PeopleFilterExposer extends BroadcastReceiver { values.put(Task.USER_ID.name, user.getValue(User.UUID)); filter.valuesForNewTasks = values; - String imageUrl = user.getValue(User.PICTURE); + String imageUrl = user.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_THUMB); //user.getValue(User.PICTURE); filter.imageUrl = imageUrl; Bundle extras = new Bundle(); diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java index fb94e14c8..ad4ccd983 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java @@ -23,6 +23,7 @@ import com.todoroo.astrid.actfm.sync.ActFmSyncThread; import com.todoroo.astrid.actfm.sync.messages.BriefMe; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.dao.UserDao; +import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.User; import com.todoroo.astrid.helper.AsyncImageView; import com.todoroo.astrid.service.SyncV2Service; @@ -68,7 +69,7 @@ public class PersonViewFragment extends TaskListFragment { private void setupUserHeader() { if (user != null) { userImage.setDefaultImageResource(R.drawable.icn_default_person_image); - userImage.setUrl(user.getValue(User.PICTURE)); + userImage.setUrl(user.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_MEDIUM)); userSubtitle.setText(getUserSubtitleText()); setupUserStatusButton(); } else { diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java index a0272e90e..3797ea1fb 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java @@ -134,7 +134,7 @@ public final class TagService { count = tagData.getValue(TagData.TASK_COUNT); remoteId = tagData.getValue(TagData.REMOTE_ID); uuid = tagData.getValue(TagData.UUID); - image = tagData.getValue(TagData.PICTURE); + image = tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_THUMB); userId = tagData.getValue(TagData.USER_ID); memberCount = tagData.getValue(TagData.MEMBER_COUNT); } diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java index ceadad15b..0cea85be0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedTaskListFragment.java @@ -23,6 +23,7 @@ import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; +import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.helper.AsyncImageView; @@ -89,7 +90,7 @@ public class FeaturedTaskListFragment extends TagViewFragment { protected void setUpMembersGallery() { // Repurposed this method to set up the description view AsyncImageView imageView = (AsyncImageView) getView().findViewById(R.id.url_image); - String imageUrl = tagData.getValue(TagData.PICTURE); + String imageUrl = tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_MEDIUM); if (!TextUtils.isEmpty(imageUrl)) { imageView.setVisibility(View.VISIBLE); imageView.setDefaultImageResource(R.drawable.default_list_0); diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java index a505cde81..c60b39370 100644 --- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java @@ -43,6 +43,7 @@ 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.Update; import com.todoroo.astrid.helper.AsyncImageView; @@ -160,7 +161,7 @@ public class UpdateAdapter extends CursorAdapter { } final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); { - final String updatePicture = update.getValue(Update.PICTURE); + final String updatePicture = update.getPictureUrl(Update.PICTURE, RemoteModel.PICTURE_THUMB); setupImagePopupForCommentView(view, commentPictureView, updatePicture, update.getValue(Update.MESSAGE), fragment, imageCache); }