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));
}
}
}
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;
}
}
}
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;
}
}
}
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();
}
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;
}
}
Aggregations