Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Feb 18, 2018
1 parent f069cad commit 14f40d8
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import android.view.View;

final class DisplayImageAction<T> extends BaseLoadImageAction<T> {
private final Resources mResources;
private final WeakReference<Resources> mResources;
private final WeakReference<View> mView;
private final Handler mMainThreadHandler;
private final DisplayCallback mDisplayCallback;
Expand All @@ -56,7 +56,7 @@ public DisplayImageAction(@NonNull Resources resources, @NonNull View view, @Non
boolean fadeEnabled, long fadeDuration, float cornerRadius) {
super(descriptor, bitmapLoader, requiredSize, cacheMode, transformation, memoryCache, storageCache,
loadCallback, errorCallback, pauseLock);
mResources = resources;
mResources = new WeakReference<>(resources);
mView = new WeakReference<>(view);
mDisplayCallback = displayCallback;
mPlaceholder = placeholder;
Expand All @@ -74,7 +74,7 @@ public boolean hasSameDescriptor(@Nullable String descriptorKey) {

@Override
protected void onImageLoaded(@NonNull Bitmap image) {
if (isCancelled() || mView.get() == null) {
if (isCancelled() || mView.get() == null || mResources.get() == null) {
return;
}
mMainThreadHandler.post(new SetImageAction(image));
Expand All @@ -90,6 +90,7 @@ protected void onError(@NonNull Throwable error) {
@Override
protected void onCancelled() {
mView.clear();
mResources.clear();
}

private final class SetErrorDrawableAction implements Runnable {
Expand Down Expand Up @@ -124,11 +125,12 @@ public void run() {
return;
}
View view = mView.get();
if (view == null || InternalUtils.getDisplayImageAction(view) != DisplayImageAction.this) {
Resources resources = mResources.get();
if (view == null || resources == null ||
InternalUtils.getDisplayImageAction(view) != DisplayImageAction.this) {
return;
}
Bitmap image = mImage;
Resources resources = mResources;
DisplayCallback displayCallback = mDisplayCallback;
float cornerRadius = mCornerRadius;
boolean roundCorners = cornerRadius > 0 || cornerRadius == RoundedDrawable.MAX_RADIUS;
Expand Down

0 comments on commit 14f40d8

Please sign in to comment.