package com.grkj.iscs_mc.view.fragment

import android.webkit.CookieManager
import androidx.navigation.fragment.navArgs
import com.grkj.iscs_mc.databinding.FragmentMaterialInstructionDetailBinding
import com.grkj.iscs_mc.extentions.navigateUp
import com.grkj.iscs_mc.util.log.LogUtil
import com.grkj.iscs_mc.view.base.BaseFragment

/**
 * 物资使用说明详情页 - WebView
 */
class MaterialInstructionDetailFragment : BaseFragment<FragmentMaterialInstructionDetailBinding>() {

    override val viewBinding: FragmentMaterialInstructionDetailBinding
        get() = FragmentMaterialInstructionDetailBinding.inflate(layoutInflater)

    override fun initView() {
        mBinding?.cbBack?.setOnClickListener { navigateUp() }

        val settings = mBinding?.wvDetail?.settings
        settings?.javaScriptEnabled = true
//        settings?.setAppCacheEnabled(true)   // 启用localstorage本地存储api
        settings?.domStorageEnabled = true   // 启用dom存储(关键就是这句)，貌似网上twitter显示有问题也是这个属性没有设置的原因
        settings?.databaseEnabled = true     // 启用html5数据库功能.
        // 默认自动播放声音是会被拦截的，只有点击触发的声音才会播放，想要自动播放的时候就需要设置
        settings?.mediaPlaybackRequiresUserGesture = false

        CookieManager.getInstance().acceptThirdPartyCookies(mBinding?.wvDetail)

        val args: MaterialInstructionDetailFragmentArgs by navArgs()
        LogUtil.i("html page file : ${args.url}")
        mBinding?.wvDetail?.loadUrl(args.url)
    }

    override fun onDestroy() {
        super.onDestroy()
        mBinding?.wvDetail?.loadUrl("about:blank")
        mBinding?.wvDetail?.destroy()
    }
}