use of io.reactivex.functions.BiFunction in project Shuttle by timusus.
the class Aesthetic method resume.
/**
* Should be called in onResume() of each Activity.
*/
public void resume(@NonNull final AppCompatActivity activity) {
if (instance == null) {
return;
}
instance.context = activity;
if (instance.subs != null) {
instance.subs.clear();
}
instance.subs = new CompositeDisposable();
instance.subs.add(instance.colorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
Util.setTaskDescriptionColor(activity, color);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.activityTheme().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer themeId) {
if (getLastActivityTheme(activity) == themeId) {
return;
}
instance.lastActivityThemes.put(activity.getClass().getName(), themeId);
activity.recreate();
}
}, onErrorLogAndRethrow()));
instance.subs.add(Observable.combineLatest(instance.colorStatusBar(), instance.lightStatusBarMode(), new BiFunction<Integer, Integer, Pair<Integer, Integer>>() {
@Override
public Pair<Integer, Integer> apply(Integer integer, Integer integer2) {
return Pair.create(integer, integer2);
}
}).compose(Rx.<Pair<Integer, Integer>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, Integer>>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Pair<Integer, Integer> result) {
instance.invalidateStatusBar(activity);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.colorNavigationBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
setNavBarColorCompat(activity, color);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.colorWindowBackground().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
activity.getWindow().setBackgroundDrawable(new ColorDrawable(color));
}
}, onErrorLogAndRethrow()));
if (MaterialDialogsUtil.shouldSupport()) {
instance.subs.add(MaterialDialogsUtil.observe(instance));
}
}
use of io.reactivex.functions.BiFunction in project Shuttle by timusus.
the class AestheticCoordinatorLayout method onAttachedToWindow.
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
// Find the toolbar and color view used to blend the scroll transition
if (getChildCount() > 0 && getChildAt(0) instanceof AppBarLayout) {
appBarLayout = (AppBarLayout) getChildAt(0);
if (appBarLayout.getChildCount() > 0 && appBarLayout.getChildAt(0) instanceof CollapsingToolbarLayout) {
collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(0);
for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
if (this.toolbar != null && this.colorView != null) {
break;
}
View child = collapsingToolbarLayout.getChildAt(i);
if (child instanceof AestheticToolbar) {
this.toolbar = (AestheticToolbar) child;
} else if (child.getBackground() != null && child.getBackground() instanceof ColorDrawable) {
this.colorView = child;
}
}
}
}
if (toolbar != null && colorView != null) {
this.appBarLayout.addOnOffsetChangedListener(this);
toolbarColorSubscription = Observable.combineLatest(toolbar.colorUpdated(), Aesthetic.get(getContext()).colorIconTitle(toolbar.colorUpdated()), new BiFunction<Integer, ActiveInactiveColors, Pair<Integer, ActiveInactiveColors>>() {
@Override
public Pair<Integer, ActiveInactiveColors> apply(Integer integer, ActiveInactiveColors activeInactiveColors) {
return Pair.create(integer, activeInactiveColors);
}
}).compose(Rx.<Pair<Integer, ActiveInactiveColors>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, ActiveInactiveColors>>() {
@Override
public void accept(@NonNull Pair<Integer, ActiveInactiveColors> result) {
toolbarColor = result.first;
iconTextColors = result.second;
invalidateColors();
}
}, onErrorLogAndRethrow());
}
if (collapsingToolbarLayout != null) {
statusBarColorSubscription = Aesthetic.get(getContext()).colorStatusBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
collapsingToolbarLayout.setContentScrimColor(color);
collapsingToolbarLayout.setStatusBarScrimColor(color);
}
}, onErrorLogAndRethrow());
}
}
use of io.reactivex.functions.BiFunction in project Offer by woshiyizhijiao.
the class RxJavaActivity method zip1.
/**
* zip操作符
* 将上游的两个管道按顺序合并,合并的最终长度为管道事件最少的的管道。默认是在同一个线程中完成,想要同时进行,需要设置Schedulers.io()
*/
public void zip1(View v) {
Observable observable1 = Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
emitter.onNext(1);
LogUtils.e("onNext 1");
emitter.onNext(2);
LogUtils.e("onNext 2");
emitter.onNext(3);
LogUtils.e("onNext 3");
emitter.onNext(4);
LogUtils.e("onNext 4");
emitter.onComplete();
LogUtils.e("onComplete 1");
}
}).subscribeOn(Schedulers.io());
Observable observable2 = Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
emitter.onNext("A");
LogUtils.e("onNext A");
emitter.onNext("B");
LogUtils.e("onNext B");
emitter.onNext("C");
LogUtils.e("onNext C");
emitter.onComplete();
LogUtils.e("onComplete 2");
}
}).subscribeOn(Schedulers.io());
Observable.zip(observable1, observable2, new BiFunction<Integer, String, String>() {
@Override
public String apply(Integer integer, String s) throws Exception {
return integer + s;
}
}).subscribe(new Observer() {
@Override
public void onSubscribe(Disposable d) {
LogUtils.e("onSubscribe");
}
@Override
public void onNext(Object value) {
LogUtils.e("onNext : " + value);
}
@Override
public void onError(Throwable e) {
LogUtils.e("onError : ");
}
@Override
public void onComplete() {
LogUtils.e("onComplete : ");
}
});
}
Aggregations