diff --git a/src/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java b/src/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java new file mode 100644 index 0000000000..620671dcde --- /dev/null +++ b/src/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java @@ -0,0 +1,33 @@ +package org.thoughtcrime.securesms.components; + +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.widget.ImageView; + +import com.bumptech.glide.request.target.BitmapImageViewTarget; + +import org.thoughtcrime.securesms.util.concurrent.SettableFuture; + +public class GlideBitmapListeningTarget extends BitmapImageViewTarget { + + private final SettableFuture loaded; + + public GlideBitmapListeningTarget(@NonNull ImageView view, @NonNull SettableFuture loaded) { + super(view); + this.loaded = loaded; + } + + @Override + protected void setResource(@Nullable Bitmap resource) { + super.setResource(resource); + loaded.set(true); + } + + @Override + public void onLoadFailed(@Nullable Drawable errorDrawable) { + super.onLoadFailed(errorDrawable); + loaded.set(true); + } +} diff --git a/src/org/thoughtcrime/securesms/components/GlideListeningTarget.java b/src/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java similarity index 79% rename from src/org/thoughtcrime/securesms/components/GlideListeningTarget.java rename to src/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java index c8b2e1e12f..e333067940 100644 --- a/src/org/thoughtcrime/securesms/components/GlideListeningTarget.java +++ b/src/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java @@ -9,11 +9,11 @@ import com.bumptech.glide.request.target.DrawableImageViewTarget; import org.thoughtcrime.securesms.util.concurrent.SettableFuture; -public class GlideListeningTarget extends DrawableImageViewTarget { +public class GlideDrawableListeningTarget extends DrawableImageViewTarget { private final SettableFuture loaded; - public GlideListeningTarget(@NonNull ImageView view, @NonNull SettableFuture loaded) { + public GlideDrawableListeningTarget(@NonNull ImageView view, @NonNull SettableFuture loaded) { super(view); this.loaded = loaded; } diff --git a/src/org/thoughtcrime/securesms/components/ThumbnailView.java b/src/org/thoughtcrime/securesms/components/ThumbnailView.java index 00fffdcd1f..7841691d5b 100644 --- a/src/org/thoughtcrime/securesms/components/ThumbnailView.java +++ b/src/org/thoughtcrime/securesms/components/ThumbnailView.java @@ -3,9 +3,7 @@ package org.thoughtcrime.securesms.components; import android.content.Context; import android.content.res.TypedArray; import android.net.Uri; -import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.support.annotation.UiThread; import android.util.AttributeSet; import android.util.Log; @@ -15,16 +13,12 @@ import android.widget.FrameLayout; import android.widget.ImageView; import com.bumptech.glide.RequestBuilder; -import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; import com.bumptech.glide.load.resource.bitmap.CenterCrop; import com.bumptech.glide.load.resource.bitmap.FitCenter; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; -import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; -import com.bumptech.glide.request.target.Target; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.database.AttachmentDatabase; @@ -280,9 +274,9 @@ public class ThumbnailView extends FrameLayout { SettableFuture result = new SettableFuture<>(); if (slide.getThumbnailUri() != null) { - buildThumbnailGlideRequest(glideRequests, slide).into(new GlideListeningTarget(image, result)); + buildThumbnailGlideRequest(glideRequests, slide).into(new GlideDrawableListeningTarget(image, result)); } else if (slide.hasPlaceholder()) { - buildPlaceholderGlideRequest(glideRequests, slide).into(new GlideListeningTarget(image, result)); + buildPlaceholderGlideRequest(glideRequests, slide).into(new GlideBitmapListeningTarget(image, result)); } else { glideRequests.clear(image); result.set(false); @@ -299,7 +293,7 @@ public class ThumbnailView extends FrameLayout { .diskCacheStrategy(DiskCacheStrategy.NONE) .transforms(new CenterCrop(), new RoundedCorners(radius)) .transition(withCrossFade()) - .into(new GlideListeningTarget(image, future)); + .into(new GlideDrawableListeningTarget(image, future)); return future; }