use of io.reactivex.functions.Consumer in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ViewPager pager = (ViewPager) findViewById(R.id.pager);
final MaterialTabs tabs = (MaterialTabs) findViewById(R.id.tabs);
observable = (Observable<PermissionRoster>) getLastNonConfigurationInstance();
if (observable == null) {
observable = Observable.create(new PermissionSource(this)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).cache();
}
sub = observable.subscribe(new Consumer<PermissionRoster>() {
@Override
public void accept(PermissionRoster roster) throws Exception {
pager.setAdapter(new PermissionTabAdapter(MainActivity.this, getFragmentManager(), roster));
tabs.setViewPager(pager);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable error) throws Exception {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
Log.e(getClass().getSimpleName(), "Exception processing request", error);
}
});
}
use of io.reactivex.functions.Consumer in project BigImageViewer by Piasy.
the class LongImageActivity method saveImage.
@SuppressWarnings("MissingPermission")
private void saveImage() {
disposePermissionRequest();
mPermissionRequest = new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
if (granted) {
mBigImageView.saveImageIntoGallery();
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});
}
use of io.reactivex.functions.Consumer in project RxJava by ReactiveX.
the class FlowableDoAfterNextTest method testIfFunctionThrowsThatNoMoreEventsAreProcessed.
@Test
public void testIfFunctionThrowsThatNoMoreEventsAreProcessed() {
final AtomicInteger count = new AtomicInteger();
final RuntimeException e = new RuntimeException();
Burst.items(1, 2).create().doAfterNext(new Consumer<Integer>() {
@Override
public void accept(Integer t) throws Exception {
count.incrementAndGet();
throw e;
}
}).test().assertError(e).assertValue(1);
assertEquals(1, count.get());
}
use of io.reactivex.functions.Consumer in project RxJava by ReactiveX.
the class ObservableSwitchIfEmptyTest method testSwitchWhenNotEmpty.
@Test
public void testSwitchWhenNotEmpty() throws Exception {
final AtomicBoolean subscribed = new AtomicBoolean(false);
final Observable<Integer> o = Observable.just(4).switchIfEmpty(Observable.just(2).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable s) {
subscribed.set(true);
}
}));
assertEquals(4, o.blockingSingle().intValue());
assertFalse(subscribed.get());
}
use of io.reactivex.functions.Consumer in project RxDownload by ssseasonnn.
the class DownloadType method startDownload.
public Observable<DownloadStatus> startDownload() {
return Flowable.just(1).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription subscription) throws Exception {
log(startLog());
record.start();
}
}).flatMap(new Function<Integer, Publisher<DownloadStatus>>() {
@Override
public Publisher<DownloadStatus> apply(Integer integer) throws Exception {
return download();
}
}).doOnNext(new Consumer<DownloadStatus>() {
@Override
public void accept(DownloadStatus status) throws Exception {
record.update(status);
}
}).doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
log(errorLog());
record.error();
}
}).doOnComplete(new Action() {
@Override
public void run() throws Exception {
log(completeLog());
record.complete();
}
}).doOnCancel(new Action() {
@Override
public void run() throws Exception {
log(cancelLog());
record.cancel();
}
}).doFinally(new Action() {
@Override
public void run() throws Exception {
log(finishLog());
record.finish();
}
}).toObservable();
}
Aggregations