use of io.reactivex.CompletableEmitter in project SimpleCropView by IsseiAoki.
the class CropImageView method loadAsCompletable.
/**
* Load image from Uri with RxJava2
*
* @param sourceUri Image Uri
*
* @see #load(Uri)
*
* @return Completable of loading image
*/
public Completable loadAsCompletable(final Uri sourceUri, final boolean useThumbnail, final RectF initialFrameRect) {
return Completable.create(new CompletableOnSubscribe() {
@Override
public void subscribe(@NonNull final CompletableEmitter emitter) throws Exception {
mInitialFrameRect = initialFrameRect;
mSourceUri = sourceUri;
if (useThumbnail) {
applyThumbnail(sourceUri);
}
final Bitmap sampled = getImage(sourceUri);
mHandler.post(new Runnable() {
@Override
public void run() {
mAngle = mExifRotation;
setImageDrawableInternal(new BitmapDrawable(getResources(), sampled));
emitter.onComplete();
}
});
}
}).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
mIsLoading.set(true);
}
}).doFinally(new Action() {
@Override
public void run() throws Exception {
mIsLoading.set(false);
}
});
}
Aggregations