package com.example.chemical.weidith

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.chemical.ChemicalApp
import com.example.chemical.R
import com.example.chemical.ui.DoubleDialogBean
import com.rc.httpcore.HttpConfig

//双人认证-通过弹框
class DoublePeopleDialog(val ct: Context, val mDoubleDialogBean: List<DoubleDialogBean>, private var iClickLit: IClickLit) :
    Dialog(ct) {
    private var butClos: Button? = null
    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.double_people_dialog)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        findViewById<TextView>(R.id.nameA).text = mDoubleDialogBean[0].name
        findViewById<TextView>(R.id.nameB).text = mDoubleDialogBean[1].name
        val imgA = findViewById<ImageView>(R.id.imgA)
        val imgB = findViewById<ImageView>(R.id.imgB)
        var tvView = findViewById<TextView>(R.id.tvView)
        iClickLit.onUpView(tvView!!)
        if (mDoubleDialogBean[0].urls != null) {
            Glide.with(ct)
                .load("${HttpConfig.API_BASE_IMG_URL}${mDoubleDialogBean[0].urls}")
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
                .error(R.mipmap.icon_zhan_wei)
                .into(imgA)
        }
        if (mDoubleDialogBean[1].urls != null) {
            Glide.with(ct)
                .load("${HttpConfig.API_BASE_IMG_URL}${mDoubleDialogBean[1].urls}")
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
                .error(R.mipmap.icon_zhan_wei)
                .into(imgB)
        }

    }
    interface IClickLit {
        fun onUpView(tvView: TextView)//关闭后调用归还api
    }
}