Permalink
Browse files

Now making sure blog is valid before loading comments

  • Loading branch information...
1 parent 060074e commit 52505eb54081badf402d8e68035ca78374147fce @nbradbury nbradbury committed Feb 22, 2014
@@ -313,7 +313,7 @@ protected void onCancelled() {
}
@Override
protected Boolean doInBackground(Void... params) {
- int localBlogId = WordPress.currentBlog.getLocalTableBlogId();
+ int localBlogId = WordPress.getCurrentLocalTableBlogId();
tmpComments = CommentTable.getCommentsForBlog(localBlogId);
if (mComments.isSameList(tmpComments))
return false;
@@ -8,6 +8,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -21,6 +22,7 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
+import org.wordpress.android.models.Blog;
import org.wordpress.android.models.Comment;
import org.wordpress.android.models.CommentList;
import org.wordpress.android.models.CommentStatus;
@@ -316,7 +318,7 @@ protected void updateComments(boolean loadMore) {
private class UpdateCommentsTask extends AsyncTask<Void, Void, CommentList> {
boolean isError;
final boolean isLoadingMore;
- String errorMessage;
+ String xmlRpcErrorMessage;
private UpdateCommentsTask(boolean loadMore) {
isLoadingMore = loadMore;
@@ -344,6 +346,12 @@ protected CommentList doInBackground(Void... args) {
if (!hasActivity())
return null;
+ Blog blog = WordPress.getCurrentBlog();
+ if (blog == null) {
+ isError = true;
+ return null;
+ }
+
Map<String, Object> hPost = new HashMap<String, Object>();
if (isLoadingMore) {
int numExisting = getCommentAdapter().getCount();
@@ -353,14 +361,14 @@ protected CommentList doInBackground(Void... args) {
hPost.put("number", COMMENTS_PER_PAGE);
}
- Object[] params = { WordPress.currentBlog.getRemoteBlogId(),
- WordPress.currentBlog.getUsername(),
- WordPress.currentBlog.getPassword(),
+ Object[] params = { blog.getRemoteBlogId(),
+ blog.getUsername(),
+ blog.getPassword(),
hPost };
try {
return ApiHelper.refreshComments(getActivity(), params);
} catch (XMLRPCException e) {
- errorMessage = e.getMessage();
+ xmlRpcErrorMessage = e.getMessage();
isError = true;
return null;
}
@@ -384,8 +392,13 @@ protected void onPostExecute(CommentList comments) {
// result will be null on error OR if no more comments exists
if (comments == null) {
- if (isError && !getActivity().isFinishing())
- ToastUtils.showToastOrAuthAlert(getActivity(), errorMessage, getString(R.string.error_refresh_comments));
+ if (isError && !getActivity().isFinishing()) {
+ if (!TextUtils.isEmpty(xmlRpcErrorMessage)) {
+ ToastUtils.showToastOrAuthAlert(getActivity(), xmlRpcErrorMessage, getString(R.string.error_refresh_comments));
+ } else {
+ ToastUtils.showToast(getActivity(), getString(R.string.error_refresh_comments));
+ }
+ }
return;
}

0 comments on commit 52505eb

Please sign in to comment.