Search in sources :

Example 31 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project Douya by DreaminginCodeZH.

the class BroadcastListResource method onBroadcastUpdated.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onBroadcastUpdated(BroadcastUpdatedEvent event) {
    if (event.isFromMyself(this) || isEmpty()) {
        return;
    }
    List<Broadcast> broadcastList = get();
    for (int i = 0, size = broadcastList.size(); i < size; ++i) {
        Broadcast broadcast = broadcastList.get(i);
        boolean changed = false;
        if (broadcast.id == event.broadcast.id) {
            broadcastList.set(i, event.broadcast);
            changed = true;
        } else if (broadcast.rebroadcastedBroadcast != null && broadcast.rebroadcastedBroadcast.id == event.broadcast.id) {
            broadcast.rebroadcastedBroadcast = event.broadcast;
            changed = true;
        }
        if (changed) {
            getListener().onBroadcastChanged(getRequestCode(), i, broadcastList.get(i));
        }
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.apiv2.Broadcast) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 32 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project Douya by DreaminginCodeZH.

the class CommentListResource method onCommentDeleted.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onCommentDeleted(CommentDeletedEvent event) {
    if (event.isFromMyself(this) || isEmpty()) {
        return;
    }
    List<Comment> commentList = get();
    for (int i = 0, size = commentList.size(); i < size; ) {
        Comment comment = commentList.get(i);
        if (comment.id == event.commentId) {
            commentList.remove(i);
            getListener().onCommentRemoved(getRequestCode(), i);
            --size;
        } else {
            ++i;
        }
    }
}
Also used : Comment(me.zhanghai.android.douya.network.api.info.apiv2.Comment) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 33 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project Douya by DreaminginCodeZH.

the class BaseReviewListResource method onReviewDeleted.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onReviewDeleted(ReviewDeletedEvent event) {
    if (event.isFromMyself(this) || isEmpty()) {
        return;
    }
    List<Review> reviewList = get();
    for (int i = 0, size = reviewList.size(); i < size; ) {
        Review review = reviewList.get(i);
        if (review.id == event.reviewId) {
            reviewList.remove(i);
            getListener().onReviewRemoved(getRequestCode(), i);
            --size;
        } else {
            ++i;
        }
    }
}
Also used : Review(me.zhanghai.android.douya.network.api.info.frodo.Review) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 34 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.

the class MediaBrowserActivity method onMediaChanged.

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMediaChanged(OnMediaChanged event) {
    if (event.isError()) {
        AppLog.w(AppLog.T.MEDIA, "Received onMediaChanged error: " + event.error.type + " - " + event.error.message);
        showMediaToastError(R.string.media_generic_error, event.error.message);
        return;
    }
    switch(event.cause) {
        case DELETE_MEDIA:
            if (event.mediaList == null || event.mediaList.isEmpty()) {
                break;
            }
            // detail view (if it was the one displayed)
            for (MediaModel mediaModel : event.mediaList) {
                int localMediaId = mediaModel.getId();
                mMediaGridFragment.removeFromMultiSelect(localMediaId);
                if (mMediaEditFragment != null && mMediaEditFragment.isVisible() && localMediaId == mMediaEditFragment.getLocalMediaId()) {
                    updateOnMediaChanged(localMediaId);
                    if (mMediaEditFragment.isInLayout()) {
                        mMediaEditFragment.loadMedia(MediaEditFragment.MISSING_MEDIA_ID);
                    } else {
                        getFragmentManager().popBackStack();
                    }
                }
            }
            break;
    }
    updateViews();
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) SuppressLint(android.annotation.SuppressLint) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 35 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.

the class WPMainActivity method onSiteChanged.

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
    // "Reload" selected site from the db, would be smarter if the OnSiteChanged provided the list of changed sites.
    if (getSelectedSite() == null && mSiteStore.hasSite()) {
        setSelectedSite(mSiteStore.getSites().get(0));
    }
    if (getSelectedSite() == null) {
        return;
    }
    SiteModel site = mSiteStore.getSiteByLocalId(getSelectedSite().getId());
    if (site != null) {
        if (site.isJetpackConnected() && !TextUtils.isEmpty(site.getPassword())) {
            // The user added a Jetpack-connected site as a self-hosted site - this isn't supported
            if (!mAccountStore.hasAccessToken()) {
                // Ask user to sign in to WordPress.com to access their Jetpack site
                Intent signInIntent = new Intent(this, SignInActivity.class);
                signInIntent.putExtra(SignInActivity.EXTRA_JETPACK_SITE_AUTH, site.getId());
                signInIntent.putExtra(SignInActivity.EXTRA_JETPACK_MESSAGE_AUTH, getString(R.string.jetpack_use_com_account));
                startActivityForResult(signInIntent, SignInActivity.REQUEST_CODE);
                finish();
            } else {
                // Remove the site and send the user back to the site list
                ToastUtils.showToast(this, R.string.jetpack_different_com_account, ToastUtils.Duration.LONG);
                mDispatcher.dispatch(SiteActionBuilder.newRemoveSiteAction(site));
            }
            return;
        }
        mSelectedSite = site;
    }
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) Intent(android.content.Intent) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Subscribe (org.greenrobot.eventbus.Subscribe)43 Intent (android.content.Intent)7 SiteModel (org.wordpress.android.fluxc.model.SiteModel)5 NotificationManager (android.app.NotificationManager)3 NotificationCompat (android.support.v4.app.NotificationCompat)3 Activity (android.app.Activity)2 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 AspectPermission (com.yydcdut.note.aspect.permission.AspectPermission)2 CategoryCreateEvent (com.yydcdut.note.bus.CategoryCreateEvent)2 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)2 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)2 CategoryMoveEvent (com.yydcdut.note.bus.CategoryMoveEvent)2 CategoryUpdateEvent (com.yydcdut.note.bus.CategoryUpdateEvent)2 PhotoNoteCreateEvent (com.yydcdut.note.bus.PhotoNoteCreateEvent)2 PhotoNoteDeleteEvent (com.yydcdut.note.bus.PhotoNoteDeleteEvent)2 UserImageEvent (com.yydcdut.note.bus.UserImageEvent)2 Category (com.yydcdut.note.entity.Category)2 ContextLife (com.yydcdut.note.injector.ContextLife)2