That fuck shit the fascists are using
at master 45 lines 1.2 kB view raw
1package org.tm.archive.glide; 2 3import android.graphics.Bitmap; 4import android.graphics.drawable.Drawable; 5 6import androidx.annotation.NonNull; 7import androidx.annotation.Nullable; 8import androidx.lifecycle.LiveData; 9import androidx.lifecycle.MutableLiveData; 10 11import com.bumptech.glide.request.target.CustomTarget; 12import com.bumptech.glide.request.transition.Transition; 13 14/** 15 * A Glide target that exposes a LiveData<Bitmap> that can be observed. 16 * 17 * If the load is canceled or otherwise fails, it will post a null value. 18 */ 19public class GlideLiveDataTarget extends CustomTarget<Bitmap> { 20 21 private final MutableLiveData<Bitmap> liveData = new MutableLiveData<>(); 22 23 public GlideLiveDataTarget(int width, int height) { 24 super(width, height); 25 } 26 27 @Override 28 public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { 29 liveData.postValue(resource); 30 } 31 32 @Override 33 public void onLoadCleared(@Nullable Drawable placeholder) { 34 liveData.postValue(null); 35 } 36 37 @Override 38 public void onLoadFailed(@Nullable Drawable errorDrawable) { 39 liveData.postValue(null); 40 } 41 42 public @NonNull LiveData<Bitmap> getLiveData() { 43 return liveData; 44 } 45}