Skip to content

Commit b1ceab2

Browse files
committed
More cleanup
1 parent 9a34a96 commit b1ceab2

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/WPImageGetter.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,40 @@ public void onErrorResponse(VolleyError error) {
8282

8383
@Override
8484
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
85-
if (response.getBitmap() != null) {
86-
// make sure view is still valid
87-
TextView view = getView();
88-
if (view == null) {
89-
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
90-
return;
91-
}
92-
93-
Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
94-
final int oldHeight = remote.getBounds().height();
95-
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
96-
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
97-
maxWidth = mMaxSize;
98-
AppLog.d(T.UTILS, "WPImageGetter maxWidth = mMaxSize");
99-
}
100-
remote.setRemoteDrawable(drawable, maxWidth);
101-
102-
// image is from cache? don't need to modify view height
103-
if (isImmediate) {
104-
AppLog.d(T.UTILS, "WPImageGetter isImmediate");
105-
return;
106-
}
107-
108-
int newHeight = remote.getBounds().height();
109-
view.setHeight(view.getHeight() + newHeight - oldHeight);
110-
view.invalidate();
85+
if (response.getBitmap() == null) {
86+
AppLog.w(T.UTILS, "WPImageGetter null bitmap");
87+
}
88+
89+
TextView view = getView();
90+
if (view == null) {
91+
AppLog.w(T.UTILS, "WPImageGetter view is invalid");
92+
return;
93+
}
94+
95+
final int oldHeight = remote.getBounds().height();
96+
int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
97+
if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
98+
maxWidth = mMaxSize;
99+
AppLog.d(T.UTILS, "WPImageGetter setting maxWidth = mMaxSize");
111100
}
101+
102+
Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
103+
remote.setRemoteDrawable(drawable, maxWidth);
104+
105+
// image is from cache? don't need to modify view height
106+
if (isImmediate) {
107+
AppLog.d(T.UTILS, "WPImageGetter isImmediate");
108+
return;
109+
}
110+
111+
// invalidate the textView so the image redraws
112+
view.invalidate();
113+
114+
int newHeight = remote.getBounds().height();
115+
view.setHeight(view.getHeight() + newHeight - oldHeight);
112116
}
113117
});
118+
114119
return remote;
115120
}
116121

0 commit comments

Comments
 (0)