Search in sources :

Example 1 with CommentModel

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

the class Note method buildComment.

/**
     * Constructs a new Comment object based off of data in a Note
     */
public CommentModel buildComment() {
    CommentModel comment = new CommentModel();
    comment.setRemotePostId(getPostId());
    comment.setRemoteCommentId(getCommentId());
    comment.setAuthorName(getCommentAuthorName());
    comment.setDatePublished(DateTimeUtils.iso8601FromTimestamp(getTimestamp()));
    comment.setContent(getCommentText());
    comment.setStatus(getCommentStatus().toString());
    comment.setAuthorUrl(getCommentAuthorUrl());
    // unavailable in note model
    comment.setPostTitle(getTitle());
    // unavailable in note model
    comment.setAuthorEmail("");
    comment.setAuthorProfileImageUrl(getIconURL());
    comment.setILike(hasLikedComment());
    return comment;
}
Also used : CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 2 with CommentModel

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

the class CommentsListFragment method moderateSelectedComments.

private void moderateSelectedComments(final CommentStatus newStatus) {
    final CommentList selectedComments = getAdapter().getSelectedComments();
    final CommentList updateComments = new CommentList();
    // build list of comments whose status is different than passed
    for (CommentModel comment : selectedComments) {
        if (CommentStatus.fromString(comment.getStatus()) != newStatus) {
            updateComments.add(comment);
        }
    }
    if (updateComments.size() == 0)
        return;
    if (!NetworkUtils.checkConnection(getActivity()))
        return;
    getAdapter().clearSelectedComments();
    finishActionMode();
    moderateComments(updateComments, newStatus);
}
Also used : CommentList(org.wordpress.android.models.CommentList) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 3 with CommentModel

use of org.wordpress.android.fluxc.model.CommentModel 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 4 with CommentModel

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

the class CommentDetailFragment method submitReply.

/*
     * post comment box text as a reply to the current comment
     */
private void submitReply() {
    if (mComment == null || !isAdded() || mIsSubmittingReply)
        return;
    if (!NetworkUtils.checkConnection(getActivity()))
        return;
    final String replyText = EditTextUtils.getText(mEditReply);
    if (TextUtils.isEmpty(replyText))
        return;
    // disable editor, hide soft keyboard, hide submit icon, and show progress spinner while submitting
    mEditReply.setEnabled(false);
    EditTextUtils.hideSoftInput(mEditReply);
    mSubmitReplyBtn.setVisibility(View.GONE);
    final ProgressBar progress = (ProgressBar) getView().findViewById(R.id.progress_submit_comment);
    progress.setVisibility(View.VISIBLE);
    mIsSubmittingReply = true;
    AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_REPLIED_TO);
    // Pseudo comment reply
    CommentModel reply = new CommentModel();
    reply.setContent(replyText);
    mDispatcher.dispatch(CommentActionBuilder.newCreateNewCommentAction(new RemoteCreateCommentPayload(mSite, mComment, reply)));
}
Also used : RemoteCreateCommentPayload(org.wordpress.android.fluxc.store.CommentStore.RemoteCreateCommentPayload) ProgressBar(android.widget.ProgressBar) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 5 with CommentModel

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

the class CommentDetailFragment method onCommentChanged.

// OnChanged events
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCommentChanged(OnCommentChanged event) {
    setProgressVisible(false);
    // Moderating comment
    if (event.causeOfChange == CommentAction.PUSH_COMMENT) {
        onCommentModerated(event);
        mPreviousStatus = null;
        return;
    }
    // New comment (reply)
    if (event.causeOfChange == CommentAction.CREATE_NEW_COMMENT) {
        onCommentCreated(event);
        return;
    }
    // Like/Unlike
    if (event.causeOfChange == CommentAction.LIKE_COMMENT) {
        onCommentLiked(event);
        return;
    }
    if (event.isError()) {
        AppLog.i(T.TESTS, "event error type: " + event.error.type + " - message: " + event.error.message);
        if (isAdded() && !TextUtils.isEmpty(event.error.message)) {
            ToastUtils.showToast(getActivity(), event.error.message);
        }
        return;
    }
    if (mCommentIdToFetch != 0) {
        CommentModel comment = mCommentStore.getCommentBySiteAndRemoteId(mSite, mCommentIdToFetch);
        setComment(comment, mSite);
        mCommentIdToFetch = 0;
    }
}
Also used : CommentModel(org.wordpress.android.fluxc.model.CommentModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

CommentModel (org.wordpress.android.fluxc.model.CommentModel)9 View (android.view.View)2 SiteModel (org.wordpress.android.fluxc.model.SiteModel)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 ImageView (android.widget.ImageView)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 CommentStatus (org.wordpress.android.fluxc.model.CommentStatus)1 RemoteCommentPayload (org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload)1 RemoteCreateCommentPayload (org.wordpress.android.fluxc.store.CommentStore.RemoteCreateCommentPayload)1 CommentList (org.wordpress.android.models.CommentList)1 FilteredRecyclerView (org.wordpress.android.ui.FilteredRecyclerView)1 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)1