package cn.yyxx.eyuancomm.impl.channel.huawei

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.*
import android.widget.ImageView
import cn.yyxx.support.DensityUtils
import cn.yyxx.support.ResUtils

/**
 * @author #Suyghur.
 * Created on 2022/01/27
 */
class HuaweiLoginDialog(context: Context, private val isLandscape: Boolean) : Dialog(context) {

    lateinit var ivHw: ImageView
    lateinit var ivGoogle: ImageView
    lateinit var ivFacebook: ImageView

    init {
        setCanceledOnTouchOutside(false)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        initView()
    }

    private fun initView() {
        val view: View = LayoutInflater.from(context).inflate(ResUtils.getResId(context, "yyxx_dialog_hw_login", "layout"), null)
        setContentView(view)

        val attr = window?.attributes as WindowManager.LayoutParams
        //设置dialog 在布局中的位置
        attr.height = ViewGroup.LayoutParams.WRAP_CONTENT
        if (isLandscape) {
            attr.width = DensityUtils.getHeightAndWidth(context)[0] / 2
        } else {
            attr.width = DensityUtils.getHeightAndWidth(context)[0] - 80
        }
        attr.gravity = Gravity.CENTER

        ivHw = view.findViewById(ResUtils.getResId(context, "yyxx_login_iv_hw", "id"))
        ivGoogle = view.findViewById(ResUtils.getResId(context, "yyxx_login_iv_google", "id"))
        ivFacebook = view.findViewById(ResUtils.getResId(context, "yyxx_login_iv_facebook", "id"))
    }
}

