Skip to content

Commit

Permalink
Merge pull request #1781 from wordpress-mobile/issue/17760-reader-com…
Browse files Browse the repository at this point in the history
…ment-full-images

issue/1760-reader-comment-full-images
  • Loading branch information
maxme committed Aug 27, 2014
2 parents e4604c8 + 169efe1 commit 7736564
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ReaderCommentAdapter extends BaseAdapter {
private final int mBgColorHighlight;
private final int mLinkColor;
private final int mNoLinkColor;
private final int mMaxImageSz;

private final String mLike;
private final String mLikedBy;
Expand Down Expand Up @@ -76,7 +75,6 @@ public ReaderCommentAdapter(Context context,
mInflater = LayoutInflater.from(context);
mIndentPerLevel = (context.getResources().getDimensionPixelSize(R.dimen.reader_comment_indent_per_level) / 2);
mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_small);
mMaxImageSz = context.getResources().getDimensionPixelSize(R.dimen.reader_comment_max_image_size);

mBgColorNormal = context.getResources().getColor(R.color.grey_extra_light);
mBgColorHighlight = context.getResources().getColor(R.color.grey_light);
Expand Down Expand Up @@ -136,7 +134,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

holder.txtAuthor.setText(comment.getAuthorName());
holder.imgAvatar.setImageUrl(PhotonUtils.fixAvatar(comment.getAuthorAvatar(), mAvatarSz), WPNetworkImageView.ImageType.AVATAR);
CommentUtils.displayHtmlComment(holder.txtText, comment.getText(), mMaxImageSz);
CommentUtils.displayHtmlComment(holder.txtText, comment.getText(), parent.getWidth());

java.util.Date dtPublished = DateTimeUtils.iso8601ToJavaDate(comment.getPublished());
holder.txtDate.setText(DateTimeUtils.javaDateToTimeSpan(dtPublished));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* adapted from existing ImageGetter code in NoteCommentFragment
*/
public class WPImageGetter implements Html.ImageGetter {
private WeakReference<TextView> mWeakView;
private int mMaxSize;
private final WeakReference<TextView> mWeakView;
private final int mMaxSize;
private ImageLoader mImageLoader;
private Drawable mLoadingDrawable;
private Drawable mFailedDrawable;
Expand All @@ -43,18 +43,6 @@ public WPImageGetter(TextView view, int maxSize, ImageLoader imageLoader, Drawab
mFailedDrawable = failedDrawable;
}

public void setImageLoader(ImageLoader imageLoader) {
mImageLoader = imageLoader;
}

public void setLoadingDrawable(Drawable loadingDrawable) {
mLoadingDrawable = loadingDrawable;
}

public void setFailedDrawable(Drawable failedDrawable) {
mFailedDrawable = failedDrawable;
}

private TextView getView() {
return mWeakView.get();
}
Expand All @@ -80,9 +68,6 @@ public Drawable getDrawable(String source) {
source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
}

TextView view = getView();
// Drawable loading = view.getContext().getResources().getDrawable(R.drawable.remote_image); FIXME: here
// Drawable failed = view.getContext().getResources().getDrawable(R.drawable.remote_failed);
final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);

mImageLoader.get(source, new ImageLoader.ImageListener() {
Expand All @@ -97,43 +82,40 @@ public void onErrorResponse(VolleyError error) {

@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
if (response.getBitmap() != null) {
// make sure view is still valid
TextView view = getView();
if (view == null) {
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
return;
}

Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
final int oldHeight = remote.getBounds().height();
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
}
remote.setRemoteDrawable(drawable, maxWidth);

// image is from cache? don't need to modify view height
if (isImmediate) {
return;
}

int newHeight = remote.getBounds().height();
view.invalidate();
// For ICS
view.setHeight(view.getHeight() + newHeight - oldHeight);
// Pre ICS
view.setEllipsize(null);
if (response.getBitmap() == null) {
AppLog.w(T.UTILS, "WPImageGetter null bitmap");
}

TextView view = getView();
if (view == null) {
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
return;
}

int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
}

Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
remote.setRemoteDrawable(drawable, maxWidth);

// force textView to resize correctly if image isn't cached by resetting the content
// to itself - this way the textView will use the cached image, and resizing to
// accommodate the image isn't necessary
if (!isImmediate) {
view.setText(view.getText());
}
}
});

return remote;
}

private static class RemoteDrawable extends BitmapDrawable {
protected Drawable mRemoteDrawable;
protected Drawable mLoadingDrawable;
protected Drawable mFailedDrawable;
Drawable mRemoteDrawable;
final Drawable mLoadingDrawable;
final Drawable mFailedDrawable;
private boolean mDidFail = false;

public RemoteDrawable(Drawable loadingDrawable, Drawable failedDrawable) {
Expand All @@ -158,11 +140,6 @@ public void setBounds(int x, int y, int width, int height) {
}
}

public void setRemoteDrawable(Drawable remote) {
mRemoteDrawable = remote;
setBounds(0, 0, mRemoteDrawable.getIntrinsicWidth(), mRemoteDrawable.getIntrinsicHeight());
}

public void setRemoteDrawable(Drawable remote, int maxWidth) {
// null sentinel for now
if (remote == null) {
Expand Down

0 comments on commit 7736564

Please sign in to comment.