package com.lukouguoji.module_base.base

import android.content.Context
import android.content.Intent
import androidx.lifecycle.ViewModel
import com.lukouguoji.module_base.interfaces.ILoading
import com.lukouguoji.module_base.model.LoadingModel
import dev.DevUtils

abstract class BaseViewModel : ViewModel(), ILoading {

    //加载弹窗
    protected var loadingModel: LoadingModel? = null

    open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

    }

    /**
     * 展示加载弹窗
     */
    override fun showLoading() {
        if (loadingModel == null) {
            createLoading(getTopActivity())
        }
        loadingModel?.showLoading()
    }

    override fun dismissLoading() {
        loadingModel?.dismissLoading()
    }

    fun getTopActivity() = DevUtils.getTopActivity()

    fun createLoading(context: Context = DevUtils.getTopActivity()) {
        loadingModel = LoadingModel(context)
    }
}