Search in sources :

Example 1 with SettingEvent

use of pri.weiqaing.common.rxbus.event.SettingEvent in project MyJapanese by 54wall.

the class SettingFragment method initPreference.

private void initPreference() {
    mUpdatePreference = getPreferenceManager().findPreference("setting_update");
    mUpdatePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Log.e(TAG, "mUpdatePreference");
            // 检查自动更新,默认UI
            return false;
        }
    });
    mTTSListPreference = (ListPreference) getPreferenceManager().findPreference("setting_tts");
    mTTSListPreference.setEntries(R.array.tts_entries);
    mTTSListPreference.setEntryValues(R.array.tts_values);
    mTTSListPreference.setValue(tts_type);
    mTTSListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.TTS_TYPE, (String) newValue);
            JpTTSUtils.getInstance().updateTtsType();
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.setting_effect)));
            return true;
        }
    });
    mThemesListPreference = (ListPreference) getPreferenceManager().findPreference("setting_theme");
    mThemesListPreference.setEntries(R.array.themes_entries);
    mThemesListPreference.setEntryValues(R.array.themes_values);
    mThemesListPreference.setValue(mode_theme);
    mThemesListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.MODE_THEME, (String) newValue);
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.reboot_to_take_effect)));
            return true;
        }
    });
}
Also used : ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) EventContainer(pri.weiqaing.common.rxbus.event.EventContainer) SettingEvent(pri.weiqaing.common.rxbus.event.SettingEvent)

Example 2 with SettingEvent

use of pri.weiqaing.common.rxbus.event.SettingEvent in project MyJapanese by 54wall.

the class MainActivityPresenterImpl method onBusEventInteraction.

@Override
public void onBusEventInteraction(EventContainer eventContainer) {
    Log.i(TAG, "onBusEventInteraction: " + eventContainer);
    switch(eventContainer.getType()) {
        case EventContainer.TYPE_PHOTOVIEW:
            PhotoViewEvent photoViewEvent = (PhotoViewEvent) eventContainer.getEvent();
            Bundle bundle = new Bundle();
            bundle.putString(Constants.IMG_URL, photoViewEvent.getImg_url());
            bundle.putInt(Constants.IMG_ID, photoViewEvent.getImg_id());
            view.startPhotoViewActivity(bundle);
            break;
        case EventContainer.TYPE_GAME:
            GameEvent gameEvent = (GameEvent) eventContainer.getEvent();
            switch(gameEvent.getType()) {
                case GameEvent.TYPE_PUZZLE:
                    view.startPuzzleActivity();
                    break;
                case GameEvent.TYPE_SUPPERZZLE:
                    view.startSupperzzleActivity();
                    break;
                default:
                    break;
            }
            break;
        case EventContainer.TYPE_SETTING:
            SettingEvent event = (SettingEvent) eventContainer.getEvent();
            view.showSnackBar(event.getMsg());
            break;
        default:
            break;
    }
}
Also used : Bundle(android.os.Bundle) SettingEvent(pri.weiqaing.common.rxbus.event.SettingEvent) PhotoViewEvent(pri.weiqaing.common.rxbus.event.PhotoViewEvent) GameEvent(pri.weiqaing.common.rxbus.event.GameEvent)

Example 3 with SettingEvent

use of pri.weiqaing.common.rxbus.event.SettingEvent in project LiYuJapanese by 54wall.

the class SettingActivity method initVariable.

@Override
protected void initVariable(@Nullable Bundle savedInstanceState) {
    if (!registered) {
        // RxBus
        subscription = RxBus.getDefault().toObserverable(EventContainer.class).subscribe(new Consumer<EventContainer>() {

            @Override
            public void accept(EventContainer eventContainer) throws Exception {
                if (eventContainer.getType() == EventContainer.TYPE_SETTING) {
                    SettingEvent event = (SettingEvent) eventContainer.getEvent();
                    showSnackBar(mRootLayout, event.getMsg());
                }
            }
        }, new Consumer<Throwable>() {

            @Override
            public void accept(Throwable throwable) throws Exception {
                Log.e(TAG, "Consumer<Throwable>:" + throwable.toString());
            }
        });
        registered = true;
    }
    initToolbar();
}
Also used : Consumer(io.reactivex.functions.Consumer) EventContainer(pri.weiqaing.common.rxbus.event.EventContainer) SettingEvent(pri.weiqaing.common.rxbus.event.SettingEvent)

Example 4 with SettingEvent

use of pri.weiqaing.common.rxbus.event.SettingEvent in project MyJapanese by 54wall.

the class ArticleDetailActivity method doAction.

@Override
protected void doAction() {
    Intent intent = getIntent();
    int id = intent.getIntExtra(Constants.FLAG_ZHIHU_ARTICLE_ID, 0);
    mToolbar.setTitle(intent.getStringExtra(Constants.FLAG_ZHIHU_ARTICLE_TITLE));
    // setSupportActionBar没有则标题和返回监听都无效
    setSupportActionBar(mToolbar);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    if (id != 0) {
        presenter.showContent(id);
    } else {
        RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.zhihu_fail_get_content)));
    }
}
Also used : EventContainer(pri.weiqaing.common.rxbus.event.EventContainer) SettingEvent(pri.weiqaing.common.rxbus.event.SettingEvent) Intent(android.content.Intent) ArticleDetailActivityView(pri.weiqiang.liyujapanese.mvp.view.zhihu.ArticleDetailActivityView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) WebView(android.webkit.WebView)

Example 5 with SettingEvent

use of pri.weiqaing.common.rxbus.event.SettingEvent in project MyJapanese by 54wall.

the class SettingActivity method initVariable.

@Override
protected void initVariable(@Nullable Bundle savedInstanceState) {
    if (!registered) {
        // RxBus
        subscription = RxBus.getDefault().toObserverable(EventContainer.class).subscribe(new Consumer<EventContainer>() {

            @Override
            public void accept(EventContainer eventContainer) throws Exception {
                if (eventContainer.getType() == EventContainer.TYPE_SETTING) {
                    SettingEvent event = (SettingEvent) eventContainer.getEvent();
                    showSnackBar(mRootLayout, event.getMsg());
                }
            }
        }, new Consumer<Throwable>() {

            @Override
            public void accept(Throwable throwable) throws Exception {
                Log.e(TAG, "Consumer<Throwable>:" + throwable.toString());
            }
        });
        registered = true;
    }
    initToolbar();
}
Also used : Consumer(io.reactivex.functions.Consumer) EventContainer(pri.weiqaing.common.rxbus.event.EventContainer) SettingEvent(pri.weiqaing.common.rxbus.event.SettingEvent)

Aggregations

SettingEvent (pri.weiqaing.common.rxbus.event.SettingEvent)8 EventContainer (pri.weiqaing.common.rxbus.event.EventContainer)6 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 ListPreference (android.preference.ListPreference)2 Preference (android.preference.Preference)2 View (android.view.View)2 WebView (android.webkit.WebView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Consumer (io.reactivex.functions.Consumer)2 GameEvent (pri.weiqaing.common.rxbus.event.GameEvent)2 PhotoViewEvent (pri.weiqaing.common.rxbus.event.PhotoViewEvent)2 ArticleDetailActivityView (pri.weiqiang.liyujapanese.mvp.view.zhihu.ArticleDetailActivityView)2