Search in sources :

Example 1 with Broadcast

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

the class BroadcastFragment method updateOptionsMenu.

private void updateOptionsMenu() {
    if (mMenu == null) {
        return;
    }
    Broadcast broadcast = mBroadcastAndCommentListResource.getBroadcast();
    boolean hasBroadcast = broadcast != null;
    mMenu.findItem(R.id.action_copy_text).setVisible(hasBroadcast);
    boolean canDelete = hasBroadcast && broadcast.isAuthorOneself(getActivity());
    mMenu.findItem(R.id.action_delete).setVisible(canDelete);
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.apiv2.Broadcast)

Example 2 with Broadcast

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

the class BroadcastFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    CustomTabsHelperFragment.attachTo(this);
    mBroadcastAndCommentListResource = BroadcastAndCommentListResource.attachTo(mBroadcastId, mBroadcast, this);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setTitle(getTitle());
    activity.setSupportActionBar(mToolbar);
    mContainerLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ActivityCompat.finishAfterTransition(getActivity());
        }
    });
    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);
        }
    });
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mBroadcastAndCommentListResource.loadBroadcast();
            mBroadcastAndCommentListResource.loadCommentList(false);
        }
    });
    mBroadcastCommentList.setHasFixedSize(true);
    mBroadcastCommentList.setItemAnimator(new NoChangeAnimationItemAnimator());
    mBroadcastCommentList.setLayoutManager(new LinearLayoutManager(activity));
    mBroadcastAdapter = new SingleBroadcastAdapter(null, this);
    setBroadcast(mBroadcastAndCommentListResource.getBroadcast());
    mCommentAdapter = new CommentAdapter(mBroadcastAndCommentListResource.getCommentList(), new ClickableSimpleAdapter.OnItemClickListener<Comment, CommentAdapter.ViewHolder>() {

        @Override
        public void onItemClick(RecyclerView parent, Comment item, CommentAdapter.ViewHolder holder) {
            onShowCommentAction(item);
        }
    });
    mAdapter = new LoadMoreAdapter(R.layout.load_more_item, mBroadcastAdapter, mCommentAdapter);
    mBroadcastCommentList.setAdapter(mAdapter);
    mBroadcastCommentList.addOnScrollListener(new OnVerticalScrollListener() {

        public void onScrolledToBottom() {
            mBroadcastAndCommentListResource.loadCommentList(true);
        }
    });
    CheatSheetUtils.setup(mSendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onSendComment();
        }
    });
    updateSendCommentStatus();
    if (savedInstanceState == null) {
        if (mShowSendComment) {
            TransitionUtils.postAfterTransition(this, new Runnable() {

                @Override
                public void run() {
                    onShowSendComment();
                }
            });
        }
    }
    TransitionUtils.setEnterReturnExplode(this);
    TransitionUtils.setupTransitionOnActivityCreated(this);
}
Also used : Comment(me.zhanghai.android.douya.network.api.info.apiv2.Comment) AppCompatActivity(android.support.v7.app.AppCompatActivity) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) SharedElementCallback(android.support.v4.app.SharedElementCallback) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

Example 3 with Broadcast

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

the class BroadcastLayout method bindBroadcast.

public void bindBroadcast(final Broadcast broadcast) {
    final Context context = getContext();
    if (broadcast.isInterest) {
        mAvatarImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recommendation_avatar_icon_grey600_40dp));
        mAvatarImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                UriHandler.open(DoubanUtils.getInterestTypeUrl(broadcast.interestType), context);
            }
        });
    } else {
        ImageUtils.loadAvatar(mAvatarImage, broadcast.author.avatar);
        mAvatarImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                context.startActivity(ProfileActivity.makeIntent(broadcast.author, context));
            }
        });
    }
    mNameText.setText(broadcast.getAuthorName());
    mTimeActionText.setDoubanTimeAndAction(broadcast.createdAt, broadcast.action);
    boolean isRebind = mBoundBroadcastId != null && mBoundBroadcastId == broadcast.id;
    // HACK: Attachment and text should not change on rebind.
    if (!isRebind) {
        Attachment attachment = broadcast.attachment;
        if (attachment != null) {
            mAttachmentLayout.setVisibility(VISIBLE);
            mAttachmentTitleText.setText(attachment.title);
            mAttachmentDescriptionText.setText(attachment.description);
            if (!TextUtils.isEmpty(attachment.image)) {
                mAttachmentImage.setVisibility(VISIBLE);
                ImageUtils.loadImage(mAttachmentImage, attachment.image);
            } else {
                mAttachmentImage.setVisibility(GONE);
            }
            final String attachmentUrl = attachment.href;
            if (!TextUtils.isEmpty(attachmentUrl)) {
                mAttachmentLayout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        UriHandler.open(attachmentUrl, context);
                    }
                });
            } else {
                mAttachmentLayout.setOnClickListener(null);
            }
        } else {
            mAttachmentLayout.setVisibility(GONE);
        }
        final ArrayList<Image> images = broadcast.images.size() > 0 ? broadcast.images : Photo.toImageList(broadcast.photos);
        int numImages = images.size();
        if (numImages == 1) {
            final Image image = images.get(0);
            mSingleImageLayout.setVisibility(VISIBLE);
            mSingleImageLayout.loadImage(image);
            mSingleImageLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    context.startActivity(GalleryActivity.makeIntent(image, context));
                }
            });
        } else {
            mSingleImageLayout.setVisibility(GONE);
        }
        if (numImages > 1) {
            mImageListLayout.setVisibility(VISIBLE);
            mImageListDescriptionText.setText(context.getString(R.string.broadcast_image_list_count_format, numImages));
            mImageListAdapter.replace(images);
            mImageListAdapter.setOnImageClickListener(new HorizontalImageAdapter.OnImageClickListener() {

                @Override
                public void onImageClick(int position) {
                    context.startActivity(GalleryActivity.makeImageListIntent(images, position, context));
                }
            });
        } else {
            mImageListLayout.setVisibility(GONE);
        }
        boolean textSpaceVisible = (attachment != null || numImages > 0) && !TextUtils.isEmpty(broadcast.text);
        ViewUtils.setVisibleOrGone(mTextSpace, textSpaceVisible);
        mTextText.setText(broadcast.getTextWithEntities(context));
    }
    mLikeButton.setText(broadcast.getLikeCountString());
    LikeBroadcastManager likeBroadcastManager = LikeBroadcastManager.getInstance();
    if (likeBroadcastManager.isWriting(broadcast.id)) {
        mLikeButton.setActivated(likeBroadcastManager.isWritingLike(broadcast.id));
        mLikeButton.setEnabled(false);
    } else {
        mLikeButton.setActivated(broadcast.isLiked);
        mLikeButton.setEnabled(true);
    }
    mLikeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onLikeClicked();
            }
        }
    });
    RebroadcastBroadcastManager rebroadcastBroadcastManager = RebroadcastBroadcastManager.getInstance();
    if (rebroadcastBroadcastManager.isWriting(broadcast.id)) {
        mRebroadcastButton.setActivated(rebroadcastBroadcastManager.isWritingRebroadcast(broadcast.id));
        mRebroadcastButton.setEnabled(false);
    } else {
        mRebroadcastButton.setActivated(broadcast.isRebroadcasted());
        mRebroadcastButton.setEnabled(true);
    }
    mRebroadcastButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onRebroadcastClicked();
            }
        }
    });
    mCommentButton.setText(broadcast.getCommentCountString());
    mCommentButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onCommentClicked();
            }
        }
    });
    mBoundBroadcastId = broadcast.id;
}
Also used : Context(android.content.Context) HorizontalImageAdapter(me.zhanghai.android.douya.ui.HorizontalImageAdapter) Attachment(me.zhanghai.android.douya.network.api.info.apiv2.Attachment) Image(me.zhanghai.android.douya.network.api.info.apiv2.Image) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TimeActionTextView(me.zhanghai.android.douya.ui.TimeActionTextView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RebroadcastBroadcastManager(me.zhanghai.android.douya.broadcast.content.RebroadcastBroadcastManager) LikeBroadcastManager(me.zhanghai.android.douya.broadcast.content.LikeBroadcastManager)

Example 4 with Broadcast

use of me.zhanghai.android.douya.network.api.info.apiv2.Broadcast 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 5 with Broadcast

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

the class SingleBroadcastAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final Broadcast broadcast = mBroadcast;
    holder.broadcastLayout.bindBroadcast(broadcast);
    holder.broadcastLayout.setListener(new BroadcastLayout.Listener() {

        @Override
        public void onLikeClicked() {
            mListener.onLike(broadcast, !broadcast.isLiked);
        }

        @Override
        public void onRebroadcastClicked() {
            mListener.onRebroadcast(broadcast, !broadcast.isRebroadcasted());
        }

        @Override
        public void onCommentClicked() {
            mListener.onComment(broadcast);
        }
    });
    holder.viewActivityButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mListener.onViewActivity(broadcast);
        }
    });
}
Also used : Broadcast(me.zhanghai.android.douya.network.api.info.apiv2.Broadcast) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) BindView(butterknife.BindView)

Aggregations

Broadcast (me.zhanghai.android.douya.network.api.info.apiv2.Broadcast)12 View (android.view.View)5 BindView (butterknife.BindView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 TextView (android.widget.TextView)3 Context (android.content.Context)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 ImageView (android.widget.ImageView)2 Image (me.zhanghai.android.douya.network.api.info.apiv2.Image)2 TimeActionTextView (me.zhanghai.android.douya.ui.TimeActionTextView)2 Subscribe (org.greenrobot.eventbus.Subscribe)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 SharedElementCallback (android.support.v4.app.SharedElementCallback)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 CardView (android.support.v7.widget.CardView)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LikeBroadcastManager (me.zhanghai.android.douya.broadcast.content.LikeBroadcastManager)1 RebroadcastBroadcastManager (me.zhanghai.android.douya.broadcast.content.RebroadcastBroadcastManager)1 BroadcastUpdatedEvent (me.zhanghai.android.douya.eventbus.BroadcastUpdatedEvent)1