Search in sources :

Example 1 with BroadcastUpdatedEvent

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

the class LikeBroadcastWriter method onResponse.

@Override
public void onResponse(Broadcast response) {
    ToastUtils.show(mLike ? R.string.broadcast_like_successful : R.string.broadcast_unlike_successful, getContext());
    EventBusUtils.postAsync(new BroadcastUpdatedEvent(response, this));
    stopSelf();
}
Also used : BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Example 2 with BroadcastUpdatedEvent

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

the class RebroadcastBroadcastWriter method onErrorResponse.

@Override
public void onErrorResponse(VolleyError error) {
    LogUtils.e(error.toString());
    Context context = getContext();
    ToastUtils.show(context.getString(mRebroadcast ? R.string.broadcast_rebroadcast_failed_format : R.string.broadcast_unrebroadcast_failed_format, ApiError.getErrorString(error, context)), context);
    boolean notified = false;
    if (mBroadcast != null && error instanceof ApiError) {
        // Correct our local state if needed.
        ApiError apiError = (ApiError) error;
        Boolean shouldBeRebroadcasted = null;
        if (apiError.code == Codes.RebroadcastBroadcast.ALREADY_REBROADCASTED) {
            shouldBeRebroadcasted = true;
        } else if (apiError.code == Codes.RebroadcastBroadcast.NOT_REBROADCASTED_YET) {
            shouldBeRebroadcasted = false;
        }
        if (shouldBeRebroadcasted != null) {
            mBroadcast.fixRebroadcasted(shouldBeRebroadcasted);
            EventBusUtils.postAsync(new BroadcastUpdatedEvent(mBroadcast, this));
            notified = true;
        }
    }
    if (!notified) {
        // Must notify to reset pending status. Off-screen items also needs to be invalidated.
        EventBusUtils.postAsync(new BroadcastWriteFinishedEvent(mBroadcastId, this));
    }
    stopSelf();
}
Also used : Context(android.content.Context) BroadcastWriteFinishedEvent(me.zhanghai.android.douya.eventbus.BroadcastWriteFinishedEvent) ApiError(me.zhanghai.android.douya.network.api.ApiError) BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Example 3 with BroadcastUpdatedEvent

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

the class BroadcastListResource method onLoadFinished.

@Override
protected void onLoadFinished(boolean more, int count, boolean successful, List<Broadcast> response, VolleyError error) {
    getListener().onLoadBroadcastListFinished(getRequestCode());
    if (successful) {
        if (more) {
            append(response);
            getListener().onBroadcastListAppended(getRequestCode(), Collections.unmodifiableList(response));
        } else {
            setAndNotifyListener(response);
        }
        for (Broadcast broadcast : response) {
            EventBusUtils.postAsync(new BroadcastUpdatedEvent(broadcast, this));
        }
    } else {
        getListener().onLoadBroadcastListError(getRequestCode(), error);
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.apiv2.Broadcast) BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Example 4 with BroadcastUpdatedEvent

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

the class BroadcastResource method onLoadFinished.

@Override
protected void onLoadFinished(boolean successful, Broadcast response, VolleyError error) {
    getListener().onLoadBroadcastFinished(getRequestCode());
    if (successful) {
        set(response);
        getListener().onBroadcastChanged(getRequestCode(), response);
        EventBusUtils.postAsync(new BroadcastUpdatedEvent(response, this));
    } else {
        getListener().onLoadBroadcastError(getRequestCode(), error);
    }
}
Also used : BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Example 5 with BroadcastUpdatedEvent

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

the class LikeBroadcastWriter method onErrorResponse.

@Override
public void onErrorResponse(VolleyError error) {
    LogUtils.e(error.toString());
    Context context = getContext();
    ToastUtils.show(context.getString(mLike ? R.string.broadcast_like_failed_format : R.string.broadcast_unlike_failed_format, ApiError.getErrorString(error, context)), context);
    boolean notified = false;
    if (mBroadcast != null && error instanceof ApiError) {
        // Correct our local state if needed.
        ApiError apiError = (ApiError) error;
        Boolean shouldBeLiked = null;
        if (apiError.code == Codes.LikeBroadcast.ALREADY_LIKED) {
            shouldBeLiked = true;
        } else if (apiError.code == Codes.LikeBroadcast.NOT_LIKED_YET) {
            shouldBeLiked = false;
        }
        if (shouldBeLiked != null) {
            mBroadcast.fixLiked(shouldBeLiked);
            EventBusUtils.postAsync(new BroadcastUpdatedEvent(mBroadcast, this));
            notified = true;
        }
    }
    if (!notified) {
        // Must notify to reset pending status. Off-screen items also needs to be invalidated.
        EventBusUtils.postAsync(new BroadcastWriteFinishedEvent(mBroadcastId, this));
    }
    stopSelf();
}
Also used : Context(android.content.Context) BroadcastWriteFinishedEvent(me.zhanghai.android.douya.eventbus.BroadcastWriteFinishedEvent) ApiError(me.zhanghai.android.douya.network.api.ApiError) BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Aggregations

BroadcastUpdatedEvent (me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)8 Context (android.content.Context)2 BroadcastWriteFinishedEvent (me.zhanghai.android.douya.eventbus.BroadcastWriteFinishedEvent)2 ApiError (me.zhanghai.android.douya.network.api.ApiError)2 BroadcastDeletedEvent (me.zhanghai.android.douya.eventbus.BroadcastDeletedEvent)1 Broadcast (me.zhanghai.android.douya.network.api.info.apiv2.Broadcast)1