package com.orange.origin.origin

import android.app.Activity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.orange.origin.util.getVmClazz

abstract class BaseVMActivity<VM : BaseViewModel>:AppCompatActivity() {

    protected lateinit var iViewModel:VM
    protected lateinit var activity:Activity

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activity = this
        initDataBinding()

        iViewModel = createViewModel()
        createLooker()
        initDo()
        initUi()
        initData()
        initEvent()
    }

    private fun createViewModel():VM{
        return ViewModelProvider(this).get(getVmClazz(this))
    }

    protected open fun initDo(){

    }

    abstract fun getLayoutId():Int
    abstract fun initDataBinding()
    abstract fun createLooker()
    abstract fun initUi()
    abstract fun initData()
    abstract fun initEvent()
}