Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Aug 25, 2014
1 parent 2426243 commit 48e4ed2
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +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;
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.setHeight(view.getHeight() + newHeight - oldHeight);
view.invalidate();
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;
}

final int oldHeight = remote.getBounds().height();
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
maxWidth = mMaxSize;
AppLog.d(T.UTILS, "WPImageGetter setting maxWidth = mMaxSize");
}

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

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

// invalidate the textView so the image redraws
view.invalidate();

int newHeight = remote.getBounds().height();
view.setHeight(view.getHeight() + newHeight - oldHeight);
}
});

return remote;
}

Expand Down

0 comments on commit 48e4ed2

Please sign in to comment.