com.squareup.otto.Subscribe Java Examples

The following examples show how to use com.squareup.otto.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: PostItemListActivity.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Subscribe
public void openHistory(OpenHistoryEvent event) {
    final int bookmarkId;
    if (event.watched) {
        bookmarkId = PostItemListActivity.BOOKMARKS_ID;
    } else {
        bookmarkId = PostItemListActivity.HISTORY_ID;
    }

    final Intent intent = new Intent(this, PostItemListActivity.class);
    final Bundle args = new Bundle();

    args.putInt(Extras.EXTRAS_LIST_TYPE, bookmarkId);
    intent.putExtras(args);
    startActivity(intent);
}
 
Example #2
Source File: ChatActivity.java    From talk-android with MIT License 6 votes vote down vote up
@Subscribe
public void onAudioProgressChangeEvent(AudioProgressChangeEvent event) {
    if (MediaController.getInstance().isPlayingAudio(event.message)) {
        for (int i = 0; i < msgListView.getChildCount(); i++) {
            Object tag = msgListView.getChildAt(i).getTag();
            if (tag != null && tag instanceof SpeechRow.SpeechRowHolder) {
                SpeechRow.SpeechRowHolder holder = (SpeechRow.SpeechRowHolder) tag;
                if (event.message.get_id().equals(holder.messageId)) {
                    holder.updateProgress(event.message.getAudioProgress(),
                            event.message.getAudioProgressSec());
                    break;
                }
            }
        }
    }
}
 
Example #3
Source File: MyService.java    From EZScreenshot with Apache License 2.0 6 votes vote down vote up
@Subscribe
public void onSettingChanged(BusEvents.SettingChangedEvent event) {
    if (event != null && event.eventType != null) {
        LogUtil.LOGI("event.eventType=" + event.eventType);
        switch (event.eventType) {
            case HideStatusbarIconSetting: {
                initNotificationState(SettingHelper.isScreenshotServicePausing());
                break;
            }
            case ShakeFunctionSettingChanged: {
                initShakeFunctionState(SettingHelper.isScreenshotServicePausing());
                break;
            }
            case ShakeSpeedThresholdChanged: {
                ShakeEventListener.setDefaultSensitivity(SettingHelper.getShakeSensitivity());
                break;
            }
        }
    }
}
 
Example #4
Source File: SlidingPanelActivity.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Subscribe
public void openBookmark(BookmarkClickedEvent event) {
    this.boardName = event.getBoardName();
    this.boardTitle = event.getBoardTitle();

    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();

    long threadId = event.getThreadId();
    detailFragment = ThreadDetailFragment.newInstance(threadId, boardName, boardTitle, null, false, false);
    ft.replace(R.id.postitem_detail, detailFragment, TAG_THREAD_DETAIL);
    ft.commit();

    if (panelLayout.isOpen()) {
        panelLayout.closePane();
    }
}
 
Example #5
Source File: HomeActivity.java    From fingerpoetry-android with Apache License 2.0 6 votes vote down vote up
@Subscribe
    public void onLoginSuccess(LoginEvent event) {
        Timber.i("receive onLoginSuccess");
        updateNavData();
//        CommonHelper.getTopics(this);
//        CommonHelper.getUserTopics(this);
//        CommonHelper.getSites(this);
//        CommonHelper.getUserSites(this);
        User user = AccountLogic.getInstance().getNowUser();
        if (!user.getIsBasicSet() && Constants.isFirstLaunch()) {
            Constants.setFirstLaunch(false);
            user.setBasicSet(true);
            LoginData data = AccountLogic.getInstance().getLoginData();
            data.setUser(user);
            AccountLogic.getInstance().setLoginData(data);
            AccountApi accountApi = BookRetrofit.getInstance().getAccountApi();
            Map<String, Object> info = new HashMap<>();
            info.put("isBasicSet", user.getIsBasicSet());
            accountApi.update(info, AccountLogic.getInstance().getToken())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(initObserver(HomeActivity.this));
            start(ChooseTopicFragment.newInstance(ChooseTopicFragment.ACTION_SET));
        }
    }
 
Example #6
Source File: BridgeActivity.java    From Android-Bridge-App with MIT License 6 votes vote down vote up
@Subscribe
public void onWSTrafficEvent(WSConnectionManager.WSTrafficEvent event) {

    boolean shouldRefresh = false;
    if (event.isSlowConnection()) {
        if (isWSTrafficSlow.compareAndSet(false, true)) {
            shouldRefresh = true;
            showToast("Bad Network Connection: " + event.getMessage() + "!", isWiFiConnected.get(), event.getMessage());
        }
    } else {
        if (isWSTrafficSlow.compareAndSet(true, false)) {
            shouldRefresh = true;
        }
    }
    if (shouldRefresh) {
        refresh();
    }
}
 
Example #7
Source File: TopicStoryFragment.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateStory(UpdateStoryEvent event) {
    if (event.story == null || StoryDataProcess.Category.getEnum(story.getCategory()) != StoryDataProcess.Category.TOPIC) return;
    this.story = event.story;
    topic = GsonProvider.getGson().fromJson(story.getData(), Topic.class);
    if (MainApp.globalMembers.containsKey(story.get_creatorId())) {
        creator = MainApp.globalMembers.get(story.get_creatorId());
    } else {
        creator = MemberDataProcess.getAnonymousInstance();
    }
    setStoryContent();
}
 
Example #8
Source File: ThreadDetailFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void onReplyClicked(final ReplyClickEvent event) {
    if (event.getPost() == null) {
        return;
    }

    try {
        if (getUserVisibleHint() && currentThread != null) {
            final long index = MimiUtil.findPostPositionById(event.getPost().getNo(), currentThread.getPosts());

            if (index >= 0) {
                scrollListToPosition(recyclerView, (int) index);
            }
        }
    } catch (Exception e) {
        if (getActivity() != null) {
            Toast.makeText(getActivity(), R.string.unknown_error, Toast.LENGTH_SHORT).show();
        }

        if (currentThread == null) {
            Log.e(LOG_TAG, "Current thread is null");
        } else {
            if (currentThread.getPosts() == null) {
                Log.e(LOG_TAG, "Thread posts are null");
            }
        }

        Log.e(LOG_TAG, "Caught exception when scrolling to post from reply dialog", e);
    }

}
 
Example #9
Source File: HistoryFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Subscribe
    public void onAutoRefresh(final UpdateHistoryEvent event) {
//        ThreadRegistry.getInstance().update(event.getThread().getThreadId(), event.getThread().getPosts().size());
//        setBookmarkCount(ThreadRegistry.getInstance().getUnreadCount());

//        if(historyAdapter != null) {
//            Log.i(LOG_TAG, "Refreshing history list");
//            historyAdapter.notifyDataSetChanged();
//        }

        loadHistory(isBookmarks);
    }
 
Example #10
Source File: TabsActivity.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void onRateApp(final RateAppEvent event) {
    Log.i(LOG_TAG, "onRateApp called: action=" + event.getAction());
    if (rateAppContainer != null) {
        if (event.getAction() == RateAppEvent.OPEN) {
            rateAppContainer.setVisibility(View.VISIBLE);
        }

        if (event.getAction() == RateAppEvent.CLOSE) {
            rateAppContainer.setVisibility(View.GONE);
        }
    }
}
 
Example #11
Source File: TodoStore.java    From TodoFluxArchitecture with Apache License 2.0 5 votes vote down vote up
/**
 * 订阅TodoListAction事件.
 *
 * @param todoListAction todo事项列表事件
 */
@Subscribe
public final void subscribeListAction(TodoListAction todoListAction) {
    LogTool.debug(todoListAction.toString());
    DataBundle<TodoListAction.Key> data = todoListAction.getDataBundle();
    switch ((TodoListAction.Type) todoListAction.getType()) {
        case LOAD: {
            List<TodoItem> list = (List<TodoItem>) data.get(TodoListAction.Key.LIST, null);
            if (list != null) {
                todoItemHashMap.clear();
                for (TodoItem item : list) {
                    todoItemHashMap.put(item.getId(), item);
                }
            }
            filter = TodoListModel.Filter.ALL;
            break;
        }
        case SHOW_ALL:
            filter = TodoListModel.Filter.ALL;
            break;
        case SHOW_COMPLETED:
            filter = TodoListModel.Filter.COMPLETED;
            break;
        case SHOW_STARED:
            filter = TodoListModel.Filter.STARED;
            break;
        default:
            break;
    }

    notifyTodoListModelChanged();
}
 
Example #12
Source File: PresenterRepoList.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@DebugLog
@Subscribe
public void onEventQueryGetRepos(@NonNull final QueryGetRepos.EventQueryGetReposDidFinish poEvent) {
    if (poEvent.success) {
        getRepos(poEvent.pullToRefresh);
    } else {
        final RepoListMvp.View loView = getView();
        if (isViewAttached() && loView != null) {
            loView.showError(poEvent.throwable, poEvent.pullToRefresh);
        }
    }
}
 
Example #13
Source File: TabsActivity.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void onTabClosed(CloseTabEvent event) {
    final long threadId = event.getId();
    final String boardName = event.getBoardName();

    if (event.isCloseOthers()) {
        closeOtherTabs(tabPagerAdapter.getPositionById(threadId));
    } else {
        closeTab(threadId, boardName, true);
    }
}
 
Example #14
Source File: LinkStoryFragment.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateStory(UpdateStoryEvent event) {
    if (event.story == null || StoryDataProcess.Category.getEnum(story.getCategory()) != StoryDataProcess.Category.LINK) return;
    this.story = event.story;
    link = GsonProvider.getGson().fromJson(story.getData(), Link.class);
    if (MainApp.globalMembers.containsKey(story.get_creatorId())) {
        creator = MainApp.globalMembers.get(story.get_creatorId());
    } else {
        creator = MemberDataProcess.getAnonymousInstance();
    }
    setStoryContent();
}
 
Example #15
Source File: AudioDetailActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onAudioProgressChangeEvent(AudioProgressChangeEvent event) {
    if (MediaController.getInstance().isPlayingAudio(event.message)) {
        if (event.message.get_id().equals(message.get_id())) {
            updateProgress(event.message.getAudioProgress(),
                    event.message.getAudioProgressSec());
        }
    }
}
 
Example #16
Source File: ContactsFragment.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateMemberEvent(UpdateMemberEvent event) {
    if (mPresenter != null) {
        mPresenter.getMembers();
        mPresenter.getLeaveMembers();
    }
}
 
Example #17
Source File: TodoListActivity.java    From TodoFluxArchitecture with Apache License 2.0 5 votes vote down vote up
/**
 * 订阅TodoListModel数据事件.
 *
 * @param todoListModel todoListModel
 */
@Subscribe
public void onTodoModelChanged(final TodoListModel todoListModel) {
    this.todoListModel = todoListModel;
    LogTool.debug(todoListModel.toString());
    recyclerAdapter.notifyDataSetChanged();
}
 
Example #18
Source File: TabsActivity.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void actionModeChanged(ActionModeEvent event) {
    if (tabLayout != null) {
        if (event.isEnabled()) {
            tabLayout.setVisibility(View.INVISIBLE);
        } else {
            tabLayout.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #19
Source File: NotificationFragment.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateNotificationEvent(UpdateNotificationEvent event) {
    if (BizLogic.isCurrentTeam(event.notification.get_teamId())) {
        adapter.updateOne(RowFactory.getInstance().makeNotificationRow(event.notification, this));
        listView.scrollToPosition(0);
    }
}
 
Example #20
Source File: MainActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
public void matureLock(OttoEvents.MatureEvent event) {
    if (event == null) {
        Logger.i(this, "OttoEvents.StartDownload event was null");
    } else {
        matureLock(event.isMature());
    }
}
 
Example #21
Source File: TopicSettingActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateMemberEvent(UpdateMemberEvent event) {
    if (event.member != null) {
        invalidateOptionsMenu();
        mAdapter.update(event.member);
    }
}
 
Example #22
Source File: LifeCycleMonitor.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
public void onActivityLifeCycleEvent(ActivityLifeCycleEvent event) {
    switch (event.getState()) {
        case CREATE:
            AptoideUtils.CrashlyticsUtils.updateNumberOfScreens(true);
            break;
        case DESTROY:
            AptoideUtils.CrashlyticsUtils.updateNumberOfScreens(false);
            break;
    }
}
 
Example #23
Source File: DownloadFragment.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
    public void refreshUi(DownloadServiceConnected event) {
        Logger.i("AptoideDownloadFragment", "refreshUi");
        service = ((MainActivity)getActivity()).getDownloadService();
        if (service != null) {
//            ongoingList.clear();
//            notOngoingList.clear();
//            ongoingList.addAll(service.getAllActiveDownloads());
//            notOngoingList.addAll(service.getAllNonActiveDownloads());
//            sectionAdapter.notifyDataSetChanged();

            displayableList.clear();
            ArrayList<Displayable> onGoing = service.getAllActiveDownloads();
            ArrayList<Displayable> notOnGoing = service.getAllNonActiveDownloads();

            if (onGoing != null && onGoing.size() > 0) {
                displayableList.add(new HeaderRow(getString(R.string.active), false, BUCKET_SIZE));
                displayableList.addAll(onGoing);
            }

            if (notOnGoing != null && notOnGoing.size() > 0) {
                displayableList.add(new HeaderRow(getString(R.string.completed), false, BUCKET_SIZE));
                displayableList.addAll(notOnGoing);
            }

            getRecyclerView().getAdapter().notifyDataSetChanged();
            getActivity().supportInvalidateOptionsMenu();
        }
    }
 
Example #24
Source File: DownloadFragment.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
    public synchronized void onDownloadUpdate(OttoEvents.DownloadInProgress event) {
        if (event != null && event.getDownload() != null) {
            Logger.d("AptoideDownloadFragment", "onDownloadUpdate " + event.getDownload().getId());
            for (Displayable displayable : displayableList) {
                if (displayable instanceof DownloadRow) {
                    DownloadRow row = (DownloadRow) displayable;
                    if (event.getDownload().equals(row.download)) {
                        getRecyclerView().getAdapter().notifyItemChanged(displayableList.indexOf(displayable));
                    }
                }
            }
        } else {
            Logger.d("AptoideDownloadFragment", "onDownloadUpdate ERROR! event || download == null");
        }

//        try {
//            int start = getListView().getFirstVisiblePosition();
//            for (int i = start, j = getListView().getLastVisiblePosition(); i <= j; i++) {
//                if (download.equals((getListView().getItemAtPosition(i)))) {
//                    View view = getListView().getChildAt(i - start);
//                    getListView().getAdapter().getView(i, view, getListView());
//                    break;
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

    }
 
Example #25
Source File: ChatActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onNewMessage(NewMessageEvent event) {
    boolean isViewingOld = msgListView.getLastVisiblePosition() < msgListView.getCount() - 6;
    try {
        Message msg = event.message;
        if ((isPrivate && msg.getForeignId().equals(member.get_id())) ||
                (!isPrivate && room != null && msg.getForeignId().equals(room.get_id())) ||
                (!isPrivate && story != null && msg.getForeignId().equals(story.get_id()))) {
            if (!isSearchResult) {
                adapter.addToEnd(RowFactory.getInstance().makeRows(msg, this,
                        messageActionCallback, retriever));
                if (!isViewingOld) {
                    scrollToBottom();
                }
            }
            if (!isPreview && isViewingOld) {
                layoutUnreadTip.setVisibility(View.VISIBLE);
                tempUnreadCount++;
                tvUnreadTip.setText(String.format(getString(R.string.unread_tip), tempUnreadCount));
            } else {
                resetUnreadLayout();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: ChatActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onUpdateMessage(UpdateMessageEvent event) {
    Message msg = event.message;
    if (msg != null) {
        adapter.updateOne(msg.get_id(), RowFactory.getInstance()
                .makeRows(msg, this, messageActionCallback, retriever));
        if (MessageDataProcess.DisplayMode.SPEECH.toString().equals(msg.getDisplayMode())) {
            msg.setIsRead(false);
        }
    }
}
 
Example #27
Source File: UpdatesFragment.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
public void removedAppEvent(OttoEvents.UnInstalledApkEvent event) {
    refreshUi(displayableList);
    if (swipeContainer != null) {
        swipeContainer.setRefreshing(false);
    }
}
 
Example #28
Source File: ChatActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onAudioResetEvent(AudioResetEvent event) {
    for (int i = 0; i < msgListView.getChildCount(); i++) {
        Object tag = msgListView.getChildAt(i).getTag();
        if (tag != null && tag instanceof SpeechRow.SpeechRowHolder) {
            SpeechRow.SpeechRowHolder holder = (SpeechRow.SpeechRowHolder) tag;
            if (event.message.get_id().equals(holder.messageId)) {
                holder.updateButtonState(SpeechRow.STATE_STOP);
                holder.updateProgress(0, MessageDataProcess.getInstance().getFile(event.message).getDuration());
                break;
            }
        }
    }
}
 
Example #29
Source File: ChatActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Subscribe
public void onAudioRecordProgressEvent(AudioRecordProgressEvent event) {
    for (int i = 0; i < msgListView.getChildCount(); i++) {
        Object tag = msgListView.getChildAt(i).getTag();
        if (tag != null && tag instanceof SpeechRecordRow.SpeechRecordRowHolder) {
            SpeechRecordRow.SpeechRecordRowHolder holder = (SpeechRecordRow.SpeechRecordRowHolder) tag;
            holder.updateRecordingTime(event.sec);
            break;
        }
    }
}
 
Example #30
Source File: AppViewActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe
public void onDownloadUpdate(OttoEvents.DownloadInProgress event) {
    if (event != null) {
        Download download = event.getDownload();
        onDownloadUpdate(download);
    }
}