Skip to content

Commit

Permalink
更改回调名
Browse files Browse the repository at this point in the history
  • Loading branch information
Reginer committed Apr 24, 2022
1 parent 3e38dd5 commit 51cb1c6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ maven { url 'https://jitpack.io' }
```

```
implementation 'com.github.Reginer:MVVMHub:2.1.3'
implementation 'com.github.Reginer:MVVMHub:2.1.4'
```

登录:
Expand All @@ -29,14 +29,14 @@ class LoginActivity : BaseVmActivity() {
override fun createObserver() {
mViewModel.loginResult.vmObserver(this) {
onAppLoading { showProgress() }
onAppSuccess { mViewModel.saveUser(it);finish() }
onAppError { Logger.e(it.errorMsg);Logger.e(" error code is:::" + it.errorCode) }
onAppComplete { dismissProgress() }
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) {
// onAppSuccess { mViewModel.saveUser(it);finish() }
// onSuccess { mViewModel.saveUser(it);finish() }
// }
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ dependencies {
androidTestImplementation(MvvmExt.espresso)
implementation project(path: ':base')
implementation(MvvmExt.viewBinding)
// releaseImplementation 'com.github.Reginer:MVVMHub:2.1.3'
// releaseImplementation 'com.github.Reginer:MVVMHub:2.1.4'
}
8 changes: 4 additions & 4 deletions app/src/main/java/win/regin/mvvm/ui/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class LoginActivity : BaseVmActivity() {
override fun createObserver() {

mViewModel.loginResult.vmObserver(this) {
onAppLoading { showProgress() }
onAppSuccess { mViewModel.saveUser(it);finish() }
onAppError { Logger.e(it.errorMsg);Logger.e(" error code is:::" + it.errorCode) }
onAppComplete { dismissProgress() }
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) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/win/regin/mvvm/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MainActivity : BaseVmActivity() {
it?.let { mViewModel.getArticle(0) }
}
mViewModel.articleResult.vmObserver(this) {
onAppSuccess { mViewModel.parseArticleData(it) }
onSuccess { mViewModel.parseArticleData(it) }
}
mViewModel.articleLiveData.observe(this) {
mViewBinding.content.text = it.toJsonString()
Expand Down
6 changes: 3 additions & 3 deletions base/src/main/java/win/regin/base/ext/MvvmExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ inline fun <T> VmLiveData<T>.vmObserver(owner: LifecycleOwner, vmResult: VmResul
val result = VmResult<T>();result.vmResult();observe(owner = owner) {
when (it) {
is VmState.Loading -> {
result.onAppLoading()
result.onLoading()
}
is VmState.Success -> {
result.onAppSuccess(it.data);result.onAppComplete()
result.onSuccess(it.data);result.onComplete()
}
is VmState.Error -> {
result.onAppError(it.error);result.onAppComplete()
result.onError(it.error);result.onComplete()
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions base/src/main/java/win/regin/base/ext/ViewState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ import win.regin.base.exception.AppException
*/

class VmResult<T> {
var onAppSuccess: (data: T) -> Unit = {}
var onAppError: (AppException) -> Unit = {}
var onAppLoading: () -> Unit = {}
var onAppComplete: () -> Unit = {}
var onSuccess: (data: T) -> Unit = {}
var onError: (AppException) -> Unit = {}
var onLoading: () -> Unit = {}
var onComplete: () -> Unit = {}

fun onAppSuccess(success: (T) -> Unit) {
onAppSuccess = success
fun onSuccess(success: (T) -> Unit) {
onSuccess = success
}

fun onAppError(error: (AppException) -> Unit) {
onAppError = error
fun onError(error: (AppException) -> Unit) {
onError = error
}

fun onAppLoading(loading: () -> Unit) {
onAppLoading = loading
fun onLoading(loading: () -> Unit) {
onLoading = loading
}

fun onAppComplete(complete: () -> Unit) {
onAppComplete = complete
fun onComplete(complete: () -> Unit) {
onComplete = complete
}
}

Expand Down

0 comments on commit 51cb1c6

Please sign in to comment.