Skip to content

Commit

Permalink
Cleanup WPImageGetter based on code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Aug 25, 2014
1 parent f0229fc commit 8e366fa
Showing 1 changed file with 8 additions and 29 deletions.
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 Down Expand Up @@ -110,30 +95,29 @@ public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate)
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
AppLog.d(T.UTILS, "WPImageGetter maxWidth = mMaxSize");
}
remote.setRemoteDrawable(drawable, maxWidth);

// image is from cache? don't need to modify view height
if (isImmediate) {
AppLog.d(T.UTILS, "WPImageGetter isImmediate");
return;
}

int newHeight = remote.getBounds().height();
view.invalidate();
// For ICS
view.setHeight(view.getHeight() + newHeight - oldHeight);
// Pre ICS
view.setEllipsize(null);
view.invalidate();
}
}
});
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 +142,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 8e366fa

Please sign in to comment.