Created
December 13, 2020 14:36
-
-
Save jobinlawrance/01f3bb8249b87cd3f8558303220587a8 to your computer and use it in GitHub Desktop.
HomeViewModel and HomeInteractor
This file contains hidden or 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
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