Last active
September 4, 2019 12:33
-
-
Save LukaKordic/a6cc33da48fa5440e1477bf46f27e8b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseViewModel<T : Any, E> : ViewModel(), KoinComponent { | |
protected val coroutineContext: CoroutineContextProvider by inject() | |
private val connectivity: Connectivity by inject() | |
protected val _viewState = MutableLiveData<ViewState<T>>() | |
val viewState: LiveData<ViewState<T>> | |
get() = _viewState | |
protected val _viewEffects = MutableLiveData<E>() | |
val viewEffects: LiveData<E> | |
get() = _viewEffects | |
protected fun executeUseCase(action: suspend () -> Unit, noInternetAction: () -> Unit) { | |
_viewState.value = Loading() | |
if (connectivity.hasNetworkAccess()) { | |
launch { action() } | |
} else { | |
noInternetAction() | |
} | |
} | |
protected fun executeUseCase(action: suspend () -> Unit) { | |
_viewState.value = Loading() | |
launch { action() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment