package com.zj365.mime.weight

import android.content.Context
import android.view.Gravity
import android.view.View
import android.webkit.WebView
import android.webkit.WebViewClient
import com.azhon.appupdate.utils.DensityUtil
import com.liang.jtablayout.utils.DensityUtils
import com.xty.base.dialog.BaseDialog
import com.zj365.mime.databinding.DialogTipToastBinding
import com.zj365.mime.databinding.DialogWebTipToastBinding

class WebViewDialog (context: Context,  var url:String="file:///android_asset/word_rule.html", var confirm:()->Unit,): BaseDialog(context) {
    val binding by lazy{ DialogWebTipToastBinding.inflate(layoutInflater)}
    override fun setLayout()=binding.root
    override fun initView() {
        super.initView()
        setDialogPadding(DensityUtils.dip2px(context,16f),0,DensityUtils.dip2px(context,16f),0)
        setWeb()
        //"file:///android_asset/word_rule.html"
        binding.mRule.loadUrl(url)

        binding.mTvConfirm.setOnClickListener {
            confirm.invoke()
            dismiss()
        }


    }

    private fun setWeb() {
        binding.mRule.webViewClient = webViewClient
    }


    private val webViewClient: WebViewClient = object : WebViewClient() {
        override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
            view.loadUrl(url)
            return true
        }


    }
}