package com.wisewoods.base.utils;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wisewoods.base.R;

public class ImgUtils {
    public static void load(Activity activity, String url, ImageView iv) {
        if (!isDestroy(activity)) {
            Glide.with(activity)
                    .load(url)
                    .placeholder(R.color.app_color_f6)
                    .error(R.color.app_color_f6)
                    .into(iv);
        }
    }

    public static void load(Context context, String url, ImageView iv) {
        Glide.with(context)
                .load(url)
                .placeholder(R.color.app_color_f6)
                .error(R.color.app_color_f6)
                .into(iv);
    }


    public static void load(Context context, String url, int error, ImageView iv) {
        Glide.with(context)
                .load(url)
                .placeholder(error)
                .error(error)
                .into(iv);
    }


    public static boolean isDestroy(Activity mActivity) {
        if (mActivity == null || mActivity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) {
            return true;
        } else {
            return false;
        }
    }

}
