private void submitComment(final long replyToCommentId) { final EditText editComment = (EditText) findViewById(R.id.edit_comment); final String commentText = EditTextUtils.getText(editComment); if (TextUtils.isEmpty(commentText)) return; // hide the comment box - this provides immediate indication that comment is being posted // and prevents users from submitting the same comment twice hideAddCommentBox(); // generate a "fake" comment id to assign to the new comment so we can add it to the db // and reflect it in the adapter before the API call returns final long fakeCommentId = ReaderCommentActions.generateFakeCommentId(); mIsSubmittingComment = true; ReaderActions.CommentActionListener actionListener = new ReaderActions.CommentActionListener() { @Override public void onActionResult(boolean succeeded, ReaderComment newComment) { mIsSubmittingComment = false; if (succeeded) { // comment posted successfully so stop highlighting the fake one and replace // it with the real one getCommentAdapter().setHighlightCommentId(0, false); getCommentAdapter().replaceComment(fakeCommentId, newComment); getListView().invalidateViews(); } else { // comment failed to post - show the comment box again with the comment text intact, // and remove the "fake" comment from the adapter editComment.setText(commentText); showAddCommentBox(replyToCommentId); getCommentAdapter().removeComment(fakeCommentId); ToastUtils.showToast( ReaderPostDetailActivity.this, R.string.reader_toast_err_comment_failed, ToastUtils.Duration.LONG); } } }; final ReaderComment newComment = ReaderCommentActions.submitPostComment( mPost, fakeCommentId, commentText, replyToCommentId, actionListener); if (newComment != null) { mIsPostChanged = true; editComment.setText(null); // add the "fake" comment to the adapter, highlight it, and show a progress bar // next to it while it's submitted getCommentAdapter().setHighlightCommentId(newComment.commentId, true); getCommentAdapter().addComment(newComment); // make sure it's scrolled into view scrollToCommentId(fakeCommentId); } }
/* * follow the tag or url the user typed into the EditText */ private void addCurrentEntry() { String entry = EditTextUtils.getText(mEditAdd).trim(); if (TextUtils.isEmpty(entry)) { return; } // is it a url or a tag? boolean isUrl = !entry.contains(" ") && (entry.contains(".") || entry.contains("://")); if (isUrl) { addAsUrl(entry); } else { addAsTag(entry); } }
private void hideAddCommentBox() { if (!mIsAddCommentBoxShowing) return; final EditText editComment = (EditText) findViewById(R.id.edit_comment); final ViewGroup layoutCommentBox = (ViewGroup) findViewById(R.id.layout_comment_box); final TextView btnComment = (TextView) findViewById(R.id.btn_comment); btnComment.setSelected(false); ReaderAniUtils.flyOut(layoutCommentBox); EditTextUtils.hideSoftInput(editComment); getCommentAdapter().setHighlightCommentId(0, false); mIsAddCommentBoxShowing = false; mReplyToCommentId = 0; }
/* * follow editText entry as a tag */ private void addAsTag(final String entry) { if (TextUtils.isEmpty(entry)) { return; } if (!ReaderTag.isValidTagName(entry)) { ToastUtils.showToast(this, R.string.reader_toast_err_tag_invalid); return; } if (ReaderTagTable.isFollowedTagName(entry)) { ToastUtils.showToast(this, R.string.reader_toast_err_tag_exists); return; } // tag is valid, follow it mEditAdd.setText(null); EditTextUtils.hideSoftInput(mEditAdd); performAddTag(entry); }