package xn.hxp.weidith

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import xn.hxp.R
import com.rc.httpcore.HttpConfig

//弹框显示大图片
class ImgDialogs(private val ct: Context,private val datas: String) : Dialog(ct) {

    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.img_dialogs)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        val img = findViewById<ImageView>(R.id.imgs)
        // 使用Glide加载图片并应用圆角转换，设置磁盘缓存策略为AUTOMATIC
        val requestOptions = RequestOptions()
            .transform(RoundedCorners(10)) // 设置圆角半径
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) // 设置磁盘缓存策略
        // 使用图片加载库加载图片并显示在ImageView中
        Glide.with(ct)
            .load("${HttpConfig.API_BASE_IMG_URL}$datas")
            .apply(requestOptions)
            .into(img)
    }


}