Skip to content

Instantly share code, notes, and snippets.

@hitherejoe hitherejoe/ViewModel.kt Secret
Last active Sep 27, 2017

What would you like to do?
open class BrowseBufferoosViewModel @Inject internal constructor(
private val getBufferoos: GetBufferoos,
private val bufferooMapper: BufferooMapper) : ViewModel() {
private val bufferoosLiveData: MutableLiveData<Resource<List<BufferooView>>> =
override fun onCleared() {
fun getBufferoos(): LiveData<Resource<List<BufferooView>>> {
return bufferoosLiveData
fun fetchBufferoos() {
bufferoosLiveData.postValue(Resource(ResourceState.LOADING, null, null))
return getBufferoos.execute(BufferooSubscriber())
inner class BufferooSubscriber: DisposableSubscriber<List<Bufferoo>>() {
override fun onComplete() { }
override fun onNext(t: List<Bufferoo>) {
bufferoosLiveData.postValue(Resource(ResourceState.SUCCESS, { bufferooMapper.mapToView(it) }, null))
override fun onError(exception: Throwable) {
bufferoosLiveData.postValue(Resource(ResourceState.ERROR, null, exception.message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.