use of org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload in project WordPress-Android by wordpress-mobile.
the class CommentsActivity method onModerateComment.
@Override
public void onModerateComment(final SiteModel site, final CommentModel comment, final CommentStatus newStatus) {
FragmentManager fm = getFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
}
if (newStatus == CommentStatus.APPROVED || newStatus == CommentStatus.UNAPPROVED) {
getListFragment().updateEmptyView();
comment.setStatus(newStatus.toString());
mDispatcher.dispatch(CommentActionBuilder.newUpdateCommentAction(comment));
mDispatcher.dispatch(CommentActionBuilder.newPushCommentAction(new RemoteCommentPayload(mSite, comment)));
} else if (newStatus == CommentStatus.SPAM || newStatus == CommentStatus.TRASH || newStatus == CommentStatus.DELETED) {
mTrashedComments.add(comment);
getListFragment().removeComment(comment);
String message = (newStatus == CommentStatus.TRASH ? getString(R.string.comment_trashed) : newStatus == CommentStatus.SPAM ? getString(R.string.comment_spammed) : getString(R.string.comment_deleted_permanently));
View.OnClickListener undoListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mTrashedComments.remove(comment);
getListFragment().loadComments();
}
};
Snackbar snackbar = Snackbar.make(getListFragment().getView(), message, Snackbar.LENGTH_LONG).setAction(R.string.undo, undoListener);
// do the actual moderation once the undo bar has been hidden
snackbar.setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
// comment will no longer exist in moderating list if action was undone
if (!mTrashedComments.contains(comment)) {
return;
}
mTrashedComments.remove(comment);
moderateComment(comment, newStatus);
}
});
snackbar.show();
}
}
use of org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload in project WordPress-Android by wordpress-mobile.
the class EditCommentActivity method loadCommentFromNote.
private void loadCommentFromNote(String noteId) {
mNote = NotificationsTable.getNoteById(noteId);
if (mNote != null) {
setFetchProgressVisible(true);
mSite = mSiteStore.getSiteBySiteId(mNote.getSiteId());
RemoteCommentPayload payload = new RemoteCommentPayload(mSite, mNote.getCommentId());
mFetchingComment = true;
mDispatcher.dispatch(CommentActionBuilder.newFetchCommentAction(payload));
} else {
showErrorAndFinish();
}
}
use of org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload in project WordPress-Android by wordpress-mobile.
the class CommentDetailFragment method showComment.
/*
* display the current comment
*/
private void showComment() {
if (!isAdded() || getView() == null)
return;
// these two views contain all the other views except the progress bar
final ScrollView scrollView = (ScrollView) getView().findViewById(R.id.scroll_view);
final View layoutBottom = getView().findViewById(R.id.layout_bottom);
// hide container views when comment is null (will happen when opened from a notification)
if (mComment == null) {
scrollView.setVisibility(View.GONE);
layoutBottom.setVisibility(View.GONE);
if (mNote != null) {
SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
if (site == null) {
ToastUtils.showToast(getActivity(), R.string.error_load_comment);
return;
}
// Check if the comment is already in our store
CommentModel comment = mCommentStore.getCommentBySiteAndRemoteId(site, mNote.getCommentId());
if (comment != null) {
// It exists, then show it as a "Notification"
showCommentAsNotification(mNote, site, comment);
} else {
// It's not in our store yet, request it.
RemoteCommentPayload payload = new RemoteCommentPayload(site, mNote.getCommentId());
mDispatcher.dispatch(CommentActionBuilder.newFetchCommentAction(payload));
setProgressVisible(true);
// Show a "temporary" comment built from the note data, the view will be refreshed once the
// comment has been fetched.
showCommentAsNotification(mNote, site, null);
}
}
return;
}
scrollView.setVisibility(View.VISIBLE);
layoutBottom.setVisibility(View.VISIBLE);
// Add action buttons footer
if (mNote == null && mLayoutButtons.getParent() == null) {
mCommentContentLayout.addView(mLayoutButtons);
}
final WPNetworkImageView imgAvatar = (WPNetworkImageView) getView().findViewById(R.id.image_avatar);
final TextView txtName = (TextView) getView().findViewById(R.id.text_name);
final TextView txtDate = (TextView) getView().findViewById(R.id.text_date);
txtName.setText(mComment.getAuthorName() == null ? getString(R.string.anonymous) : HtmlUtils.fastUnescapeHtml(mComment.getAuthorName()));
txtDate.setText(DateTimeUtils.javaDateToTimeSpan(DateTimeUtils.dateFromIso8601(mComment.getDatePublished()), WordPress.getContext()));
int maxImageSz = getResources().getDimensionPixelSize(R.dimen.reader_comment_max_image_size);
CommentUtils.displayHtmlComment(mTxtContent, mComment.getContent(), maxImageSz, mImageLoader);
int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_large);
if (mComment.getAuthorProfileImageUrl() != null) {
imgAvatar.setImageUrl(GravatarUtils.fixGravatarUrl(mComment.getAuthorProfileImageUrl(), avatarSz), WPNetworkImageView.ImageType.AVATAR);
} else if (mComment.getAuthorEmail() != null) {
String avatarUrl = GravatarUtils.gravatarFromEmail(mComment.getAuthorEmail(), avatarSz);
imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
} else {
imgAvatar.setImageUrl(null, WPNetworkImageView.ImageType.AVATAR);
}
updateStatusViews();
// navigate to author's blog when avatar or name clicked
if (mComment.getAuthorUrl() != null) {
View.OnClickListener authorListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
ReaderActivityLauncher.openUrl(getActivity(), mComment.getAuthorUrl());
}
};
imgAvatar.setOnClickListener(authorListener);
txtName.setOnClickListener(authorListener);
txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.reader_hyperlink));
} else {
txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.grey_darken_30));
}
showPostTitle(mSite, mComment.getRemotePostId());
// make sure reply box is showing
if (mLayoutReply.getVisibility() != View.VISIBLE && canReply()) {
AniUtils.animateBottomBar(mLayoutReply, true);
if (mEditReply != null && mShouldFocusReplyField) {
mEditReply.performClick();
disableShouldFocusReplyField();
}
}
getFragmentManager().invalidateOptionsMenu();
}
use of org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload in project WordPress-Android by wordpress-mobile.
the class EditCommentActivity method saveComment.
private void saveComment() {
// make sure comment content was entered
final EditText editContent = (EditText) findViewById(R.id.edit_comment_content);
if (EditTextUtils.isEmpty(editContent)) {
editContent.setError(getString(R.string.content_required));
return;
}
// return immediately if comment hasn't changed
if (!isCommentEdited()) {
ToastUtils.showToast(this, R.string.toast_comment_unedited);
return;
}
// make sure we have an active connection
if (!NetworkUtils.checkConnection(this)) {
return;
}
showSaveDialog();
mComment.setContent(getEditTextStr(R.id.edit_comment_content));
mDispatcher.dispatch(CommentActionBuilder.newPushCommentAction(new RemoteCommentPayload(mSite, mComment)));
}
Aggregations