Created
August 5, 2018 18:52
-
-
Save ShaishavGandhi/e0bce62aa5ea9d962219fe3072a21cea to your computer and use it in GitHub Desktop.
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.lifecycle.ViewModel | |
import androidx.lifecycle.ViewModelProvider | |
import io.reactivex.Observable | |
class MainViewModel(private val repository: ImageRepository): ViewModel() { | |
fun loadBitmap(imageId: Int): Observable<Bitmap> { | |
return repository.loadImage(imageId) | |
} | |
// Custom factory to pass ImageRepository to MainViewModel's constructor. | |
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