package com.develop.base.mvvm

import android.os.Bundle
import android.view.LayoutInflater
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding

/**
 * viewModel绑定Aty生命周期
 */
abstract class BaseBVMActivity<VB : ViewBinding, VM : BaseViewModel> : BaseBindingActivity<VB>() {

    protected lateinit var viewModel: VM

    abstract fun createViewModel(): VM

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel = createViewModel()
        lifecycle.addObserver(viewModel)
    }

    override fun onDestroy() {
        super.onDestroy()
        lifecycle.removeObserver(viewModel)
    }
}