package com.yidianling.dynamic.common.tool;

import android.app.Activity;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lzy.imagepicker.loader.ImageLoader;
import com.ydl.ydl_image.config.ISimpleImageOpConfig;
import com.ydl.ydl_image.config.SimpleImageOpConfiger;
import com.ydl.ydl_image.manager.YDLImageCacheManager;
import com.ydl.ydl_image.module.GlideApp;
import com.yidianling.dynamic.R;

/**
 * Created by xiongyu on 2017/4/7.
 */

public class GlideImageLoader implements ImageLoader {
    @Override
    public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
        showImage(activity,path,imageView,width,height);
    }

    @Override
    public void displayImagePreview(Activity activity, String path, ImageView imageView, int width, int height) {
        showImage(activity,path,imageView,width,height);
    }

    @Override
    public void displayImage(Activity activity, Uri uri, ImageView imageView, int width, int i1) {
        GlideApp.with(activity)                             //配置上下文
                .load(uri)      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                .error(com.ydl.ydlcommon.R.drawable.platform_default_img)           //设置错误图片
                .placeholder(com.ydl.ydlcommon.R.drawable.platform_default_img)     //设置占位图片
                .diskCacheStrategy(DiskCacheStrategy.ALL)//缓存全尺寸
                .into(imageView);
    }

    private void showImage(Activity activity, String path, ImageView imageView, int width, int height){
        SimpleImageOpConfiger sp = new SimpleImageOpConfiger();
        sp.loadingPic = R.drawable.dynamic_default_img;
        sp.errorPic = R.drawable.dynamic_default_img;
        sp.scaleType = ISimpleImageOpConfig.CENTER_CROP;
        sp.isCacheOnDisk = false;
        YDLImageCacheManager.showImage(activity,path,imageView,width, height,sp);
    }

    @Override
    public void clearMemoryCache() {

    }
}
