Search in sources :

Example 36 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.

the class CustomCheckbox method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    // noinspection ConstantConditions
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(colorIsDarkState -> invalidateColors(colorIsDarkState), onErrorLogAndRethrow()));
    ViewTextColorAction.create(this).accept(Color.BLACK);
}
Also used : Color(android.graphics.Color) Context(android.content.Context) ViewTextColorAction(com.afollestad.aesthetic.ViewTextColorAction) Aesthetic(com.afollestad.aesthetic.Aesthetic) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) AttributeSet(android.util.AttributeSet) Rx(com.afollestad.aesthetic.Rx) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) Observable(io.reactivex.Observable) AestheticCheckBox(com.afollestad.aesthetic.AestheticCheckBox) ColorIsDarkState(com.afollestad.aesthetic.ColorIsDarkState) ViewUtil(com.afollestad.aesthetic.ViewUtil) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 37 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable 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));
    }
}
Also used : Consumer(io.reactivex.functions.Consumer) ColorDrawable(android.graphics.drawable.ColorDrawable) BiFunction(io.reactivex.functions.BiFunction) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Pair(android.support.v4.util.Pair)

Example 38 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.

the class AestheticEditText method onAttachedToWindow.

@SuppressWarnings("ConstantConditions")
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
    subscriptions.add(ViewUtil.getObservableForResId(getContext(), textColorResId, Aesthetic.get(getContext()).textColorPrimary()).compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this), onErrorLogAndRethrow()));
    subscriptions.add(ViewUtil.getObservableForResId(getContext(), textColorHintResId, Aesthetic.get(getContext()).textColorSecondary()).compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewHintTextColorAction.create(this), onErrorLogAndRethrow()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 39 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.

the class AestheticTextInputLayout method onAttachedToWindow.

@SuppressWarnings("ConstantConditions")
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subs = new CompositeDisposable();
    subs.add(Aesthetic.get(getContext()).textColorSecondary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@NonNull Integer color) {
            TextInputLayoutUtil.setHint(AestheticTextInputLayout.this, adjustAlpha(color, 0.7f));
        }
    }, onErrorLogAndRethrow()));
    subs.add(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()).compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@NonNull Integer color) {
            invalidateColors(color);
        }
    }, onErrorLogAndRethrow()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 40 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.

the class AestheticRadioButton method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    // noinspection ConstantConditions
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
    subscriptions.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this)));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)81 Nullable (android.support.annotation.Nullable)15 Test (org.junit.Test)11 Bundle (android.os.Bundle)10 View (android.view.View)10 Consumer (io.reactivex.functions.Consumer)10 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 NonNull (android.support.annotation.NonNull)8 TextUtils (android.text.TextUtils)7 ViewGroup (android.view.ViewGroup)7 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)7 TextView (android.widget.TextView)6 BindView (butterknife.BindView)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Intent (android.content.Intent)5 LayoutInflater (android.view.LayoutInflater)5 Task (bolts.Task)5 TaskCompletionSource (bolts.TaskCompletionSource)5