package com.guadou.ninegrid

import android.annotation.SuppressLint
import android.content.Context
import android.widget.ImageView
import com.guadou.lib_baselib.engine.extLoad
import com.guadou.lib_baselib.engine.extLoadGif
import com.guadou.lib_baselib.ext.checkEmpty

/**
 * 九宫格加载器
 */
class NineGlideLoader : ImageLoader {
    @SuppressLint("CheckResult")
    override fun onDisplayImage(context: Context, imageView: ImageView, url: String) {
        var urlStr = url
        if (urlStr.checkEmpty()) return

        if (urlStr.startsWith("https")) {
            //https可能会阻塞glide线程，导致图片加载缓慢
            urlStr = urlStr.replace("https", "http")
        }

        imageView.setImageResource(R.drawable.layer_main_placeholder)

        if (urlStr.endsWith(".gif")) {

            imageView.extLoadGif(urlStr, R.drawable.layer_main_placeholder)

        } else {
            imageView.extLoad(urlStr, R.drawable.layer_main_placeholder)
        }
    }
}