Remove getPictureUrl

pull/189/head
Alex Baker 12 years ago
parent 6e00422d81
commit 1e47a6dfa5

@ -26,8 +26,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import static org.tasks.date.DateTimeUtils.currentTimeMillis;
/** /**
* A model that is synchronized to a remote server and has a remote id * A model that is synchronized to a remote server and has a remote id
* *
@ -92,14 +90,6 @@ abstract public class RemoteModel extends AbstractModel {
return NO_UUID.equals(uuid) || TextUtils.isEmpty(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 String getPictureUrl(StringProperty pictureProperty, String size) {
String value = getValue(pictureProperty);
return PictureHelper.getPictureUrl(value, size);
}
public Bitmap getPictureBitmap(StringProperty pictureProperty) { public Bitmap getPictureBitmap(StringProperty pictureProperty) {
String value = getValue(pictureProperty); String value = getValue(pictureProperty);
return PictureHelper.getPictureBitmap(value); return PictureHelper.getPictureBitmap(value);
@ -109,17 +99,6 @@ abstract public class RemoteModel extends AbstractModel {
public static final String PICTURES_DIRECTORY = "pictures"; //$NON-NLS-1$ public static final String PICTURES_DIRECTORY = "pictures"; //$NON-NLS-1$
public static String getPictureHash(TagData tagData) {
long tag_date = 0;
if (tagData.containsValue(TagData.CREATION_DATE)) {
tag_date = tagData.getCreationDate();
}
if (tag_date == 0) {
tag_date = currentTimeMillis();
}
return String.format("cached::%s%s", tagData.getName(), tag_date);
}
@TargetApi(Build.VERSION_CODES.FROYO) @TargetApi(Build.VERSION_CODES.FROYO)
public static JSONObject savePictureJson(Context context, Bitmap bitmap) { public static JSONObject savePictureJson(Context context, Bitmap bitmap) {
try { try {
@ -154,23 +133,6 @@ abstract public class RemoteModel extends AbstractModel {
return null; return null;
} }
public static String getPictureUrl(String value, String size) {
try {
if (value == null) {
return null;
}
JSONObject pictureJson = new JSONObject(value);
if (pictureJson.has("path")) // Unpushed encoded bitmap //$NON-NLS-1$
{
return null;
}
return pictureJson.optString(size);
} catch (JSONException e) {
log.error(e.getMessage(), e);
return value;
}
}
public static Bitmap getPictureBitmap(String value) { public static Bitmap getPictureBitmap(String value) {
try { try {
if (value == null) { if (value == null) {

@ -50,10 +50,6 @@ public final class TagData extends RemoteModel {
public static final StringProperty NAME = new StringProperty( public static final StringProperty NAME = new StringProperty(
TABLE, "name"); TABLE, "name");
/** Project picture */
public static final StringProperty PICTURE = new StringProperty(
TABLE, "picture", Property.PROP_FLAG_JSON | Property.PROP_FLAG_PICTURE);
/** Tag team array (JSON) */ /** Tag team array (JSON) */
@Deprecated public static final StringProperty MEMBERS = new StringProperty( @Deprecated public static final StringProperty MEMBERS = new StringProperty(
TABLE, "members"); TABLE, "members");
@ -144,7 +140,6 @@ public final class TagData extends RemoteModel {
defaultValues.put(USER.name, ""); defaultValues.put(USER.name, "");
defaultValues.put(UUID.name, NO_UUID); defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(NAME.name, ""); defaultValues.put(NAME.name, "");
defaultValues.put(PICTURE.name, "");
defaultValues.put(IS_TEAM.name, 1); defaultValues.put(IS_TEAM.name, 1);
defaultValues.put(MEMBERS.name, ""); defaultValues.put(MEMBERS.name, "");
defaultValues.put(MEMBER_COUNT.name, 0); defaultValues.put(MEMBER_COUNT.name, 0);
@ -266,8 +261,4 @@ public final class TagData extends RemoteModel {
public void setMemberCount(Integer memberCount) { public void setMemberCount(Integer memberCount) {
setValue(MEMBER_COUNT, memberCount); setValue(MEMBER_COUNT, memberCount);
} }
public void setPicture(String picture) {
setValue(PICTURE, picture);
}
} }

@ -69,7 +69,6 @@ public class TagSettingsActivity extends InjectingActionBarActivity {
@Inject ResourceResolver resourceResolver; @Inject ResourceResolver resourceResolver;
private EditText tagName; private EditText tagName;
private Bitmap setBitmap;
private boolean isNewTag = false; private boolean isNewTag = false;
private boolean isDialog; private boolean isDialog;
@ -177,13 +176,6 @@ public class TagSettingsActivity extends InjectingActionBarActivity {
} }
} }
if (setBitmap != null) {
JSONObject pictureJson = RemoteModel.PictureHelper.savePictureJson(this, setBitmap);
if (pictureJson != null) {
tagData.setPicture(pictureJson.toString());
}
}
JSONArray members = new JSONArray(); JSONArray members = new JSONArray();
tagData.setMemberCount(members.length()); tagData.setMemberCount(members.length());
@ -205,19 +197,6 @@ public class TagSettingsActivity extends InjectingActionBarActivity {
finish(); finish();
} }
private void saveTagPictureLocally(Bitmap bitmap) {
if (bitmap == null) {
return;
}
try {
String tagPicture = RemoteModel.PictureHelper.getPictureHash(tagData);
tagData.setPicture(tagPicture);
}
catch (Exception e) {
log.error(e.getMessage(), e);
}
}
@Override @Override
public void finish() { public void finish() {
finishWithAnimation(!isDialog); finishWithAnimation(!isDialog);
@ -253,8 +232,7 @@ public class TagSettingsActivity extends InjectingActionBarActivity {
CameraResultCallback callback = new CameraResultCallback() { CameraResultCallback callback = new CameraResultCallback() {
@Override @Override
public void handleCameraResult(Bitmap bitmap) { public void handleCameraResult(Bitmap bitmap) {
setBitmap = bitmap; log.error("Not expecting this");
saveTagPictureLocally(bitmap);
} }
}; };
if (!ActFmCameraModule.activityResult(this, requestCode, resultCode, data, callback)) { if (!ActFmCameraModule.activityResult(this, requestCode, resultCode, data, callback)) {

@ -100,7 +100,6 @@ public class NameMaps {
putTagPropertyToServerName(TagData.UUID, "uuid", false); putTagPropertyToServerName(TagData.UUID, "uuid", false);
putTagPropertyToServerName(TagData.TASK_COUNT, "task_count", false); putTagPropertyToServerName(TagData.TASK_COUNT, "task_count", false);
putTagPropertyToServerName(TagData.TAG_DESCRIPTION, "description", true); putTagPropertyToServerName(TagData.TAG_DESCRIPTION, "description", true);
putTagPropertyToServerName(TagData.PICTURE, "picture", true);
putTagPropertyToServerName(TagData.IS_FOLDER, "is_folder", false); putTagPropertyToServerName(TagData.IS_FOLDER, "is_folder", false);
} }

@ -13,7 +13,6 @@ import android.graphics.Bitmap;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.TypedValue; import android.util.TypedValue;
@ -31,7 +30,6 @@ import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import org.tasks.R; import org.tasks.R;
@ -152,13 +150,8 @@ public class UpdateAdapter extends CursorAdapter {
private void setupUserActivityRow(View view, UserActivity activity) { private void setupUserActivityRow(View view, UserActivity activity) {
final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); { final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); {
String pictureThumb = activity.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM); Bitmap updateBitmap = activity.getPictureBitmap(UserActivity.PICTURE);
Bitmap updateBitmap = null; setupImagePopupForCommentView(view, commentPictureView, updateBitmap, activity.getMessage(), fragment);
if (TextUtils.isEmpty(pictureThumb)) {
updateBitmap = activity.getPictureBitmap(UserActivity.PICTURE);
}
setupImagePopupForCommentView(view, commentPictureView, pictureThumb, updateBitmap,
activity.getMessage(), fragment);
} }
// name // name
@ -168,7 +161,6 @@ public class UpdateAdapter extends CursorAdapter {
nameView.setTextColor(color); nameView.setTextColor(color);
} }
// date // date
final TextView date = (TextView)view.findViewById(R.id.date); { final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(activity.getCreatedAt(), CharSequence dateString = DateUtils.getRelativeTimeSpanString(activity.getCreatedAt(),
@ -183,13 +175,11 @@ public class UpdateAdapter extends CursorAdapter {
return false; return false;
} }
public static void setupImagePopupForCommentView(View view, ImageView commentPictureView, final String pictureThumb, final Bitmap updateBitmap, public static void setupImagePopupForCommentView(View view, ImageView commentPictureView, final Bitmap updateBitmap,
final String message, final Fragment fragment) { final String message, final Fragment fragment) {
if ((!TextUtils.isEmpty(pictureThumb) && !"null".equals(pictureThumb)) || updateBitmap != null) { //$NON-NLS-1$ if (updateBitmap != null) { //$NON-NLS-1$
commentPictureView.setVisibility(View.VISIBLE); commentPictureView.setVisibility(View.VISIBLE);
if (updateBitmap != null) { commentPictureView.setImageBitmap(updateBitmap);
commentPictureView.setImageBitmap(updateBitmap);
}
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
@ -198,9 +188,7 @@ public class UpdateAdapter extends CursorAdapter {
ImageView imageView = new ImageView(fragment.getActivity()); ImageView imageView = new ImageView(fragment.getActivity());
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
imageView.setImageResource(android.R.drawable.ic_menu_gallery); imageView.setImageResource(android.R.drawable.ic_menu_gallery);
if (updateBitmap != null) { imageView.setImageBitmap(updateBitmap);
imageView.setImageBitmap(updateBitmap);
}
image.setView(imageView); image.setView(imageView);
image.setMessage(message); image.setMessage(message);

@ -358,7 +358,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
// picture // picture
final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture); final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture);
UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.pictureThumb, item.commentBitmap, item.title.toString(), fragment); UpdateAdapter.setupImagePopupForCommentView(view, commentPictureView, item.commentBitmap, item.title.toString(), fragment);
} }
private void addComment() { private void addComment() {
@ -407,14 +407,12 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
private static class NoteOrUpdate { private static class NoteOrUpdate {
private final Spanned title; private final Spanned title;
private final String pictureThumb;
private final Bitmap commentBitmap; private final Bitmap commentBitmap;
private final long createdAt; private final long createdAt;
public NoteOrUpdate(Spanned title, String pictureThumb, Bitmap commentBitmap, long createdAt) { public NoteOrUpdate(Spanned title, Bitmap commentBitmap, long createdAt) {
super(); super();
this.title = title; this.title = title;
this.pictureThumb = pictureThumb;
this.commentBitmap = commentBitmap; this.commentBitmap = commentBitmap;
this.createdAt = createdAt; this.createdAt = createdAt;
} }
@ -428,31 +426,21 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
} }
Spanned title = Html.fromHtml(String.format("%s\n%s", m.getValue(NoteMetadata.TITLE), m.getValue(NoteMetadata.BODY))); //$NON-NLS-1$ Spanned title = Html.fromHtml(String.format("%s\n%s", m.getValue(NoteMetadata.TITLE), m.getValue(NoteMetadata.BODY))); //$NON-NLS-1$
return new NoteOrUpdate(title, return new NoteOrUpdate(title,
m.getValue(NoteMetadata.COMMENT_PICTURE),
null, null,
m.getCreationDate()); m.getCreationDate());
} }
public static NoteOrUpdate fromUpdate(UserActivity u) { public static NoteOrUpdate fromUpdate(UserActivity u) {
String pictureThumb;
Spanned title;
Bitmap commentBitmap = null;
long createdAt;
if(u == null) { if(u == null) {
throw new RuntimeException("UserActivity should never be null"); throw new RuntimeException("UserActivity should never be null");
} }
pictureThumb = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM); Bitmap commentBitmap = u.getPictureBitmap(UserActivity.PICTURE);
if (TextUtils.isEmpty(pictureThumb)) { Spanned title = UpdateAdapter.getUpdateComment(u);
commentBitmap = u.getPictureBitmap(UserActivity.PICTURE); long createdAt = u.getCreatedAt();
}
title = UpdateAdapter.getUpdateComment(u);
createdAt = u.getCreatedAt();
return new NoteOrUpdate( return new NoteOrUpdate(
title, title,
pictureThumb,
commentBitmap, commentBitmap,
createdAt); createdAt);
} }

@ -11,7 +11,6 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
@ -86,9 +85,6 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
}; };
filter.customTaskList = new ComponentName(context, TagViewFragment.class); filter.customTaskList = new ComponentName(context, TagViewFragment.class);
if(tag.image != null) {
filter.imageUrl = tag.image;
}
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag); extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.uuid); extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.uuid);

@ -83,13 +83,11 @@ public final class TagService {
public String tag; public String tag;
public int count; public int count;
public String uuid; public String uuid;
public String image;
public Tag(TagData tagData) { public Tag(TagData tagData) {
tag = tagData.getName(); tag = tagData.getName();
count = tagData.getTaskCount(); count = tagData.getTaskCount();
uuid = tagData.getUUID(); uuid = tagData.getUUID();
image = tagData.getPictureUrl(TagData.PICTURE, RemoteModel.PICTURE_THUMB);
} }
@Override @Override

@ -211,7 +211,7 @@ public class WidgetHelper {
long id = preferences.getLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, 0); long id = preferences.getLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, 0);
TagData tagData; TagData tagData;
if (id > 0) { if (id > 0) {
tagData = tagDataService.fetchById(id, TagData.ID, TagData.NAME, TagData.TASK_COUNT, TagData.UUID, TagData.PICTURE, TagData.USER_ID, TagData.MEMBER_COUNT); tagData = tagDataService.fetchById(id, TagData.ID, TagData.NAME, TagData.TASK_COUNT, TagData.UUID, TagData.USER_ID, TagData.MEMBER_COUNT);
if (tagData != null && !tagData.getName().equals(filter.title)) { // Tag has been renamed; rebuild filter if (tagData != null && !tagData.getName().equals(filter.title)) { // Tag has been renamed; rebuild filter
filter = TagFilterExposer.filterFromTagData(context, tagData); filter = TagFilterExposer.filterFromTagData(context, tagData);
preferences.setString(WidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery()); preferences.setString(WidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery());

Loading…
Cancel
Save