Android 组件化

Android-MVVM-Architecture(Databi

2020-04-30  本文已影响0人  LuckySuperMan

Android-MVVM-Architecture 简介

该项目是采用kotlin编写,结合Jetpack架构组件(Databinding 、ViewModel 、LiveData)+Retrofit+协程搭建的项目框架。

特点

主要是封装网络请求模块(统一处理服务器返回异常、showLoading、dissmissLoading),
只需要在viewModel中调用launchOnlyResult()方法

class ArticleListViewModel : BaseViewModel() {

    var articleList = MutableLiveData<HomeListBean>()

    private val articleRepository by lazy { InjectorUtil.getArticleRepository() }

    fun getArticleList(page: Int) {
        launchOnlyResult(
            {
                articleRepository.getArticleList(page)
            },
            {
                articleList.value = it
            },
            complete = {
                defUI.refreshFinishEvent.call()
            },
            isShowDialog = false
        )
    }
}

项目地址

https://github.com/ning767566973/Android-MVVM-Architecture

上一篇下一篇

猜你喜欢

热点阅读