package com.xty.base.dialog

import android.content.Context
import android.graphics.Bitmap
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.xty.base.databinding.DialogActivitiesBinding
import com.xty.common.R
import com.xty.common.SizeUtil
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.setBigImage
import com.xty.common.setImage
import com.xty.common.setImageUser
import com.xty.network.model.BannerBean

class DialogActivities (context:Context,var bannerBean: BannerBean?): BaseDialog(context)  {
    val binding by lazy { DialogActivitiesBinding.inflate(layoutInflater) }
    override fun setLayout() = binding.root

    override fun initView() {
        super.initView()
        setDialogPadding(SizeUtil.dp2px(context, 30f), 0, SizeUtil.dp2px(context, 30f), 0)
        bannerBean?.let {
            binding.imgActivies.setBigImage(context,it.imgUrl)
            /*Glide.with(context).asBitmap().load(it.imgUrl).error(R.mipmap.ic_welcome_main_bg)
                .into(object : SimpleTarget<Bitmap?>() {
                    override fun onResourceReady(
                        resource: Bitmap,
                        transition: Transition<in Bitmap?>?
                    ) {
                        if (resource != null) {
                            binding.imgActivies.setImageBitmap(resource)
                        }
                    }
                })*/
        }
        binding.imgClose.setOnClickListener { dismiss() }

        binding.imgActivies.setOnClickListener {
            bannerBean?.let { bean->
                bean.linkAddress?.let {
                    if(bean.bannerType != 5 &&it.startsWith("http")){
                        var bundle = Bundle()
                        bundle.putString("title", bean.title)
                        bundle.putString("url", it)
                        RouteManager.goAct(ARouterUrl.WEB_ACT, bundle)
                    }
                }


            }

        }
    }
}