Search in sources :

Example 1 with UserUpdatedEvent

use of me.zhanghai.android.douya.eventbus.UserUpdatedEvent in project Douya by DreaminginCodeZH.

the class FollowUserWriter method onErrorResponse.

@Override
public void onErrorResponse(VolleyError error) {
    LogUtils.e(error.toString());
    Context context = getContext();
    ToastUtils.show(context.getString(mFollow ? R.string.user_follow_failed_format : R.string.user_unfollow_failed_format, ApiError.getErrorString(error, context)), context);
    boolean notified = false;
    if (mUser != null && error instanceof ApiError) {
        // Correct our local state if needed.
        ApiError apiError = (ApiError) error;
        Boolean shouldBeFollowed = null;
        if (apiError.code == Codes.Followship.ALREADY_FOLLOWED) {
            shouldBeFollowed = true;
        } else if (apiError.code == Codes.Followship.NOT_FOLLOWED_YET) {
            shouldBeFollowed = false;
        }
        if (shouldBeFollowed != null) {
            mUser.fixFollowed(shouldBeFollowed);
            EventBusUtils.postAsync(new UserUpdatedEvent(mUser, this));
            notified = true;
        }
    }
    if (!notified) {
        // Must notify to reset pending status. Off-screen items also needs to be invalidated.
        EventBusUtils.postAsync(new UserWriteFinishedEvent(mUserIdOrUid, this));
    }
    stopSelf();
}
Also used : Context(android.content.Context) ApiError(me.zhanghai.android.douya.network.api.ApiError) UserUpdatedEvent(me.zhanghai.android.douya.eventbus.UserUpdatedEvent) UserWriteFinishedEvent(me.zhanghai.android.douya.eventbus.UserWriteFinishedEvent)

Example 2 with UserUpdatedEvent

use of me.zhanghai.android.douya.eventbus.UserUpdatedEvent in project Douya by DreaminginCodeZH.

the class UserResource method onLoadFinished.

@Override
protected void onLoadFinished(boolean successful, User response, VolleyError error) {
    getListener().onLoadUserFinished(getRequestCode());
    if (successful) {
        set(response);
        onLoadSuccess(response);
        getListener().onUserChanged(getRequestCode(), get());
        EventBusUtils.postAsync(new UserUpdatedEvent(response, this));
    } else {
        getListener().onLoadUserError(getRequestCode(), error);
    }
}
Also used : UserUpdatedEvent(me.zhanghai.android.douya.eventbus.UserUpdatedEvent)

Example 3 with UserUpdatedEvent

use of me.zhanghai.android.douya.eventbus.UserUpdatedEvent in project Douya by DreaminginCodeZH.

the class FollowUserWriter method onResponse.

@Override
public void onResponse(User response) {
    ToastUtils.show(mFollow ? R.string.user_follow_successful : R.string.user_unfollow_successful, getContext());
    EventBusUtils.postAsync(new UserUpdatedEvent(response, this));
    stopSelf();
}
Also used : UserUpdatedEvent(me.zhanghai.android.douya.eventbus.UserUpdatedEvent)

Aggregations

UserUpdatedEvent (me.zhanghai.android.douya.eventbus.UserUpdatedEvent)3 Context (android.content.Context)1 UserWriteFinishedEvent (me.zhanghai.android.douya.eventbus.UserWriteFinishedEvent)1 ApiError (me.zhanghai.android.douya.network.api.ApiError)1