com.hwangjr.rxbus.RxBus Java Examples
The following examples show how to use
com.hwangjr.rxbus.RxBus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsFragment.java From a with GNU General Public License v3.0 | 6 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(getString(R.string.pk_ImmersionStatusBar)) || key.equals(getString(R.string.pk_navigationBarColorChange))) { settingActivity.initImmersionBar(); RxBus.get().post(RxBusTag.IMMERSION_CHANGE, true); } else if (key.equals(getString(R.string.pk_bookshelf_px)) || key.equals(getString(R.string.pk_bookshelf_show))) { RxBus.get().post(RxBusTag.REFRESH_BOOK_LIST, true); }else if (key.equals(getString(R.string.pk_bookshelf_space))) { RxBus.get().post(RxBusTag.RECREATE, true); }else if (key.equals("showAllFind")) { RxBus.get().post(RxBusTag.UPDATE_BOOK_SOURCE, true); }else if (key.equals(getString(R.string.pk_bookshelf_show))) { RxBus.get().post(RxBusTag.UPDATE_BOOK_SOURCE, false); } }
Example #2
Source File: UpdateBookListService.java From a with GNU General Public License v3.0 | 6 votes |
private synchronized void nextCheck() { checkIndex++; if (checkIndex > threadsNum) { String msg = String.format(getString(R.string.progress_show), checkIndex - threadsNum, recommendIndexBeanList.size()); RxBus.get().post(RxBusTag.CHECK_SOURCE_STATE, msg); updateNotification(checkIndex - threadsNum, msg); } if (checkIndex < recommendIndexBeanList.size()) { UpdateBookListTask checkSource = new UpdateBookListTask(recommendIndexBeanList.get(checkIndex), scheduler, updateBookListListener); checkSource.startCheck(); } else { if (checkIndex >= recommendIndexBeanList.size() + threadsNum - 1) { doneService(); } } }
Example #3
Source File: UpdateService.java From a with GNU General Public License v3.0 | 6 votes |
/** * 更新通知 */ private void updateNotification(int state) { RxBus.get().post(RxBusTag.UPDATE_APK_STATE, state); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MApplication.channelIdReadAloud) .setSmallIcon(R.drawable.ic_download) .setOngoing(true) .setContentTitle(getString(R.string.download_update)) .setContentText(String.format(getString(R.string.progress_show), state, 100)) .setContentIntent(getActivityPendingIntent()); builder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.cancel), getThisServicePendingIntent()); builder.setProgress(100, state, false); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Notification notification = builder.build(); int notificationId = 3425; startForeground(notificationId, notification); }
Example #4
Source File: MainPresenter.java From a with GNU General Public License v3.0 | 6 votes |
private void getBook(BookShelfBean bookShelfBean) { WebBookModel.getInstance() .getBookInfo(bookShelfBean) .flatMap(bookShelfBean1 -> WebBookModel.getInstance().getChapterList(bookShelfBean1)) .flatMap(chapterBeanList -> saveBookToShelfO(bookShelfBean, chapterBeanList)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new MyObserver<BookShelfBean>() { @Override public void onNext(BookShelfBean value) { if (value.getBookInfoBean().getChapterUrl() == null) { mView.toast("添加书籍失败"); } else { //成功 //发送RxBus RxBus.get().post(RxBusTag.HAD_ADD_BOOK, bookShelfBean); mView.toast("添加书籍成功"); } } @Override public void onError(Throwable e) { mView.toast("添加书籍失败" + e.getMessage()); } }); }
Example #5
Source File: CheckSourceService.java From a with GNU General Public License v3.0 | 6 votes |
private synchronized void nextCheck() { checkIndex++;if (checkIndex > threadsNum) { String msg = String.format(getString(R.string.progress_show), checkIndex - threadsNum, bookSourceBeanList.size()); RxBus.get().post(RxBusTag.CHECK_SOURCE_STATE, msg); updateNotification(checkIndex - threadsNum, msg); } if (checkIndex < bookSourceBeanList.size()) { CheckSourceTask checkSource = new CheckSourceTask(bookSourceBeanList.get(checkIndex), scheduler, checkSourceListener); checkSource.startCheck(); } else { if (checkIndex >= bookSourceBeanList.size() + threadsNum - 1) { doneService(); } } }
Example #6
Source File: ChapterListFragment.java From a with GNU General Public License v3.0 | 6 votes |
/** * 控件绑定 */ @Override protected void bindView() { super.bindView(); unbinder = ButterKnife.bind(this, view); rvList.setLayoutManager(layoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, isChapterReverse)); rvList.setItemAnimator(null); chapterListAdapter = new ChapterListAdapter(getContext(),bookShelf, chapterBeanList, (index, page) -> { if (index != bookShelf.getDurChapter()) { RxBus.get().post(RxBusTag.SKIP_TO_CHAPTER, new OpenChapterBean(index, page)); } if (getFatherActivity() != null) { getFatherActivity().searchViewCollapsed(); getFatherActivity().finish(); } }); if (bookShelf != null) { rvList.setAdapter(chapterListAdapter); updateIndex(bookShelf.getDurChapter()); updateChapterInfo(); } }
Example #7
Source File: WebBookModel.java From a with GNU General Public License v3.0 | 6 votes |
/** * 保存章节 */ @SuppressLint("DefaultLocale") private Observable<BookContentBean> saveContent(BookInfoBean infoBean, BaseChapterBean chapterBean, BookContentBean bookContentBean) { return Observable.create(e -> { bookContentBean.setNoteUrl(chapterBean.getNoteUrl()); if (isEmpty(bookContentBean.getDurChapterContent())) { e.onError(new Throwable("下载章节出错")); } else if (infoBean.isAudio()) { bookContentBean.setTimeMillis(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1)); DbHelper.getDaoSession().getBookContentBeanDao().insertOrReplace(bookContentBean); e.onNext(bookContentBean); } else if (BookshelfHelp.saveChapterInfo(infoBean.getName() + "-" + chapterBean.getTag(), chapterBean.getDurChapterIndex(), chapterBean.getDurChapterName(), bookContentBean.getDurChapterContent())) { RxBus.get().post(RxBusTag.CHAPTER_CHANGE, chapterBean); e.onNext(bookContentBean); } else { e.onError(new Throwable("保存章节出错")); } e.onComplete(); }); }
Example #8
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 6 votes |
@Override public void onDestroy() { running = false; super.onDestroy(); stopForeground(true); handler.removeCallbacks(dsRunnable); if("1".equals(replace)) { RxBus.get().post(RxBusTag.ALOUD_STATE, Status.STOPFORREPLACE); }else{ RxBus.get().post(RxBusTag.ALOUD_STATE, Status.STOP); } unRegisterMediaButton(); unregisterReceiver(broadcastReceiver); clearTTS(); }
Example #9
Source File: MyMainPresenter.java From a with GNU General Public License v3.0 | 6 votes |
private void getBook(BookShelfBean bookShelfBean) { WebBookModel.getInstance() .getBookInfo(bookShelfBean) .flatMap(bookShelfBean1 -> WebBookModel.getInstance().getChapterList(bookShelfBean1)) .flatMap(chapterBeanList -> saveBookToShelfO(bookShelfBean, chapterBeanList)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new MyObserver<BookShelfBean>() { @Override public void onNext(BookShelfBean value) { if (value.getBookInfoBean().getChapterUrl() == null) { mView.toast("添加书籍失败"); } else { //成功 //发送RxBus RxBus.get().post(RxBusTag.HAD_ADD_BOOK, bookShelfBean); mView.toast("添加书籍成功"); } } @Override public void onError(Throwable e) { mView.toast("添加书籍失败" + e.getMessage()); } }); }
Example #10
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 6 votes |
/** * @param pause true 暂停, false 失去焦点 */ private void pauseReadAloud(Boolean pause) { this.pause = pause; speak = false; updateNotification(); updateMediaSessionPlaybackState(); if (isAudio) { if (mediaPlayer != null && mediaPlayer.isPlaying()) mediaPlayer.pause(); } else { if (fadeTts) { AsyncTask.execute(() -> mediaManager.fadeOutVolume()); handler.postDelayed(() -> textToSpeech.stop(), 300); } else { textToSpeech.stop(); } } RxBus.get().post(RxBusTag.ALOUD_STATE, Status.PAUSE); }
Example #11
Source File: BookSourceManager.java From a with GNU General Public License v3.0 | 6 votes |
public static List<String> getGroupList() { List<String> groupList = new ArrayList<>(); String sql = "SELECT DISTINCT " + BookSourceBeanDao.Properties.BookSourceGroup.columnName + " FROM " + BookSourceBeanDao.TABLENAME; Cursor cursor = DbHelper.getDaoSession().getDatabase().rawQuery(sql, null); if (!cursor.moveToFirst()) return groupList; do { String group = cursor.getString(0); if (TextUtils.isEmpty(group) || TextUtils.isEmpty(group.trim())) continue; for (String item : group.split("\\s*[,;,;]\\s*")) { if (TextUtils.isEmpty(item) || groupList.contains(item)) continue; groupList.add(item); } } while (cursor.moveToNext()); Collections.sort(groupList); RxBus.get().post(RxBusTag.UPDATE_BOOK_SOURCE, new Object()); return groupList; }
Example #12
Source File: ReadBookPresenter.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void addToShelf(final OnAddListener addListener) { if (bookShelf != null) { AsyncTask.execute(() -> { BookshelfHelp.saveBookToShelf(bookShelf); RxBus.get().post(RxBusTag.HAD_ADD_BOOK, bookShelf); mView.setAdd(true); if (addListener != null) { addListener.addSuccess(); } }); } }
Example #13
Source File: Debug.java From a with GNU General Public License v3.0 | 5 votes |
static void printLog(String tag, int state, String msg, boolean print, boolean formatHtml) { if (print && Objects.equals(SOURCE_DEBUG_TAG, tag)) { if (formatHtml) { msg = StringUtils.formatHtml(msg); } if (state == 111) { msg = msg.replace("\n", ","); } msg = String.format("%s %s", getDoTime(), msg); RxBus.get().post(RxBusTag.PRINT_DEBUG_LOG, msg); } }
Example #14
Source File: UpLastChapterModel.java From a with GNU General Public License v3.0 | 5 votes |
private synchronized void doUpdate() { upIndex++; if (upIndex < searchBookBeanList.size()) { toBookshelf(searchBookBeanList.get(upIndex)) .flatMap(this::getChapterList) .flatMap(this::saveSearchBookBean) .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<SearchBookBean>() { @Override public void onSubscribe(Disposable d) { compositeDisposable.add(d); handler.postDelayed(() -> { if (!d.isDisposed()) { d.dispose(); doUpdate(); } }, 20 * 1000); } @Override public void onNext(SearchBookBean searchBookBean) { RxBus.get().post(RxBusTag.UP_SEARCH_BOOK, searchBookBean); doUpdate(); } @Override public void onError(Throwable e) { doUpdate(); } @Override public void onComplete() { } }); } }
Example #15
Source File: ImportBookPresenter.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void importBooks(List<File> books) { Observable.fromIterable(books) .flatMap(file -> ImportBookModel.getInstance().importBook(file)) .compose(RxUtils::toSimpleSingle) .subscribe(new Observer<LocBookShelfBean>() { @Override public void onSubscribe(Disposable d) { compositeDisposable.add(d); } @Override public void onNext(LocBookShelfBean value) { if (value.getNew()) { RxBus.get().post(RxBusTag.HAD_ADD_BOOK, value.getBookShelfBean()); } } @Override public void onError(Throwable e) { e.printStackTrace(); mView.addError(e.getMessage()); } @Override public void onComplete() { mView.addSuccess(); } }); }
Example #16
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); running = true; preference = MApplication.getConfigPreferences(); audioFocusChangeListener = new AudioFocusChangeListener(); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaManager = MediaManager.getInstance(); mediaManager.setStream(TextToSpeech.Engine.DEFAULT_STREAM); fadeTts = preference.getBoolean("fadeTTS", false); dsRunnable = this::doDs; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { initFocusRequest(); } initMediaSession(); initBroadcastReceiver(); mediaSessionCompat.setActive(true); updateMediaSessionPlaybackState(); updateNotification(); mpRunnable = new Runnable() { @Override public void run() { if (mediaPlayer != null) { RxBus.get().post(RxBusTag.AUDIO_DUR, mediaPlayer.getCurrentPosition()); } handler.postDelayed(this, 1000); } }; }
Example #17
Source File: SettingNestedFragment.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case ResultSelectBg: if (resultCode == RESULT_OK && null != data) { //Toast.makeText(getActivity(), data.getDataString(), Toast.LENGTH_SHORT).show(); String logoPath = FileUtils.getPath(getActivity(), data.getData()); MApplication.getInstance().setLogoPath(logoPath); // SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences(); //SharedPreferences.Editor editor = sharedPreferences.edit(); // editor.putString(getString(R.string.pk_logo_path), logoPath); // editor.apply(); final Preference logoPathPreference = findPreference(getString(R.string.pk_logo_path)); logoPathPreference.setSummary(logoPath); RxBus.get().post(RxBusTag.UPDATE_UI, true); } break; } }
Example #18
Source File: SettingNestedFragment.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(getString(R.string.pk_logo_title)) || key.equals(getString(R.string.pk_logo_title_align)) ) { RxBus.get().post(RxBusTag.UPDATE_UI, true); } }
Example #19
Source File: MBaseActivity.java From a with GNU General Public License v3.0 | 5 votes |
protected void setNightTheme(boolean isNightTheme) { preferences.edit() .putBoolean("nightTheme", isNightTheme) .apply(); MApplication.getInstance().initNightTheme(); MApplication.getInstance().upThemeStore(); RxBus.get().post(RxBusTag.RECREATE, true); }
Example #20
Source File: MBaseSimpleActivity.java From a with GNU General Public License v3.0 | 5 votes |
protected void setNightTheme(boolean isNightTheme) { preferences.edit() .putBoolean("nightTheme", isNightTheme) .apply(); MApplication.getInstance().initNightTheme(); MApplication.getInstance().upThemeStore(); RxBus.get().post(RxBusTag.RECREATE, true); }
Example #21
Source File: MediaButtonIntentReceiver.java From a with GNU General Public License v3.0 | 5 votes |
private static void readAloud(final Context context, String command) { if (!AppActivityManager.getInstance().isExist(MyReadBookActivity.class)) { Intent intent = new Intent(context, MyReadBookActivity.class); intent.putExtra("openFrom", ReadBookPresenter.OPEN_FROM_APP); intent.putExtra("readAloud", true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } } else { RxBus.get().post(RxBusTag.MEDIA_BUTTON, command); } }
Example #22
Source File: UpdateService.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroy() { super.onDestroy(); isRunning = false; if (disposableDown != null) { disposableDown.dispose(); } stopForeground(true); RxBus.get().post(RxBusTag.UPDATE_APK_STATE, -1); RxBus.get().unregister(this); }
Example #23
Source File: MyReadBookActivity.java From a with GNU General Public License v3.0 | 5 votes |
/** * 结束 */ @Override public void finish() { if (!checkAddShelf()) { return; } if (!AppActivityManager.getInstance().isExist(MyMainActivity.class)) { Intent intent = new Intent(this, MyMainActivity.class); startActivity(intent); } RxBus.get().post(RxBusTag.AUTO_BACKUP, true); super.finish(); }
Example #24
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 5 votes |
public void playTTSN() { if (contentList.size() < 1) { RxBus.get().post(RxBusTag.ALOUD_STATE, Status.NEXT); return; } if (ttsInitSuccess && !speak && requestFocus()) { speak = !speak; RxBus.get().post(RxBusTag.ALOUD_STATE, Status.PLAY); updateNotification(); initSpeechRate(); initSpeechPitch(); HashMap<String, String> map = new HashMap<>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "content"); for (int i = nowSpeak; i < contentList.size(); i++) { if (i == 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { textToSpeech.speak(contentList.get(i), TextToSpeech.QUEUE_FLUSH, null, "content"); } else { textToSpeech.speak(contentList.get(i), TextToSpeech.QUEUE_FLUSH, map); } } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { textToSpeech.speak(contentList.get(i), TextToSpeech.QUEUE_ADD, null, "content"); } else { textToSpeech.speak(contentList.get(i), TextToSpeech.QUEUE_ADD, map); } } } } }
Example #25
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 5 votes |
/** * 恢复朗读 */ private void resumeReadAloud() { updateTimer(0); pause = false; updateNotification(); if (isAudio) { if (mediaPlayer != null && !mediaPlayer.isPlaying()) mediaPlayer.start(); } else { playTTS(); } RxBus.get().post(RxBusTag.ALOUD_STATE, Status.PLAY); }
Example #26
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 5 votes |
/** * 更新通知 */ private void updateNotification() { if (text == null) text = getString(R.string.read_aloud_s); String nTitle; if (pause) { nTitle = getString(R.string.read_aloud_pause); } else if (timeMinute > 0 && timeMinute <= 60) { nTitle = getString(R.string.read_aloud_timer, timeMinute); } else { nTitle = getString(R.string.read_aloud_t); } nTitle += ": " + title; RxBus.get().post(RxBusTag.ALOUD_TIMER, nTitle); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MApplication.channelIdReadAloud) .setSmallIcon(R.drawable.ic_volume_up) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_read_book)) .setOngoing(true) .setContentTitle(nTitle) .setContentText(text) .setContentIntent(getReadBookActivityPendingIntent()); if (pause) { builder.addAction(R.drawable.ic_play_24dp, getString(R.string.resume), getThisServicePendingIntent(ActionResumeService)); } else { builder.addAction(R.drawable.ic_pause_24dp, getString(R.string.pause), getThisServicePendingIntent(ActionPauseService)); } builder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.stop), getThisServicePendingIntent(ActionDoneService)); builder.addAction(R.drawable.ic_time_add_24dp, getString(R.string.set_timer), getThisServicePendingIntent(ActionSetTimer)); builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle() .setMediaSession(mediaSessionCompat.getSessionToken()) .setShowActionsInCompactView(0, 1, 2)); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Notification notification = builder.build(); startForeground(notificationId, notification); }
Example #27
Source File: UpdateService.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); isRunning = true; //创建 Notification.Builder 对象 updateNotification(0); RxBus.get().register(this); }
Example #28
Source File: ReadAloudService.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void onDone(String s) { readAloudNumber = readAloudNumber + contentList.get(nowSpeak).length() + 1; nowSpeak = nowSpeak + 1; if (nowSpeak >= contentList.size()) { RxBus.get().post(RxBusTag.ALOUD_STATE, Status.NEXT); } }
Example #29
Source File: SelectSourceDialog.java From a with GNU General Public License v3.0 | 5 votes |
public void saveDate(List<BookSourceBean> bookSourceBeans) { AsyncTask.execute(() -> { DbHelper.getDaoSession().getBookSourceBeanDao().insertOrReplaceInTx(bookSourceBeans); }); RxBus.get().post(RxBusTag.SOURCE_LIST_CHANGE, true); }
Example #30
Source File: MBaseActivity.java From a with GNU General Public License v3.0 | 5 votes |
protected void setNightTheme(boolean isNightTheme) { preferences.edit() .putBoolean("nightTheme", isNightTheme) .apply(); MApplication.getInstance().initNightTheme(); MApplication.getInstance().upThemeStore(); RxBus.get().post(RxBusTag.RECREATE, true); }