Skip to content

Commit

Permalink
Fix blurhash being visible on transparent images.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Oct 21, 2019
1 parent 660ec88 commit 8b06051
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/org/thoughtcrime/securesms/components/ThumbnailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.bumptech.glide.load.engine.DiskCacheStrategy;
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.RequestOptions;

Expand All @@ -31,6 +30,7 @@
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideClickListener;
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
Expand All @@ -40,6 +40,7 @@
import java.util.Collections;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;

Expand Down Expand Up @@ -299,6 +300,12 @@ public ListenableFuture<Boolean> setImageResource(@NonNull GlideRequests glideRe
}

if (slide.getThumbnailUri() != null) {
if (!MediaUtil.isJpegType(slide.getContentType()) && !MediaUtil.isVideoType(slide.getContentType())) {
SettableFuture<Boolean> thumbnailFuture = new SettableFuture<>();
thumbnailFuture.deferTo(result);
thumbnailFuture.addListener(new BlurhashClearListener(glideRequests, blurhash));
}

buildThumbnailGlideRequest(glideRequests, slide).into(new GlideDrawableListeningTarget(image, result));
resultHandled = true;
} else {
Expand Down Expand Up @@ -445,4 +452,27 @@ public void onClick(View view) {
}
}
}

private static class BlurhashClearListener implements ListenableFuture.Listener<Boolean> {

private final GlideRequests glideRequests;
private final ImageView blurhash;

private BlurhashClearListener(@NonNull GlideRequests glideRequests, @NonNull ImageView blurhash) {
this.glideRequests = glideRequests;
this.blurhash = blurhash;
}

@Override
public void onSuccess(Boolean result) {
glideRequests.clear(blurhash);
blurhash.setImageDrawable(null);
}

@Override
public void onFailure(ExecutionException e) {
glideRequests.clear(blurhash);
blurhash.setImageDrawable(null);
}
}
}

0 comments on commit 8b06051

Please sign in to comment.