MVP-VM实践

时间:2022-08-15 17:09:45
【文件属性】:

文件名称:MVP-VM实践

文件大小:402B

文件格式:TXT

更新时间:2022-08-15 17:09:45

MVP MVP-VM MVPVM

引入VIewModel 减轻对P对V的操作 protected fun vmProviders(modelClass: Class): T { val viewModel: BaseViewModel if (mContext is FragmentActivity || mContext is Fragment) { viewModel = if (mContext is BaseActivity) { ViewModelProviders.of(mContext as FragmentActivity).get(modelClass) } else { ViewModelProviders.of(mContext as Fragment).get(modelClass) } } else { viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(App.getInstance()).create(modelClass) } // 监听viewModel被销毁时 也销毁presenter viewModel.setClearedListener(object : BaseViewModel.ViewModelClearedListener { override fun onCleared() { onDestroy() } }) initCommon(viewModel) return viewModel


网友评论