@@ -97,6 +97,7 @@ public class CommentDetailFragment extends Fragment implements NotificationFragm
9797
9898 private boolean mIsUsersBlog = false ;
9999 private boolean mIsCommentReply = false ;
100+ private boolean mIsSubmittingReply = false ;
100101
101102 private NotificationsDetailListFragment mNotificationsDetailListFragment ;
102103
@@ -625,19 +626,41 @@ private void moderateComment(final CommentStatus newStatus) {
625626 if (!NetworkUtils .checkConnection (getActivity ()))
626627 return ;
627628
628- // Fire the appropriate listener
629+ // Fire the appropriate listener if we have one
629630 if (mNote != null && mOnNoteCommentActionListener != null ) {
630631 mOnNoteCommentActionListener .onModerateCommentForNote (mNote , newStatus );
632+ return ;
631633 } else if (mOnCommentActionListener != null ) {
632634 mOnCommentActionListener .onModerateComment (mLocalBlogId , mComment , newStatus );
635+ return ;
633636 }
637+
638+ if (mNote == null ) return ;
639+
640+ // Basic moderation support, currently only used when this Fragment is in a CommentDetailActivity
641+ // Uses WP.com REST API and requires a note object
642+ final CommentStatus oldStatus = mComment .getStatusEnum ();
643+ mComment .setStatus (CommentStatus .toString (newStatus ));
644+ updateStatusViews ();
645+ CommentActions .moderateCommentRestApi (mNote .getSiteId (), mComment .commentID , newStatus , new CommentActions .CommentActionListener () {
646+ @ Override
647+ public void onActionResult (boolean succeeded ) {
648+ if (!isAdded ()) return ;
649+
650+ if (!succeeded ) {
651+ mComment .setStatus (CommentStatus .toString (oldStatus ));
652+ updateStatusViews ();
653+ ToastUtils .showToast (getActivity (), R .string .error_moderate_comment );
654+ }
655+ }
656+ });
634657 }
635658
636659 /*
637660 * post comment box text as a reply to the current comment
638661 */
639662 private void submitReply () {
640- if (!isAdded ())
663+ if (!isAdded () || mIsSubmittingReply )
641664 return ;
642665
643666 if (!NetworkUtils .checkConnection (getActivity ()))
@@ -653,15 +676,46 @@ private void submitReply() {
653676 mEditReply .setEnabled (false );
654677 EditTextUtils .hideSoftInput (mEditReply );
655678 mImgSubmitReply .setVisibility (View .GONE );
656- ProgressBar progress = (ProgressBar ) getView ().findViewById (R .id .progress_submit_comment );
657- progress .setVisibility (View .VISIBLE );
679+ final ProgressBar progressBar = getView () != null ? (ProgressBar ) getView ().findViewById (R .id .progress_submit_comment ) : null ;
680+ if (getView () != null ) {
681+ progressBar .setVisibility (View .VISIBLE );
682+ }
658683
659- // Fire the appropriate action listener
684+ // Fire the appropriate action listener if we have one
660685 if (mNote != null && mOnNoteCommentActionListener != null ) {
661686 mOnNoteCommentActionListener .onReplyToNote (mNote , replyText );
687+ return ;
662688 } else if (mOnCommentActionListener != null ) {
663689 mOnCommentActionListener .onReplyToComment (mLocalBlogId , mComment , replyText );
690+ return ;
664691 }
692+
693+ if (mNote == null ) return ;
694+
695+ // Handle the reply here if no OnCommentActionListener was provided. Uses WP.com REST API
696+ mIsSubmittingReply = true ;
697+ CommentActions .submitReplyToCommentRestApi (mNote .getSiteId (), mComment .commentID , replyText , new CommentActions .CommentActionListener () {
698+ @ Override
699+ public void onActionResult (boolean succeeded ) {
700+ if (!isAdded ()) return ;
701+
702+ mIsSubmittingReply = false ;
703+ mEditReply .setEnabled (true );
704+ mImgSubmitReply .setVisibility (View .VISIBLE );
705+ if (progressBar != null ) {
706+ progressBar .setVisibility (View .GONE );
707+ }
708+ updateStatusViews ();
709+ if (succeeded ) {
710+ ToastUtils .showToast (getActivity (), getString (R .string .note_reply_successful ));
711+ mEditReply .setText (null );
712+ } else {
713+ ToastUtils .showToast (getActivity (), R .string .reply_failed , ToastUtils .Duration .LONG );
714+ // refocus editor on failure and show soft keyboard
715+ EditTextUtils .showSoftInput (mEditReply );
716+ }
717+ }
718+ });
665719 }
666720
667721 /*
@@ -827,7 +881,7 @@ private boolean canEdit() {
827881 return (mLocalBlogId > 0 && canModerate ());
828882 }
829883 private boolean canLike () {
830- return (mEnabledActions != null && mEnabledActions .contains (EnabledActions .ACTION_LIKE ));
884+ return (! mIsCommentReply && mEnabledActions != null && mEnabledActions .contains (EnabledActions .ACTION_LIKE ));
831885 }
832886
833887 /*
0 commit comments