view代码
class MvpActivity : BaseActivity<MvpPresenter>(), MvpContract.View {
// private val myPresenter:MvpPresenter by lifecycleScope.inject()
override fun initData(savedInstanceState: Bundle?) {
mPresenter = lifecycleScope.get<MvpPresenter>()
mPresenter?.getArticle()
}
override fun initView(savedInstanceState: Bundle?): Int = R.layout.activity_mvp
override fun showArticleBean(articleBean: ArticleBean) {
tvResult.text = articleBean.toString()
LogUtils.i(articleBean.errorCode)
}
}
presenter代码
class MvpPresenter(
view: MvpContract.View,
model: MvpContract.Model
) :
BasePresenter<MvpContract.View, MvpContract.Model>(view, model) {
fun getArticle() {
launch {
mRootView.showLoading()
val articleBean = mModel.getArticleBean()
mRootView.showArticleBean(articleBean)
}
}
}
model代码
class MvpModel(context: Context) : BaseModel(context), MvpContract.Model {
override suspend fun getArticleBean(): ArticleBean {
return apiService.getArticle()
}
}
需要额外引用框架
implementation 'com.yuanwanli:easymvp:0.0.1'
网友评论