Skip to content

Instantly share code, notes, and snippets.

@jobinlawrance
Created December 13, 2020 14:36
Show Gist options
  • Save jobinlawrance/01f3bb8249b87cd3f8558303220587a8 to your computer and use it in GitHub Desktop.
Save jobinlawrance/01f3bb8249b87cd3f8558303220587a8 to your computer and use it in GitHub Desktop.
HomeViewModel and HomeInteractor
class HomeViewModel(val homeInteractor: HomeInteractor) {
private val resultLiveData = MutableLiveData<Result<String>>()
fun getResultFromApi(): LiveData<Result<String>> {
homeInteractor.getResultFromApi()
.startWith(Result.InProgress)
.subscribe({ someString ->
resultLiveData.value = Result.Success(someString)
}, { err ->
resultLiveData.value = Result.Error(err)
}) //Handle the disposing
return resultLiveData
}
}
class HomeInteractor(val apiService: ApiService) {
homeInteractor.getResultFromApi(): Observable<String>
= apiService.getResult()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment