package com.rdiot.yx485.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment

/**
 *
 * @author mR2hao
 * @date 2021/8/2
 */
abstract class BaseFragment<TBinding : ViewDataBinding> : Fragment() {

//    @Inject
//    lateinit var appData: AppData

    lateinit var act: BaseActivity<TBinding>

    protected abstract fun getLayoutId(): Int

    /**
     * 初始化界面元素和成员变量
     * */
    protected abstract fun initView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    )

    private var _binding: TBinding? = null

    val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        act = requireActivity() as BaseActivity<TBinding>

        _binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false)
        binding.lifecycleOwner = viewLifecycleOwner

        initView(inflater, container, savedInstanceState)//初始化界面元素和成员变量

        return binding.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }


}