package com.hx.utils.application.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.viewbinding.ViewBinding

/**
 * author: hx
 * created on: 2024/12/6 13:28
 * description:
 */
abstract class BaseFragment<Binding : ViewBinding, VM : ViewModel> : Fragment() {
    private var _binding: Binding? = null
    protected val binding get() = _binding!!
    protected lateinit var viewModel: VM

    abstract fun setupViewModel()
    abstract fun setupView()
    abstract fun setupBinding(inflater: LayoutInflater, container: ViewGroup?): Binding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = setupBinding(inflater, container)
        setupViewModel()
        setupView()
        return binding.root
    }

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

}