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;
}
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);
}
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();
}
}
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)));
}
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;
}
}
Aggregations