package com.hongyegroup.cpt_parttime.ui

import android.os.Bundle
import android.text.TextUtils
import android.view.ViewGroup
import android.widget.FrameLayout
import com.guadou.cs_cptservices.base.fragment.YYBaseVDBFragment
import com.guadou.cs_cptservices.interfaces.IFragmentRefresh
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.view.MyWebView
import com.guadou.lib_baselib.view.WebViewManager
import com.hongyegroup.cpt_parttime.R
import com.hongyegroup.cpt_parttime.databinding.FragmentParttimeJobDetailPaymentBinding
import com.hongyegroup.cpt_parttime.mvvm.PartJobDetailPaymentViewModel

/**
 * 工作详情 子页面 展示推荐的工作
 */
class PartJobDetailPaymentFragment : YYBaseVDBFragment<PartJobDetailPaymentViewModel, FragmentParttimeJobDetailPaymentBinding>(),
    IFragmentRefresh {

    private val mWebUrl = "http://yyjobs-api-dev.guabean.com/payment_process/payment_process_life.html" //网页加载的地址
    private lateinit var mWebView: MyWebView

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_parttime_job_detail_payment)
    }

    override fun init(savedInstanceState: Bundle?) {

        initWebview()
    }

    private fun initWebview() {

        //先移除所有View
        mBinding.flPaymentProcess.removeAllViews()

        val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        mWebView = WebViewManager.obtain(mActivity)
        mWebView.layoutParams = params

        mWebView.setOnWebChangeListener(object : MyWebView.OnWebChangeListener {
            override fun titleChange(title: String?) {}
            override fun progressChange(progress: Int) {}
            override fun onInnerLinkChecked() {}
            override fun onWebLoadError() {}
        })

        if (!TextUtils.isEmpty(mWebUrl)) {
            mWebView.loadUrl(mWebUrl)
        }

        mBinding.flPaymentProcess.addView(mWebView)
    }


    override fun onDestroyView() {
        super.onDestroyView()
        //工具类回收重置状态
        WebViewManager.recycle(mWebView)
    }

    override fun startObserve() {
    }

    override fun scrollTopRefresh() {

    }

}