页面销毁glide报错处理
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.dahe.mylibrary.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.MultiTransformation;
|
||||
@@ -70,9 +73,19 @@ public class ImageLoader {
|
||||
*/
|
||||
public void loadImage(Context context, final Object url, final ImageView imageView, RequestOptions requestOptions, int placeholder) {
|
||||
if (null != context) {
|
||||
if (placeholder != -1)
|
||||
requestOptions = requestOptions.placeholder(placeholder).error(placeholder);
|
||||
Glide.with(context).load(url).centerCrop().apply(requestOptions).into(imageView);
|
||||
if (context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
if (activity != null && !activity.isFinishing()) {
|
||||
if (placeholder != -1)
|
||||
requestOptions = requestOptions.placeholder(placeholder).error(placeholder);
|
||||
Glide.with(context).load(url).centerCrop().apply(requestOptions).into(imageView);
|
||||
}
|
||||
}else {
|
||||
if (placeholder != -1)
|
||||
requestOptions = requestOptions.placeholder(placeholder).error(placeholder);
|
||||
Glide.with(context).load(url).centerCrop().apply(requestOptions).into(imageView);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +193,7 @@ public class ImageLoader {
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public void loadCircleWithBorderImage(Context context, Object url,RequestOptions requestOptions, int borderWidth, int borderColor, ImageView imageView, int placeholder) {
|
||||
public void loadCircleWithBorderImage(Context context, Object url, RequestOptions requestOptions, int borderWidth, int borderColor, ImageView imageView, int placeholder) {
|
||||
if (null != context) {
|
||||
requestOptions.transform(new GlideCircleWithBorder(context, borderWidth, ContextCompat.getColor(context, borderColor)));
|
||||
loadImage(context, url, imageView, requestOptions, placeholder);
|
||||
|
||||
Reference in New Issue
Block a user