org.greenrobot.eventbus.Subscribe Java Examples
The following examples show how to use
org.greenrobot.eventbus.Subscribe.
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: MyArticleFragment.java From tysq-android with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void articleHideStatusChange(HideArticleEvent event){ int articleIndex = -1; for (int i = 0; i < mData.size(); i++){ MyArticleResp.ArticlesInfoBean item = mData.get(i); if (item.getId().equals(event.getAccountId())){ articleIndex = i; break; } } if (articleIndex == -1){ return; } mData.get(articleIndex).setStatus(event.getStatu()); //头部坐标 int headPos = (isNeedHeader ? 1 : 0); //刷新头部坐标 int refreshPos = (isNeedRefresh ? 1 : 0); int realIndex = articleIndex + headPos + refreshPos; mBaseAdapter.notifyItemChanged(realIndex); }
Example #2
Source File: MainActivity.java From pe-protector-moe with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onResChange(EventBusUtil util) { // 刷新界面信息 if (util.getCode() == EVENT_RES_CHANGE) { try { TextView textView = findViewById(R.id.tv_username); textView.setText(userData.userBaseData.friendVo.username); textView = findViewById(R.id.tv_sign); textView.setText(userData.userBaseData.friendVo.sign); CircleImageView imageView = findViewById(R.id.img_mine); Bitmap b = FileUtil.getImageFromAssetsFile("html/images/head/" + userData.userBaseData.friendVo.avatar_cid + ".png"); imageView.setImageBitmap(b); } catch (Exception e) { } } }
Example #3
Source File: EnterCodeFragment.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onVerificationCodeReceived(@NonNull ReceivedSmsEvent event) { verificationCodeView.clear(); List<Integer> parsedCode = convertVerificationCodeToDigits(event.getCode()); autoCompleting = true; final int size = parsedCode.size(); for (int i = 0; i < size; i++) { final int index = i; verificationCodeView.postDelayed(() -> { verificationCodeView.append(parsedCode.get(index)); if (index == size - 1) { autoCompleting = false; } }, i * 200); } }
Example #4
Source File: RestoreBackupFragment.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(@NonNull FullBackupBase.BackupEvent event) { int count = event.getCount(); if (count == 0) { restoreBackupProgress.setText(R.string.RegistrationActivity_checking); } else { restoreBackupProgress.setText(getString(R.string.RegistrationActivity_d_messages_so_far, count)); } setSpinning(restoreButton); skipRestoreButton.setVisibility(View.INVISIBLE); if (event.getType() == FullBackupBase.BackupEvent.Type.FINISHED) { Navigation.findNavController(requireView()) .navigate(RestoreBackupFragmentDirections.actionBackupRestored()); } }
Example #5
Source File: MainActivity.java From Focus with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void refreshUI(EventMessage eventBusMessage) { if (EventMessage.feedAndFeedFolderAndItemOperation.contains(eventBusMessage.getType())) {//更新整个左侧边栏 // ALog.d("收到新的订阅添加,更新!" + eventBusMessage); new Handler().postDelayed(new Runnable() { @Override public void run() { ALog.d("重构"); updateDrawer(); } }, 100); // 延迟一下,因为数据异步存储需要时间 }else if (EventMessage.updateBadge.contains(eventBusMessage.getType())){//只需要修改侧边栏阅读书目 new Handler().postDelayed(new Runnable() { @Override public void run() { //打印map ALog.d("更新左侧边栏"); updateDrawer(); } }, 100); // 延迟一下,因为数据异步存储需要时间 } else if (Objects.equals(eventBusMessage.getType(), EventMessage.FEED_PULL_DATA_ERROR)) { // ALog.d("收到错误FeedId List"); // errorFeedIdList = eventBusMessage.getIds(); } }
Example #6
Source File: MainActivity.java From tysq-android with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void update(NotificationUpdateEvent event) { MenuItemVO menuItemVO = TyFragmentManager.getMainNav().get(2); // 我的 if (menuItemVO != null) { menuItemVO.setNotifyNum(event.getCount()); TabLayout.Tab tab = tabLayout.getTabAt(2); if (tab == null) { return; } MainNavTabItem mainNavTabItem = (MainNavTabItem) tab.getCustomView(); if (mainNavTabItem == null) { return; } mainNavTabItem.updateNotificationNum(); } }
Example #7
Source File: MyFansFragment.java From tysq-android with GNU General Public License v3.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void attentionChange(AttentionEvent event) { int attentionIndex = -1; for (int i = 0; i < mData.size(); i++) { MyFansListResp.AttentionInfoBean item = mData.get(i); if (item.getAccountId() == event.getAccountId()) { attentionIndex = i; break; } } if (attentionIndex == -1) { return; } mData.get(attentionIndex).setFollow(event.getIsFollow()); //头部坐标 int headPos = (isNeedHeader ? 1 : 0); //刷新头部坐标 int refreshPos = (isNeedRefresh ? 1 : 0); int realIndex = attentionIndex + headPos + refreshPos; mBaseAdapter.notifyItemChanged(realIndex); }
Example #8
Source File: ChartActivity.java From InteractiveChart with Apache License 2.0 | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onPush(ServiceMessage msg) { if (null == msg) { return; } switch (msg.getWhat()) { case PushService.CANDLE: CandleEntry candleEntry = (CandleEntry) msg.getEntry(); if (null != candleEntry) { candleAdapter.dataPush(candleEntry); } break; case PushService.DEPTH: break; } }
Example #9
Source File: FragmentSingleIllust.java From Pixiv-Shaft with MIT License | 6 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(Channel event) { if (event.getReceiver().contains("FragmentSingleIllust starIllust")) { if (illust.getId() == (int) event.getObject()) { illust.setIs_bookmarked(true); ((FloatingActionButton) parentView.findViewById(R.id.post_like)) .setImageResource(R.drawable.ic_favorite_accent_24dp); } } if (event.getReceiver().equals("FragmentSingleIllust download finish")) { if ((int) event.getObject() == illust.getId()) { baseBind.download.setImageResource(R.drawable.ic_has_download); } } }
Example #10
Source File: MineFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void update(NotificationUpdateEvent event) { if (event.getCount() <= 0) { tvNotification.setVisibility(View.GONE); return; } tvNotification.setVisibility(View.VISIBLE); tvNotification.setText(String.valueOf(event.getCount())); }
Example #11
Source File: BaseMainFragment.java From v9porn with MIT License | 5 votes |
/** * 尝试释放内存,因为我们使用的是FragmentPagerAdapter,导致即使页面不可见也不会释放内存,好处在于返回该页面时所有状态视图会保持为之前的状态 */ @Subscribe(threadMode = ThreadMode.MAIN) public void onTryToReleaseMemory(LowMemoryEvent lowMemoryEvent) { //有可能已经被回收或者还没创建(概率) if (!isBackground || categoryList == null || fragmentManager == null || viewPager == null || mBaseMainFragmentAdapter == null) { return; } if (!BuildConfig.DEBUG) { //Bugsnag.notify(new Throwable(TAG + ":LowMemory,try to release some memory now!"), Severity.INFO); } try { Logger.t(TAG).d("start try to release memory ...."); FragmentTransaction mCurTransaction = fragmentManager.beginTransaction(); //获取当前不可见的fragment,并尝试释放掉它们来释放内存,但同时会导致切换回该页面时所有状态均没有了,会被重新创建 for (int i = 0; i < categoryList.size(); i++) { //尝试移除不可见的fragment if (i < currentSelectPosition - 1 || i > currentSelectPosition + 1) { long itemId = mBaseMainFragmentAdapter.getItemId(i); String name = FragmentUtils.makeFragmentName(viewPager.getId(), itemId); Fragment fragment = fragmentManager.findFragmentByTag(name); if (fragment != null) { mCurTransaction.remove(fragment); } } } mCurTransaction.commitNowAllowingStateLoss(); //通知系统尝试释放内存 System.gc(); System.runFinalization(); Logger.t(TAG).d("try to release memory success !!!"); } catch (Exception e) { e.printStackTrace(); if (!BuildConfig.DEBUG) { //Bugsnag.notify(new Throwable(TAG + " tryToReleaseMemory error::", e), Severity.WARNING); } } }
Example #12
Source File: MainActivity.java From landlord_client with Apache License 2.0 | 5 votes |
/** * 玩家信息反馈 */ @Subscribe(threadMode = ThreadMode.MAIN) public void onUserInfoResponse(UserInfoResponse response) { if(response.getUserName().equals(SharedPreferencesUtil.getUsername())) { win.append(response.getWin()); SharedPreferencesUtil.saveWin(response.getWin()); lose.append(response.getLose()); SharedPreferencesUtil.saveLose(response.getLose()); money.append(response.getMoney()); SharedPreferencesUtil.saveMoney(response.getMoney()); } }
Example #13
Source File: BitBaseActivity.java From tysq-android with GNU General Public License v3.0 | 5 votes |
/** * 进行关闭页面 */ @Subscribe(threadMode = ThreadMode.MAIN) public void onClose(CloseEvent closeEvent) { if (isSameView(closeEvent.getViewId())) { finish(); } }
Example #14
Source File: CloudListFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void addItem(UploadUpdateEvent event) { for (FileInfoResp.FileItem fileItem : mData) { // 如果列表中已经有id是相同的,则不添加 if (fileItem.getId() == event.getFileItem().getId()) { return; } } mStart = 0; loadData(true); }
Example #15
Source File: CloudUploadingFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public synchronized void removeItem(UploadUpdateEvent event) { int index = -1; for (int i = 0; i < mData.size(); i++) { FileModel fileModel = mData.get(i); // 如果列表中已经有id是相同的,则不添加 if (fileModel.getUrl().equals(event.getFileModel().getUrl()) && fileModel.getFilename().equals(event.getFileModel().getFilename())) { index = i; } } if (index == -1) { return; } mData.remove(index); mBaseAdapter.notifyItemRemoved(index); if (mData.size() == 0) { mBaseAdapter.onEmpty(); } updateCount(); }
Example #16
Source File: GameActivity.java From landlord_client with Apache License 2.0 | 5 votes |
/** * 最终确认的加倍请求 */ @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) @SuppressWarnings("unused") public void onMultipleWagerResponse(MultipleWagerResponse response) { EventBus.getDefault().removeStickyEvent(response); wagerMultipleNum = response.getMultipleNum(); doubleNum.setText(String.format("当前倍数是:%s", wagerMultipleNum)); if (meSeatNum == landlordSeatNum) { //我是地主,我先出牌 throwCards(true); } else { //我不是地主,我等上家出牌 gone(meStatusChoose); } }
Example #17
Source File: GameActivity.java From landlord_client with Apache License 2.0 | 5 votes |
/** * 处理新玩家进入房间 */ @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) @SuppressWarnings("unused") public void onEnterTableResponse(EnterTableResponse response) { EventBus.getDefault().removeStickyEvent(response); if (response.isSuccess()) { tablePlayers = response.getTablePlayers(); for (Map.Entry<Integer, String> tmp : tablePlayers.entrySet()) { if (tmp.getValue().equals(SharedPreferencesUtil.getUsername())) meSeatNum = tmp.getKey(); } refreshPlayers(); } }
Example #18
Source File: CloudDownloadFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void addItem(DownloadAddEvent event) { for (CloudDownloadVO item : mData) { DownloadInfo downloadInfo = item.getDownloadInfo(); if (downloadInfo == null) { continue; } downloadInfo.removeListener(); } getFirstData(LoadType.CUSTOM); }
Example #19
Source File: HallFragment.java From landlord_client with Apache License 2.0 | 5 votes |
/** * 接收游戏大厅聊天信息 */ @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void onChatMsgResponse(ChatMsgResponse response) { if (response.getChatFlag() == 1 && tvMessage != null && etSend != null) { tvMessage.append("\n" + response.getUserName() + " 说:" + response.getMsg()); etSend.setText(""); } }
Example #20
Source File: ArticleExamFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onUpdateExamList(ExamOverEvent event) { int index = -1; for (int i = 0; i < mData.size(); i++) { ReviewArticleListResp.ReviewArticlesBean articleInfo = mData.get(i); if (articleInfo.getArticleId() == null) { continue; } if (articleInfo.getArticleId().equals(event.getArticleId())) { index = i; break; } } if (index == -1) { return; } mTitleCountVO.reduceTotal(); mData.remove(index); mBaseAdapter.notifyItemChanged(1); mBaseAdapter.notifyItemRemoved(2 + index); }
Example #21
Source File: BitBaseFragment.java From tysq-android with GNU General Public License v3.0 | 5 votes |
/** * 进行关闭页面 */ @Subscribe(threadMode = ThreadMode.MAIN) public void onClose(CloseEvent closeEvent) { if (isSameView(closeEvent.getViewId()) && getActivity() != null) { getActivity().finish(); } }
Example #22
Source File: BaseAppCompatActivity.java From v9porn with MIT License | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void checkGoogleRecaptcha(NeedCheckGoogleRecaptchaEvent needCheckGoogleRecaptchaEvent) { if (needGoToCheckGoogleRecaptcha()) { Intent intent = new Intent(this, GoogleRecaptchaVerifyActivity.class); startActivityWithAnimation(intent); } }
Example #23
Source File: MainActivity.java From v9porn with MIT License | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onTryToReleaseMemory(LowMemoryEvent lowMemoryEvent) { if (contentFrameLayout == null || fragmentManager == null || !isBackground) { return; } if (!BuildConfig.DEBUG) { //Bugsnag.notify(new Throwable(TAG + ":LowMemory,try to release some memory now!"), Severity.INFO); } try { Logger.t(TAG).d("start try to release memory ...."); FragmentTransaction bt = fragmentManager.beginTransaction(); for (int i = 0; i < 5; i++) { //只移除当前未选中的 if (i != selectIndex) { String name = FragmentUtils.makeFragmentName(contentFrameLayout.getId(), i); Fragment fragment = fragmentManager.findFragmentByTag(name); if (fragment != null) { bt.remove(fragment); setNull(i); } } } bt.commitAllowingStateLoss(); //通知系统尝试释放内存 System.gc(); System.runFinalization(); Logger.t(TAG).d("try to release memory success !!!"); } catch (Exception e) { e.printStackTrace(); if (!BuildConfig.DEBUG) { //Bugsnag.notify(new Throwable(TAG + " tryToReleaseMemory error::", e), Severity.WARNING); } } }
Example #24
Source File: Bus.java From Android-VMLib with Apache License 2.0 | 5 votes |
/** * We need to detect that whether the subscriber has one method: * used {@link Subscribe} annotation and has more than one parameters. * This is necessary, since if we registered a subscriber don't meet the requirements, * it will throw an exception. * * @param subscriber the subscriber. * @return does the subscriber has at least one method required. */ private boolean haveAnnotation(Object subscriber) { boolean skipSuperClasses = false; Class<?> clazz = subscriber.getClass(); while (clazz != null && !isSystemClass(clazz.getName()) && !skipSuperClasses) { Method[] allMethods; try { allMethods = clazz.getDeclaredMethods(); } catch (Throwable th) { try { allMethods = clazz.getMethods(); }catch (Throwable th2) { continue; }finally { skipSuperClasses = true; } } for (Method method : allMethods) { Class<?>[] parameterTypes = method.getParameterTypes(); if (method.isAnnotationPresent(Subscribe.class) && parameterTypes.length == 1) { return true; } } clazz = clazz.getSuperclass(); } return false; }
Example #25
Source File: MainFragment.java From pe-protector-moe with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onResChange(EventBusUtil util) { if (util == null || util.getCode() != EventBusUtil.EVENT_RES_CHANGE) return; try { View view = getView(); if (view == null) return; TextView oil = view.findViewById(R.id.tv_oil); TextView ammo = view.findViewById(R.id.tv_ammo); TextView steel = view.findViewById(R.id.tv_steel); TextView aluminium = view.findViewById(R.id.tv_aluminium); TextView qz = view.findViewById(R.id.tv_qz); TextView xy = view.findViewById(R.id.tv_xy); TextView zl = view.findViewById(R.id.tv_zl); TextView hm = view.findViewById(R.id.tv_hm); TextView qt = view.findViewById(R.id.tv_qt); TextView ship = view.findViewById(R.id.tv_ship); TextView equipment = view.findViewById(R.id.tv_equipment); TextView repair = view.findViewById(R.id.tv_repair); oil.setText(String.valueOf(userData.userBaseData.userVo.oil)); ammo.setText(String.valueOf(userData.userBaseData.userVo.ammo)); steel.setText(String.valueOf(userData.userBaseData.userVo.steel)); aluminium.setText(String.valueOf(userData.userBaseData.userVo.aluminium)); qz.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_DD_CUBE))); xy.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_CL_CUBE))); zl.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_BB_CUBE))); hm.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_CV_CUBE))); qt.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_SS_CUBE))); ship.setText(String.format(getResources().getString(R.string.ship_num), userData.allShip.size(), userData.shipNumTop)); equipment.setText(String.format(getResources().getString(R.string.equipment_num), userData.equipmentSize(), userData.equipmentNumTop)); repair.setText(String.valueOf(userData.packageGet(UserData.PACKAGE_FAST_REPAIR))); } catch (Exception e) { Log.e(TAG, "刷新Res出现问题"); e.printStackTrace(); } }
Example #26
Source File: FragmentLikeIllust.java From Pixiv-Shaft with MIT License | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(Channel event) { if (event.getReceiver().contains(starType)) { tag = (String) event.getObject(); baseBind.refreshLayout.autoRefresh(); } }
Example #27
Source File: MainActivity.java From landlord_client with Apache License 2.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.ASYNC) public void onPictureCompressEvent(PictureCompressEvent pictureCompressEvent) { //压缩后的图片不大于1MB Uri compressUri = AvatarChangeUtil.compress(this, pictureCompressEvent.getPictureUri(), 1024); if(compressUri != null) { SharedPreferencesUtil.saveUserAvatar(compressUri); userAvatar.setImageURI(compressUri); } }
Example #28
Source File: MainActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(Object event) { Log.d("请求数据了===", "sss"); boolean loadComplete = SPUtils.getBoolean(this, "loadComplete", false); if (loadComplete) { parseInvokeIntent(); SPUtils.putBoolean(this, "loadComplete", false); } }
Example #29
Source File: LogFragment.java From pe-protector-moe with GNU General Public License v3.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onAddLog(EventBusUtil util) { if (util == null) { textViewLog.setText(UIUpdate.stringBuilder); } else if (util.getCode() == EventBusUtil.EVENT_LOG_ADD && textViewLog != null) { UIUpdate.stringBuilder.insert(0, util.getMessage() + "\n"); textViewLog.setText(UIUpdate.stringBuilder); } }
Example #30
Source File: SampleActivity.java From dialog-helper with Apache License 2.0 | 5 votes |
@Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(InfoDialogDismissedEvent event) { switch (event.getDialogId()) { case DIALOG_ID_INFO: Toast.makeText(this, "Info dialog dismissed", Toast.LENGTH_LONG).show(); break; case DIALOG_ID_SECOND_IN_CHAIN: Toast.makeText(this, "Last dialog in chain dismissed", Toast.LENGTH_LONG).show(); break; } }