Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ public static int getCurrentBlogId() {
return (currentBlog != null ? currentBlog.getBlogId() : 0);
}

public static int getCurrentBlogAccountId() {
return (currentBlog != null ? currentBlog.getId() : 0);
}

/**
* Checks for WordPress.com credentials
*
Expand Down
52 changes: 30 additions & 22 deletions src/org/wordpress/android/ui/comments/CommentActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import org.wordpress.android.WordPress;
import org.wordpress.android.models.Blog;
Expand Down Expand Up @@ -42,13 +43,13 @@ protected interface OnCommentChangeListener {
/**
* reply to an individual comment
*/
protected static void submitReplyToComment(final Blog account,
final int blogId,
protected static void submitReplyToComment(final int accountId,
final Comment comment,
final String replyText,
final CommentActionListener actionListener) {

if (account==null || comment==null || TextUtils.isEmpty(replyText)) {
final Blog blog = WordPress.getBlog(accountId);
if (blog==null || comment==null || TextUtils.isEmpty(replyText)) {
if (actionListener != null)
actionListener.onActionResult(false);
return;
Expand All @@ -60,9 +61,9 @@ protected static void submitReplyToComment(final Blog account,
@Override
public void run() {
XMLRPCClient client = new XMLRPCClient(
account.getUrl(),
account.getHttpuser(),
account.getHttppassword());
blog.getUrl(),
blog.getHttpuser(),
blog.getHttppassword());

Map<String, Object> replyHash = new HashMap<String, Object>();
replyHash.put("comment_parent", comment.commentID);
Expand All @@ -71,9 +72,10 @@ public void run() {
replyHash.put("author_url", "");
replyHash.put("author_email", "");

Object[] params = { blogId,
account.getUsername(),
account.getPassword(),
Object[] params = {
blog.getBlogId(),
blog.getUsername(),
blog.getPassword(),
Integer.valueOf(comment.postID),
replyHash };

Expand All @@ -82,12 +84,13 @@ public void run() {
try {
newCommentID = (Integer) client.call("wp.newComment", params);
} catch (XMLRPCException e) {
Log.e(WordPress.TAG, e.getMessage(), e);
newCommentID = -1;
}

final boolean succeeded = (newCommentID >= 0);
if (succeeded)
WordPress.wpDB.updateLatestCommentID(account.getId(), newCommentID);
WordPress.wpDB.updateLatestCommentID(accountId, newCommentID);

if (actionListener != null) {
handler.post(new Runnable() {
Expand All @@ -104,11 +107,13 @@ public void run() {
/**
* change the status of a comment
*/
protected static void moderateComment(final Blog blog,
protected static void moderateComment(final int accountId,
final Comment comment,
final CommentStatus newStatus,
final CommentActionListener actionListener) {

final Blog blog = WordPress.getBlog(accountId);

if (blog==null || comment==null || newStatus==null || newStatus==CommentStatus.UNKNOWN) {
if (actionListener != null)
actionListener.onActionResult(false);
Expand All @@ -120,7 +125,8 @@ protected static void moderateComment(final Blog blog,
new Thread() {
@Override
public void run() {
XMLRPCClient client = new XMLRPCClient(blog.getUrl(),
XMLRPCClient client = new XMLRPCClient(
blog.getUrl(),
blog.getHttpuser(),
blog.getHttppassword());

Expand All @@ -141,6 +147,7 @@ public void run() {
try {
result = client.call("wp.editComment", params);
} catch (final XMLRPCException e) {
Log.e(WordPress.TAG, e.getMessage(), e);
result = null;
}

Expand All @@ -163,11 +170,11 @@ public void run() {
/**
* delete (trash) a single comment
*/
protected static void deleteComment(final Blog account,
final int blogId,
protected static void deleteComment(final int accountId,
final Comment comment,
final CommentActionListener actionListener) {
if (account==null || comment==null) {
final Blog blog = WordPress.getBlog(accountId);
if (blog==null || comment==null) {
if (actionListener != null)
actionListener.onActionResult(false);
return;
Expand All @@ -179,26 +186,27 @@ protected static void deleteComment(final Blog account,
@Override
public void run() {
XMLRPCClient client = new XMLRPCClient(
account.getUrl(),
account.getHttpuser(),
account.getHttppassword());
blog.getUrl(),
blog.getHttpuser(),
blog.getHttppassword());

Object[] params = {
blogId,
account.getUsername(),
account.getPassword(),
blog.getBlogId(),
blog.getUsername(),
blog.getPassword(),
comment.commentID };

Object result;
try {
result = client.call("wp.deleteComment", params);
} catch (final XMLRPCException e) {
Log.e(WordPress.TAG, e.getMessage(), e);
result = null;
}

final boolean success = (result != null && Boolean.parseBoolean(result.toString()));
if (success) {
WordPress.wpDB.deleteComment(account.getId(), comment.commentID);
WordPress.wpDB.deleteComment(accountId, comment.commentID);
}

if (actionListener != null) {
Expand Down
66 changes: 45 additions & 21 deletions src/org/wordpress/android/ui/comments/CommentDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -37,6 +41,7 @@
import org.wordpress.android.util.ReaderAniUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.VolleyUtils;
import org.wordpress.android.util.WPImageGetter;

import java.util.Map;
Expand Down Expand Up @@ -157,12 +162,15 @@ private void hideReplyBox(boolean hideImmediately) {
return;

final ViewGroup layoutReply = (ViewGroup) getActivity().findViewById(R.id.layout_comment_box);
if (layoutReply == null || layoutReply.getVisibility() != View.VISIBLE)
if (layoutReply == null)
return;

// showReplyBox() animation may still be happening, so clear it here
layoutReply.clearAnimation();

if (hideImmediately) {
layoutReply.setVisibility(View.GONE);
} else {
} else if (layoutReply.getVisibility() != View.VISIBLE) {
ReaderAniUtils.flyOut(layoutReply);
}
}
Expand Down Expand Up @@ -290,49 +298,62 @@ public void onClick(View v) {
}
}

/*
* returns true if there's an active network connection, otherwise displays a toast error
* and returns false
*/
// TODO: move this routine to NetworkUtils once that class is merged into develop
private boolean checkConnection(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null && info.isConnected())
return true;

ToastUtils.showToast(getActivity(), R.string.no_network_message);
return false;
}

/*
* approve the current comment
*/
private void approveComment() {
if (!hasActivity() || !hasComment() || mIsApprovingComment)
return;

if (!checkConnection(getActivity()))
return;

final TextView txtBtnApprove = (TextView) getActivity().findViewById(R.id.text_approve);
ReaderAniUtils.flyOut(txtBtnApprove);

// immediately show MessageBox saying comment has been approved - runnable below executes
// once MessageBar disappears
Runnable runnable = new Runnable() {
@Override
public void run() {
showReplyBox();
}
};
MessageBarUtils.showMessageBar(getActivity(),
getString(R.string.comment_approved),
MessageBarUtils.MessageBarType.INFO,
runnable);

mIsApprovingComment = true;
// immediately show MessageBox saying comment has been approved
MessageBarUtils.showMessageBar(getActivity(), getString(R.string.comment_approved));

CommentActions.CommentActionListener actionListener = new CommentActions.CommentActionListener() {
@Override
public void onActionResult(boolean succeeded) {
mIsApprovingComment = false;
if (hasActivity()) {
if (succeeded) {
showReplyBox();
mComment.setStatus(CommentStatus.toString(CommentStatus.APPROVED));
if (mChangeListener != null)
mChangeListener.onCommentModerated();
} else {
hideReplyBox(true);
txtBtnApprove.setVisibility(View.VISIBLE);
ToastUtils.showToast(getActivity(), R.string.error_moderate_comment, ToastUtils.Duration.LONG);
// fly in "Approve" after we know it had enough time to fly out
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ReaderAniUtils.flyIn(txtBtnApprove);
}
}, 500);
}
}
}
};
CommentActions.moderateComment(WordPress.currentBlog, mComment, CommentStatus.APPROVED, actionListener);
mIsApprovingComment = true;
CommentActions.moderateComment(mAccountId, mComment, CommentStatus.APPROVED, actionListener);
}

/*
Expand All @@ -342,6 +363,9 @@ private void submitReply() {
if (!hasActivity() || mIsSubmittingReply)
return;

if (!checkConnection(getActivity()))
return;

final EditText editComment = (EditText) getActivity().findViewById(R.id.edit_comment);
final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.progress_submit_comment);
final ImageView imgSubmit = (ImageView) getActivity().findViewById(R.id.image_post_comment);
Expand Down Expand Up @@ -383,8 +407,7 @@ public void onActionResult(boolean succeeded) {
};

mIsSubmittingReply = true;
CommentActions.submitReplyToComment(WordPress.currentBlog,
mBlogId,
CommentActions.submitReplyToComment(mAccountId,
mComment,
replyText,
actionListener);
Expand Down Expand Up @@ -454,6 +477,7 @@ public void onResponse(JSONObject jsonObject) {
@Override
public void onErrorResponse(VolleyError volleyError) {
mIsRequestingComment = false;
Log.e(WordPress.TAG, VolleyUtils.errStringFromVolleyError(volleyError), volleyError);
if (hasActivity()) {
if (progress != null)
progress.setVisibility(View.GONE);
Expand Down
5 changes: 2 additions & 3 deletions src/org/wordpress/android/ui/comments/CommentsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ public boolean onContextItemSelected(android.view.MenuItem item) {
*/
showDialog(ID_DIALOG_DELETING);
CommentActions.deleteComment(
WordPress.currentBlog,
WordPress.getCurrentBlogId(),
WordPress.getCurrentBlogAccountId(),
WordPress.currentComment,
new CommentActions.CommentActionListener() {
@Override
Expand Down Expand Up @@ -288,7 +287,7 @@ public void onActionResult(boolean succeeded) {
return true;
}

CommentActions.moderateComment(WordPress.currentBlog,
CommentActions.moderateComment(WordPress.getCurrentBlogAccountId(),
WordPress.currentComment,
status,
new CommentActions.CommentActionListener() {
Expand Down