Created
August 5, 2018 21:16
-
-
Save ShaishavGandhi/375ea279a5415fbc4e43b37a1220c09b to your computer and use it in GitHub Desktop.
With hot observable
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
package com.shaishavgandhi.rxreplayingsharesample | |
import android.content.res.Resources | |
import android.graphics.Bitmap | |
import androidx.annotation.RawRes | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.ViewModelProvider | |
import io.reactivex.Observable | |
class MainViewModel(private val repository: ImageRepository): ViewModel() { | |
fun image(): Observable<Bitmap> { | |
return repository.image() | |
} | |
fun loadImage(@RawRes imageId: Int) { | |
repository.loadImage(imageId) | |
} | |
class Factory(private val imageRepository: ImageRepository): ViewModelProvider.Factory { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | |
return MainViewModel(imageRepository) as T | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment