Search in sources :

Example 36 with Subscribe

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);
    }
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 37 with Subscribe

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();
    }
}
Also used : FragmentManager(android.app.FragmentManager) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 38 with Subscribe

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));
}
Also used : AuthenticatePayload(org.wordpress.android.fluxc.store.AccountStore.AuthenticatePayload) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 39 with Subscribe

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;
    }
}
Also used : PostError(org.wordpress.android.fluxc.store.PostStore.PostError) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 40 with Subscribe

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)));
    }
}
Also used : Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) RxUser(com.yydcdut.note.model.rx.RxUser) Inject(javax.inject.Inject) CategoryUpdateEvent(com.yydcdut.note.bus.CategoryUpdateEvent) UserImageEvent(com.yydcdut.note.bus.UserImageEvent) Const(com.yydcdut.note.utils.Const) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) IHomePresenter(com.yydcdut.note.presenters.home.IHomePresenter) IHomeView(com.yydcdut.note.views.home.IHomeView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent) Subscribe(org.greenrobot.eventbus.Subscribe) Permission(com.yydcdut.note.utils.permission.Permission) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) Activity(android.app.Activity) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) Category(com.yydcdut.note.entity.Category) RxCategory(com.yydcdut.note.model.rx.RxCategory)

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