Search in sources :

Example 1 with Broadcast

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);
        }
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with Broadcast

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);
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) BroadcastUpdatedEvent(me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)

Example 3 with Broadcast

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();
    }
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 4 with Broadcast

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);
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast)

Example 5 with Broadcast

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);
}
Also used : ToastUtils(me.zhanghai.android.douya.util.ToastUtils) Bundle(android.os.Bundle) DoubleClickToolbar(me.zhanghai.android.douya.ui.DoubleClickToolbar) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) ProgressBar(android.widget.ProgressBar) FrameLayout(android.widget.FrameLayout) Comment(me.zhanghai.android.douya.network.api.info.frodo.Comment) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) GetOnLongClickListenerImageButton(me.zhanghai.android.douya.ui.GetOnLongClickListenerImageButton) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) BindView(butterknife.BindView) FragmentUtils(me.zhanghai.android.douya.util.FragmentUtils) ShareUtils(me.zhanghai.android.douya.util.ShareUtils) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator) ViewCompat(androidx.core.view.ViewCompat) WebViewActivity(me.zhanghai.android.douya.ui.WebViewActivity) DeleteBroadcastManager(me.zhanghai.android.douya.broadcast.content.DeleteBroadcastManager) LikeBroadcastManager(me.zhanghai.android.douya.broadcast.content.LikeBroadcastManager) ConfirmDiscardContentDialogFragment(me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) DoubanUtils(me.zhanghai.android.douya.util.DoubanUtils) List(java.util.List) Nullable(androidx.annotation.Nullable) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CustomTabsHelperFragment(me.zhanghai.android.customtabshelper.CustomTabsHelperFragment) EventBusUtils(me.zhanghai.android.douya.eventbus.EventBusUtils) ButterKnife(butterknife.ButterKnife) BroadcastCommentSentEvent(me.zhanghai.android.douya.eventbus.BroadcastCommentSentEvent) ApiError(me.zhanghai.android.douya.network.api.ApiError) FragmentFinishable(me.zhanghai.android.douya.ui.FragmentFinishable) MenuItem(android.view.MenuItem) Settings(me.zhanghai.android.douya.settings.info.Settings) ImeUtils(me.zhanghai.android.douya.util.ImeUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ClipboardUtils(me.zhanghai.android.douya.util.ClipboardUtils) LogUtils(me.zhanghai.android.douya.util.LogUtils) Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) TooltipUtils(me.zhanghai.android.douya.util.TooltipUtils) BroadcastCommentSendErrorEvent(me.zhanghai.android.douya.eventbus.BroadcastCommentSendErrorEvent) ActivityCompat(androidx.core.app.ActivityCompat) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) LayoutInflater(android.view.LayoutInflater) ViewUtils(me.zhanghai.android.douya.util.ViewUtils) DeleteBroadcastCommentManager(me.zhanghai.android.douya.broadcast.content.DeleteBroadcastCommentManager) TransitionUtils(me.zhanghai.android.douya.util.TransitionUtils) TextUtils(android.text.TextUtils) R(me.zhanghai.android.douya.R) BroadcastCommentCountFixer(me.zhanghai.android.douya.broadcast.content.BroadcastCommentCountFixer) RebroadcastBroadcastManager(me.zhanghai.android.douya.broadcast.content.RebroadcastBroadcastManager) Subscribe(org.greenrobot.eventbus.Subscribe) SendBroadcastCommentManager(me.zhanghai.android.douya.broadcast.content.SendBroadcastCommentManager) BroadcastAndCommentListResource(me.zhanghai.android.douya.broadcast.content.BroadcastAndCommentListResource) SharedElementCallback(androidx.core.app.SharedElementCallback) Activity(android.app.Activity) EditText(android.widget.EditText) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SharedElementCallback(androidx.core.app.SharedElementCallback) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

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