Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue/1760-reader-comment-full-images #1781

Merged
merged 5 commits into from
Aug 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought view.requestLayout(); view.invalidate(); would be sufficient but that doesn't work:

}
}
});

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