use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.
the class TimelineBroadcastListResource method onBroadcastUpdated.
@Subscribe(threadMode = ThreadMode.POSTING)
public void onBroadcastUpdated(BroadcastUpdatedEvent event) {
if (event.isFromMyself(this) || isEmpty()) {
return;
}
List<Broadcast> broadcastList = get();
for (int i = 0, size = broadcastList.size(); i < size; ++i) {
Broadcast updatedBroadcast = event.update(broadcastList.get(i), this);
if (updatedBroadcast != null) {
broadcastList.set(i, updatedBroadcast);
getListener().onBroadcastChanged(getRequestCode(), i, updatedBroadcast);
}
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.
the class TimelineBroadcastListResource method onLoadFinished.
private 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 {
setAndNotifyListener(response, true);
}
for (Broadcast broadcast : response) {
EventBusUtils.postAsync(new BroadcastUpdatedEvent(broadcast, this));
}
// Frodo API is sometimes buggy that broadcast list size may not be count. In this case,
// we simply load more until no more broadcast is returned.
setCanLoadMore(count == 0 || response.size() > 0);
} else {
getListener().onLoadBroadcastListFinished(getRequestCode());
getListener().onLoadBroadcastListError(getRequestCode(), error);
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.
the class BroadcastActivityDialogFragment method onBroadcastUpdated.
@Subscribe(threadMode = ThreadMode.POSTING)
public void onBroadcastUpdated(BroadcastUpdatedEvent event) {
if (event.isFromMyself(this)) {
return;
}
Broadcast updatedBroadcast = event.update(mBroadcast, this);
if (updatedBroadcast != null) {
mBroadcast = updatedBroadcast;
updateTabTitle();
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.
the class BroadcastFragment method updateOptionsMenu.
private void updateOptionsMenu() {
if (mCopyTextMenuItem == null && mDeleteMenuItem == null) {
return;
}
Broadcast broadcast = mResource.getEffectiveBroadcast();
boolean hasBroadcast = broadcast != null;
mCopyTextMenuItem.setEnabled(hasBroadcast);
boolean canDelete = hasBroadcast && broadcast.isAuthorOneself();
mDeleteMenuItem.setVisible(canDelete);
}
use of me.zhanghai.android.douya.network.api.info.frodo.Broadcast in project Douya by DreaminginCodeZH.
the class BroadcastFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsHelperFragment.attachTo(this);
mResource = BroadcastAndCommentListResource.attachTo(mBroadcastId, mBroadcast, this);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setTitle(getTitle());
activity.setSupportActionBar(mToolbar);
mContainerLayout.setOnClickListener(view -> onFinish());
ViewCompat.setTransitionName(mSharedView, Broadcast.makeTransitionName(mBroadcastId));
// This magically gives better visual effect when the broadcast is partially visible. Using
// setEnterSharedElementCallback() disables this hack when no transition is used to start
// this Activity.
ActivityCompat.setEnterSharedElementCallback(activity, new SharedElementCallback() {
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
mBroadcastCommentList.scrollToPosition(0);
}
});
mToolbar.setOnDoubleClickListener(view -> {
mBroadcastCommentList.smoothScrollToPosition(0);
return true;
});
mSwipeRefreshLayout.setOnRefreshListener(() -> {
mResource.loadBroadcast();
mResource.loadCommentList(false);
});
mBroadcastCommentList.setHasFixedSize(true);
mBroadcastCommentList.setItemAnimator(new NoChangeAnimationItemAnimator());
mBroadcastCommentList.setLayoutManager(new LinearLayoutManager(activity));
mBroadcastAdapter = new SingleBroadcastAdapter(null, this);
// BroadcastLayout will take care of showing the effective broadcast.
// noinspection deprecation
setBroadcast(mResource.getBroadcast());
mCommentAdapter = new CommentAdapter(mResource.getCommentList(), (parent, itemView, item, position) -> onShowCommentAction(item));
mAdapter = new LoadMoreAdapter(mBroadcastAdapter, mCommentAdapter);
mBroadcastCommentList.setAdapter(mAdapter);
mBroadcastCommentList.addOnScrollListener(new OnVerticalScrollListener() {
public void onScrolledToBottom() {
mResource.loadCommentList(true);
}
});
mSendButton.setOnClickListener(view -> onSendComment());
TooltipUtils.setup(mSendButton);
View.OnLongClickListener sendTooltipListener = mSendButton.getOnLongClickListener();
mSendButton.setOnLongClickListener(view -> {
if (!Settings.LONG_CLICK_TO_SHOW_SEND_COMMENT_ACTIVITY.getValue()) {
return sendTooltipListener.onLongClick(view);
}
onShowSendCommentActivity();
return true;
});
updateSendCommentStatus();
if (savedInstanceState == null) {
if (mShowSendComment) {
TransitionUtils.postAfterTransition(this, this::onShowCommentIme);
}
}
TransitionUtils.setEnterReturnExplode(this);
TransitionUtils.setupTransitionOnActivityCreated(this);
}
Aggregations