Search in sources :

Example 1 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class CommentsListFragment method deleteSelectedComments.

private void deleteSelectedComments(boolean deletePermanently) {
    if (!NetworkUtils.checkConnection(getActivity())) {
        return;
    }
    final int dlgId = deletePermanently ? CommentDialogs.ID_COMMENT_DLG_DELETING : CommentDialogs.ID_COMMENT_DLG_TRASHING;
    final CommentList selectedComments = getAdapter().getSelectedComments();
    CommentStatus newStatus = CommentStatus.TRASH;
    if (deletePermanently) {
        newStatus = CommentStatus.DELETED;
    }
    dismissDialog(dlgId);
    finishActionMode();
    moderateComments(selectedComments, newStatus);
}
Also used : CommentList(org.wordpress.android.models.CommentList) CommentStatus(org.wordpress.android.fluxc.model.CommentStatus)

Example 2 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class CommentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    CommentModel comment = mComments.get(position);
    CommentHolder holder = (CommentHolder) viewHolder;
    // Note: following operation can take some time, we could maybe cache the calculated objects (title, spanned
    // content) to make the list scroll smoother.
    holder.txtTitle.setText(Html.fromHtml(getFormattedTitle(comment)));
    holder.txtComment.setText(getSpannedContent(comment));
    holder.txtDate.setText(getFormattedDate(comment, mContext));
    // status is only shown for comments that haven't been approved
    final boolean showStatus;
    CommentStatus commentStatus = CommentStatus.fromString(comment.getStatus());
    switch(commentStatus) {
        case SPAM:
            showStatus = true;
            holder.txtStatus.setText(mStatusTextSpam);
            holder.txtStatus.setTextColor(mStatusColorSpam);
            break;
        case UNAPPROVED:
            showStatus = true;
            holder.txtStatus.setText(mStatusTextUnapproved);
            holder.txtStatus.setTextColor(mStatusColorUnapproved);
            break;
        default:
            showStatus = false;
            break;
    }
    holder.txtStatus.setVisibility(showStatus ? View.VISIBLE : View.GONE);
    int checkmarkVisibility;
    if (mEnableSelection && isItemSelected(position)) {
        checkmarkVisibility = View.VISIBLE;
        holder.containerView.setBackgroundColor(mSelectedColor);
    } else {
        checkmarkVisibility = View.GONE;
        holder.imgAvatar.setImageUrl(getAvatarForDisplay(comment, mAvatarSz), WPNetworkImageView.ImageType.AVATAR);
        holder.containerView.setBackgroundColor(mUnselectedColor);
    }
    if (holder.imgCheckmark.getVisibility() != checkmarkVisibility) {
        holder.imgCheckmark.setVisibility(checkmarkVisibility);
    }
    // comment text needs to be to the left of date/status when the title is a single line and
    // the status is displayed or else the status may overlap the comment text - note that
    // getLineCount() will return 0 if the view hasn't been rendered yet, which is why we
    // check getLineCount() <= 1
    boolean adjustComment = (showStatus && holder.txtTitle.getLineCount() <= 1);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.txtComment.getLayoutParams();
    if (adjustComment) {
        params.addRule(RelativeLayout.LEFT_OF, R.id.layout_date_status);
    } else {
        params.addRule(RelativeLayout.LEFT_OF, 0);
    }
    // request to load more comments when we near the end
    if (mOnLoadMoreListener != null && position >= getItemCount() - 1 && position >= CommentsListFragment.COMMENTS_PER_PAGE - 1) {
        mOnLoadMoreListener.onLoadMore();
    }
}
Also used : RelativeLayout(android.widget.RelativeLayout) CommentStatus(org.wordpress.android.fluxc.model.CommentStatus) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 3 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.comment_detail_fragment, container, false);
    mTxtStatus = (TextView) view.findViewById(R.id.text_status);
    mTxtContent = (TextView) view.findViewById(R.id.text_content);
    mLayoutButtons = (ViewGroup) inflater.inflate(R.layout.comment_action_footer, null, false);
    mBtnLikeComment = mLayoutButtons.findViewById(R.id.btn_like);
    mBtnLikeIcon = (ImageView) mLayoutButtons.findViewById(R.id.btn_like_icon);
    mBtnLikeTextView = (TextView) mLayoutButtons.findViewById(R.id.btn_like_text);
    mBtnModerateComment = mLayoutButtons.findViewById(R.id.btn_moderate);
    mBtnModerateIcon = (ImageView) mLayoutButtons.findViewById(R.id.btn_moderate_icon);
    mBtnModerateTextView = (TextView) mLayoutButtons.findViewById(R.id.btn_moderate_text);
    mBtnEditComment = mLayoutButtons.findViewById(R.id.btn_edit);
    mBtnSpamComment = mLayoutButtons.findViewById(R.id.btn_spam);
    mBtnSpamCommentText = (TextView) mLayoutButtons.findViewById(R.id.btn_spam_text);
    mBtnTrashComment = mLayoutButtons.findViewById(R.id.btn_trash);
    mBtnTrashCommentText = (TextView) mLayoutButtons.findViewById(R.id.btn_trash_text);
    // As we are using CommentDetailFragment in a ViewPager, and we also use nested fragments within
    // CommentDetailFragment itself:
    // It is important to have a live reference to the Comment Container layout at the moment this layout is
    // inflated (onCreateView), so we can make sure we set its ID correctly once we have an actual Comment object
    // to populate it with. Otherwise, we could be searching and finding the container for _another fragment/page
    // in the viewpager_, which would cause strange results (changing the views for a different fragment than we
    // intended to).
    mCommentContentLayout = (ViewGroup) view.findViewById(R.id.comment_content_container);
    mLayoutReply = (ViewGroup) view.findViewById(R.id.layout_comment_box);
    mEditReply = (SuggestionAutoCompleteText) mLayoutReply.findViewById(R.id.edit_comment);
    setReplyUniqueId();
    mSubmitReplyBtn = mLayoutReply.findViewById(R.id.btn_submit_reply);
    // hide comment like button until we know it can be enabled in showCommentAsNotification()
    mBtnLikeComment.setVisibility(View.GONE);
    // hide moderation buttons until updateModerationButtons() is called
    mLayoutButtons.setVisibility(View.GONE);
    // this is necessary in order for anchor tags in the comment text to be clickable
    mTxtContent.setLinksClickable(true);
    mTxtContent.setMovementMethod(WPLinkMovementMethod.getInstance());
    mEditReply.setHint(R.string.reader_hint_comment_on_comment);
    mEditReply.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEND)
                submitReply();
            return false;
        }
    });
    if (!TextUtils.isEmpty(mRestoredReplyText)) {
        mEditReply.setText(mRestoredReplyText);
        mRestoredReplyText = null;
    }
    mSubmitReplyBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            submitReply();
        }
    });
    mBtnSpamComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mComment == null)
                return;
            if (CommentStatus.fromString(mComment.getStatus()) == CommentStatus.SPAM) {
                moderateComment(CommentStatus.APPROVED);
            } else {
                moderateComment(CommentStatus.SPAM);
            }
        }
    });
    mBtnTrashComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mComment == null)
                return;
            CommentStatus status = CommentStatus.fromString(mComment.getStatus());
            // If the comment status is trash or spam, next deletion is a permanent deletion.
            if (status == CommentStatus.TRASH || status == CommentStatus.SPAM) {
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
                dialogBuilder.setTitle(getResources().getText(R.string.delete));
                dialogBuilder.setMessage(getResources().getText(R.string.dlg_sure_to_delete_comment));
                dialogBuilder.setPositiveButton(getResources().getText(R.string.yes), new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        moderateComment(CommentStatus.DELETED);
                    }
                });
                dialogBuilder.setNegativeButton(getResources().getText(R.string.no), null);
                dialogBuilder.setCancelable(true);
                dialogBuilder.create().show();
            } else {
                moderateComment(CommentStatus.TRASH);
            }
        }
    });
    mBtnLikeComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            likeComment(false);
        }
    });
    mBtnEditComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            editComment();
        }
    });
    setupSuggestionServiceAndAdapter();
    return view;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) CommentActionBuilder(org.wordpress.android.fluxc.generated.CommentActionBuilder) CommentStatus(org.wordpress.android.fluxc.model.CommentStatus) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) ScrollView(android.widget.ScrollView) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView)

Example 4 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method performModerateAction.

private void performModerateAction() {
    if (mComment == null || !isAdded() || !NetworkUtils.checkConnection(getActivity())) {
        return;
    }
    CommentStatus newStatus = CommentStatus.APPROVED;
    if (CommentStatus.fromString(mComment.getStatus()) == CommentStatus.APPROVED) {
        newStatus = CommentStatus.UNAPPROVED;
    }
    mComment.setStatus(newStatus.toString());
    setModerateButtonForStatus(newStatus);
    AniUtils.startAnimation(mBtnModerateIcon, R.anim.notifications_button_scale);
    moderateComment(newStatus);
}
Also used : CommentStatus(org.wordpress.android.fluxc.model.CommentStatus)

Example 5 with CommentStatus

use of org.wordpress.android.fluxc.model.CommentStatus in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method updateStatusViews.

/*
     * update the text, drawable & click listener for mBtnModerate based on
     * the current status of the comment, show mBtnSpam if the comment isn't
     * already marked as spam, and show the current status of the comment
     */
private void updateStatusViews() {
    if (!isAdded() || mComment == null) {
        return;
    }
    // string resource id for status text
    final int statusTextResId;
    // color for status text
    final int statusColor;
    CommentStatus commentStatus = CommentStatus.fromString(mComment.getStatus());
    switch(commentStatus) {
        case APPROVED:
            statusTextResId = R.string.comment_status_approved;
            statusColor = ContextCompat.getColor(getActivity(), R.color.notification_status_unapproved_dark);
            break;
        case UNAPPROVED:
            statusTextResId = R.string.comment_status_unapproved;
            statusColor = ContextCompat.getColor(getActivity(), R.color.notification_status_unapproved_dark);
            break;
        case SPAM:
            statusTextResId = R.string.comment_status_spam;
            statusColor = ContextCompat.getColor(getActivity(), R.color.comment_status_spam);
            break;
        case TRASH:
        default:
            statusTextResId = R.string.comment_status_trash;
            statusColor = ContextCompat.getColor(getActivity(), R.color.comment_status_spam);
            break;
    }
    if (canLike()) {
        mBtnLikeComment.setVisibility(View.VISIBLE);
        if (mComment != null) {
            toggleLikeButton(mComment.getILike());
        } else if (mNote != null) {
            mNote.hasLikedComment();
        }
    }
    // comment hasn't been CommentStatus.APPROVED
    if (mIsUsersBlog && commentStatus != CommentStatus.APPROVED) {
        mTxtStatus.setText(getString(statusTextResId).toUpperCase());
        mTxtStatus.setTextColor(statusColor);
        if (mTxtStatus.getVisibility() != View.VISIBLE) {
            mTxtStatus.clearAnimation();
            AniUtils.fadeIn(mTxtStatus, AniUtils.Duration.LONG);
        }
    } else {
        mTxtStatus.setVisibility(View.GONE);
    }
    if (canModerate()) {
        setModerateButtonForStatus(commentStatus);
        mBtnModerateComment.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                performModerateAction();
            }
        });
        mBtnModerateComment.setVisibility(View.VISIBLE);
    } else {
        mBtnModerateComment.setVisibility(View.GONE);
    }
    if (canMarkAsSpam()) {
        mBtnSpamComment.setVisibility(View.VISIBLE);
        if (commentStatus == CommentStatus.SPAM) {
            mBtnSpamCommentText.setText(R.string.mnu_comment_unspam);
        } else {
            mBtnSpamCommentText.setText(R.string.mnu_comment_spam);
        }
    } else {
        mBtnSpamComment.setVisibility(View.GONE);
    }
    if (canTrash()) {
        mBtnTrashComment.setVisibility(View.VISIBLE);
        if (commentStatus == CommentStatus.TRASH) {
            mBtnModerateIcon.setImageResource(R.drawable.ic_undo_grey_24dp);
            mBtnModerateTextView.setText(R.string.mnu_comment_untrash);
            mBtnTrashCommentText.setText(R.string.mnu_comment_delete_permanently);
        } else {
            mBtnTrashCommentText.setText(R.string.mnu_comment_trash);
        }
    } else {
        mBtnTrashComment.setVisibility(View.GONE);
    }
    if (canEdit()) {
        mBtnEditComment.setVisibility(View.VISIBLE);
    }
    mLayoutButtons.setVisibility(View.VISIBLE);
}
Also used : CommentStatus(org.wordpress.android.fluxc.model.CommentStatus) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) ScrollView(android.widget.ScrollView)

Aggregations

CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)6 View (android.view.View)2 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 TextView (android.widget.TextView)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 KeyEvent (android.view.KeyEvent)1 RelativeLayout (android.widget.RelativeLayout)1 CommentActionBuilder (org.wordpress.android.fluxc.generated.CommentActionBuilder)1 CommentModel (org.wordpress.android.fluxc.model.CommentModel)1 CommentList (org.wordpress.android.models.CommentList)1 Note (org.wordpress.android.models.Note)1