Search in sources :

Example 21 with Broadcast

use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.

the class TimelineBroadcastListResource method onBroadcastDeleted.

@Subscribe(threadMode = ThreadMode.POSTING)
public void onBroadcastDeleted(BroadcastDeletedEvent event) {
    if (event.isFromMyself(this) || isEmpty()) {
        return;
    }
    List<Broadcast> broadcastList = get();
    for (int i = 0, size = broadcastList.size(); i < size; ) {
        Broadcast broadcast = broadcastList.get(i);
        if (broadcast.id == event.broadcastId) {
            broadcastList.remove(i);
            getListener().onBroadcastRemoved(getRequestCode(), i);
            --size;
        } else {
            if (broadcast.parentBroadcast != null && broadcast.parentBroadcast.id == event.broadcastId) {
                // Same behavior as Frodo API.
                // FIXME: Won't reach here if another list shares this broadcast instance.
                broadcast.parentBroadcast = null;
                getListener().onBroadcastChanged(getRequestCode(), i, broadcast);
            } else if (broadcast.rebroadcastedBroadcast != null && broadcast.rebroadcastedBroadcast.id == event.broadcastId) {
                broadcast.rebroadcastedBroadcast.isDeleted = true;
                getListener().onBroadcastChanged(getRequestCode(), i, broadcast);
            }
            ++i;
        }
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 22 with Broadcast

use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.

the class BaseBroadcastListResource method onLoadFinished.

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

Aggregations

Broadcast (me.zhanghai.android.douya.network.api.info.frodo.Broadcast)22 Subscribe (org.greenrobot.eventbus.Subscribe)7 Context (android.content.Context)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 TextUtils (android.text.TextUtils)2 View (android.view.View)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 BindView (butterknife.BindView)2 ButterKnife (butterknife.ButterKnife)2 List (java.util.List)2 R (me.zhanghai.android.douya.R)2 BroadcastUpdatedEvent (me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)2 ApiError (me.zhanghai.android.douya.network.api.ApiError)2 SizedImageItem (me.zhanghai.android.douya.ui.SizedImageItem)2 ViewUtils (me.zhanghai.android.douya.util.ViewUtils)2 Bundle (android.os.Bundle)1 AttributeSet (android.util.AttributeSet)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1