Fix glide problem

pull/21/head
FongMi 4 years ago
parent 2f194b6313
commit 04987164ca
  1. 27
      app/src/main/java/com/fongmi/android/tv/utils/ImgUtil.java

@ -4,15 +4,14 @@ import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.bumptech.glide.signature.ObjectKey;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
@ -30,21 +29,27 @@ public class ImgUtil {
public static void load(String url, ImageView view) {
float thumbnail = 1 - Prefers.getThumbnail() * 0.3f;
Glide.with(App.get()).load(url).thumbnail(thumbnail).signature(new ObjectKey(url + "_" + thumbnail)).placeholder(R.drawable.ic_img_loading).error(R.drawable.ic_img_error).listener(getListener(view)).into(view);
Glide.with(App.get()).load(url).thumbnail(thumbnail).signature(new ObjectKey(url + "_" + thumbnail)).placeholder(R.drawable.ic_img_loading).into(customTarget(view));
}
private static RequestListener<Drawable> getListener(ImageView view) {
return new RequestListener<>() {
private static CustomTarget<Drawable> customTarget(ImageView view) {
return new CustomTarget<>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
public void onLoadFailed(@Nullable Drawable errorDrawable) {
view.setScaleType(ImageView.ScaleType.CENTER);
return false;
view.setImageResource(R.drawable.ic_img_error);
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
return false;
view.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
view.setScaleType(ImageView.ScaleType.CENTER);
view.setImageDrawable(null);
}
};
}

Loading…
Cancel
Save