Search in sources :

Example 1 with NightModeEvent

use of com.codeest.geeknews.model.event.NightModeEvent in project GeekNews by codeestX.

the class MainPresenter method registerEvent.

void registerEvent() {
    Subscription rxSubscription = RxBus.getDefault().toObservable(NightModeEvent.class).compose(RxUtil.<NightModeEvent>rxSchedulerHelper()).map(new Func1<NightModeEvent, Boolean>() {

        @Override
        public Boolean call(NightModeEvent nightModeEvent) {
            return nightModeEvent.getNightMode();
        }
    }).subscribe(new CommonSubscriber<Boolean>(mView, "切换模式失败ヽ(≧Д≦)ノ") {

        @Override
        public void onNext(Boolean aBoolean) {
            mView.useNightMode(aBoolean);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : NightModeEvent(com.codeest.geeknews.model.event.NightModeEvent) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 2 with NightModeEvent

use of com.codeest.geeknews.model.event.NightModeEvent in project GeekNews by codeestX.

the class SettingFragment method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    switch(compoundButton.getId()) {
        case R.id.cb_setting_night:
            if (isNull) {
                //防止夜间模式MainActivity执行reCreate后重复调用
                SharedPreferenceUtil.setNightModeState(b);
                NightModeEvent event = new NightModeEvent();
                event.setNightMode(b);
                RxBus.getDefault().post(event);
            }
            break;
        case R.id.cb_setting_image:
            SharedPreferenceUtil.setNoImageState(b);
            break;
        case R.id.cb_setting_cache:
            SharedPreferenceUtil.setAutoCacheState(b);
            break;
    }
}
Also used : NightModeEvent(com.codeest.geeknews.model.event.NightModeEvent)

Aggregations

NightModeEvent (com.codeest.geeknews.model.event.NightModeEvent)2 Subscription (rx.Subscription)1 Func1 (rx.functions.Func1)1