GithubHelp home page GithubHelp logo

mvvmhub's Introduction

MVVMHub

maven { url 'https://jitpack.io' }
implementation 'com.github.Reginer:MVVMHub:2.1.11'

登录:

class LoginActivity : BaseVmActivity() {

    private val mViewModel by viewModels<LoginViewModel>()
    private val mViewBinding by viewBinding(ActivityLoginBinding::bind)

    override val layoutId: Int get() = R.layout.activity_login


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding.login.setOnClickListener { mViewModel.login(mViewBinding.username.text(), mViewBinding.pwd.text()) }
    }

    override fun createObserver() {

        mViewModel.loginResult.vmObserver(this) {
            onLoading { showProgress() }
            onSuccess { mViewModel.saveUser(it);finish() }
            onError { Logger.e(it.errorMsg);Logger.e("  error code is:::" + it.errorCode) }
            onComplete { dismissProgress() }
        }
        //可以只取成功回调
//        mViewModel.loginResult.vmObserver(this) {
//            onSuccess { mViewModel.saveUser(it);finish() }
//        }
    }
}
class LoginViewModel : BaseViewModel() {
    private val loginRepository by lazy { LoginRepository() }
    val loginResult: VmLiveData<UserEntity> = MutableLiveData()

    fun login(username: String, password: String) {
        launchVmRequest({ loginRepository.login(username, password) }, loginResult)
    }

    fun saveUser(userEntity: UserEntity) {
        loginRepository.insertUser(userEntity)
    }
}

License

MIT License

Copyright (c) 2019 鼎鼎鼎

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

mvvmhub's People

Contributors

reginer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mvvmhub's Issues

催更

写的很好,可惜等你写完的下一秒就是我的了
Ps:
1.buildSrc是干嘛的
2.common准备写啥,为什么是空白的

刚哥,我发现ViewState使用起来缺乏灵活性

一般情况下是很方便,但是在某些情况下需要扩展,实际使用中感觉sealed写法缺乏扩展性。
一开始我的解决方案是:
另外再开一个,和网络请求的State独立开
image

但是我发现某些情况下我需要合在网络请求的State里面一起通知activity:
比如我分页的时候我需要在返回数据的同时告诉Activity这是刷新的数据还是加载更多的数据(isRefresh),如果按照上面的独立开得方案,总觉得不太对劲,感觉会在某些情况下产生bug。

isRefresh类似的参数添加方式:
如果为了一个参数重新写一个通用的PageViewState感觉不划算,因为有很多相同部分,而且相关扩展也要对应写一份。
或者直接在原有的State上面加一个很多时候用不到的参数感觉也不是太舒服,如果之后还有其他的参数岂不是越加越多?

刚哥给点意见?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.