use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.
the class PostUploadService method onMediaUploaded.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMediaUploaded(OnMediaUploaded event) {
// Event for unknown media, ignoring
if (event.media == null || mCurrentUploadingPost == null || mMediaLatchMap.get(event.media.getId()) == null) {
AppLog.w(T.POSTS, "Media event not recognized: " + event.media);
return;
}
if (event.isError()) {
SiteModel site = mSiteStore.getSiteByLocalId(mCurrentUploadingPost.getLocalSiteId());
// TODO: We should interpret event.error.type and pass our own string rather than use error.message
String message = TextUtils.isEmpty(event.error.message) ? event.error.type.toString() : event.error.message;
mPostUploadNotifier.updateNotificationError(mCurrentUploadingPost, site, message, true);
mFirstPublishPosts.remove(mCurrentUploadingPost.getId());
finishUpload();
return;
}
if (event.canceled) {
// Not implemented
return;
}
if (event.completed) {
AppLog.i(T.POSTS, "Media upload completed for post. Media id: " + event.media.getId() + ", post id: " + mCurrentUploadingPost.getId());
mMediaLatchMap.get(event.media.getId()).countDown();
mMediaLatchMap.remove(event.media.getId());
} else {
// Progress update
mPostUploadNotifier.updateNotificationProgress(mCurrentUploadingPost, event.progress);
}
}
use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.
the class BlogPreferencesActivity method onSiteDeleted.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteDeleted(OnSiteDeleted event) {
FragmentManager fragmentManager = getFragmentManager();
SiteSettingsFragment siteSettingsFragment = (SiteSettingsFragment) fragmentManager.findFragmentByTag(KEY_SETTINGS_FRAGMENT);
if (siteSettingsFragment != null) {
if (event.isError()) {
siteSettingsFragment.handleDeleteSiteError(event.error);
return;
}
siteSettingsFragment.handleSiteDeleted();
setResult(RESULT_BLOG_REMOVED);
finish();
}
}
use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.
the class NewUserFragment method onNewUserCreated.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onNewUserCreated(OnNewUserCreated event) {
AppLog.i(T.NUX, event.toString());
if (event.isError()) {
endProgress();
AnalyticsTracker.track(AnalyticsTracker.Stat.CREATE_ACCOUNT_FAILED);
showUserError(event.error.type, event.error.message);
return;
}
if (event.dryRun) {
// User Validated, now try to validate site creation
mDispatcher.dispatch(SiteActionBuilder.newCreateNewSiteAction(mNewSitePayload));
updateProgress(getString(R.string.validating_site_data));
return;
}
// User created, now authenticate the newly created user
AuthenticatePayload payload = new AuthenticatePayload(mNewAccountPayload.username, mNewAccountPayload.password);
mDispatcher.dispatch(AuthenticationActionBuilder.newAuthenticateAction(payload));
}
use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.
the class PostsListFragment method onPostChanged.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPostChanged(OnPostChanged event) {
switch(event.causeOfChange) {
case FETCH_POSTS:
case FETCH_PAGES:
mIsFetchingPosts = false;
if (!isAdded()) {
return;
}
setRefreshing(false);
hideLoadMoreProgress();
if (!event.isError()) {
mCanLoadMorePosts = event.canLoadMore;
loadPosts(LoadMode.IF_CHANGED);
} else {
PostError error = event.error;
switch(error.type) {
case UNAUTHORIZED:
updateEmptyView(EmptyViewMessageType.PERMISSION_ERROR);
break;
default:
updateEmptyView(EmptyViewMessageType.GENERIC_ERROR);
break;
}
}
break;
case DELETE_POST:
if (event.isError()) {
String message = String.format(getText(R.string.error_delete_post).toString(), mIsPage ? "page" : "post");
ToastUtils.showToast(getActivity(), message, ToastUtils.Duration.SHORT);
loadPosts(LoadMode.IF_CHANGED);
}
break;
}
}
use of org.greenrobot.eventbus.Subscribe in project PhotoNoter by yydcdut.
the class HomePresenterImpl method updateFromBroadcast.
@Override
public void updateFromBroadcast(boolean broadcast_process, boolean broadcast_service) {
//有时候categoryLabel为null,感觉原因是activity被回收了,但是一直解决不掉,所以迫不得已的解决办法
if (mCategoryId == -1) {
mRxCategory.getAllCategories().subscribe(categories -> {
for (Category category : categories) {
if (category.isCheck()) {
mCategoryId = category.getId();
}
}
}, (throwable -> YLog.e(throwable)));
}
//从另外个进程过来的数据
if (broadcast_process) {
mRxPhotoNote.refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNoteList -> {
mRxCategory.findByCategoryId(mCategoryId).subscribe(category -> {
category.setPhotosNumber(photoNoteList.size());
mRxCategory.updateCategory(category).observeOn(AndroidSchedulers.mainThread()).subscribe(categories -> {
mHomeView.notifyCategoryDataChanged();
}, (throwable -> YLog.e(throwable)));
}, (throwable -> YLog.e(throwable)));
});
}
//从Service中来
if (broadcast_service) {
mRxCategory.getAllCategories().observeOn(AndroidSchedulers.mainThread()).subscribe(categories -> mHomeView.updateCategoryList(categories), (throwable -> YLog.e(throwable)));
}
}
Aggregations