Skip to content

Instantly share code, notes, and snippets.

@ShaishavGandhi
Last active August 5, 2018 18:42
Show Gist options
  • Save ShaishavGandhi/20cd928557b2ce8e46fa4a0f8c9217a3 to your computer and use it in GitHub Desktop.
Save ShaishavGandhi/20cd928557b2ce8e46fa4a0f8c9217a3 to your computer and use it in GitHub Desktop.
package com.shaishavgandhi.rxreplayingsharesample
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.annotation.RawRes
import io.reactivex.Observable
class ImageRepository(private val resources: Resources) {
fun loadImage(@RawRes imageId: Int): Observable<Bitmap> {
return Observable.fromCallable {
// Use BitmapFactory to get Bitmap from a raw resource
return@fromCallable BitmapFactory.decodeStream(resources.openRawResource(imageId))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment