package com.grkj.iscs_mc.view.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.grkj.iscs_mc.view.dialog.LoadingProgressDialog

abstract class BaseFragment<T : ViewBinding?> : Fragment() {
    protected var mBinding: T? = null
    abstract val viewBinding: T
    private var loadingProgressDialog: LoadingProgressDialog? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = viewBinding
        return mBinding!!.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initView()
    }

    abstract fun initView()

    fun handleLoading(isShow: Boolean, progressStr: String? = null) {
        if (isShow) {
            loadingProgressDialog ?: let {
                loadingProgressDialog = context?.let { itCtx -> LoadingProgressDialog(itCtx) }
            }
            loadingProgressDialog?.show()
            loadingProgressDialog?.setProgress(progressStr)
        } else {
            loadingProgressDialog?.dismiss()
        }
    }
}