Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #955 from wordpress-mobile/issue/954-comment-list-…

…runtime-exception

Issue/954 comment list runtime exception
  • Loading branch information...
commit 76befd8f81cd31866cede7fe405229dc30621ddc 2 parents af9caa3 + ccc2896
@maxme maxme authored
View
2  src/org/wordpress/android/ui/ViewSiteActivity.java
@@ -35,6 +35,8 @@ public void onCreate(Bundle savedInstanceState) {
}
private void loadSiteURL() {
+ if (mBlog == null)
+ return;
String siteURL = null;
Gson gson = new Gson();
Type type = new TypeToken<Map<?, ?>>() {}.getType();
View
7 src/org/wordpress/android/ui/WPActionBarActivity.java
@@ -548,6 +548,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (blogNames.length >= 1) {
setupCurrentBlog();
onBlogChanged();
+ } else {
+ // user has hidden all blogs
+ onBlogChanged();
}
WordPress.registerForCloudMessaging(this);
}
@@ -620,10 +623,10 @@ public void onClick(DialogInterface dialog,
}
/**
- * This method is called when the user changes the active blog.
+ * This method is called when the user changes the active blog or hides all blogs
*/
public void onBlogChanged() {
- WordPress.wpDB.updateLastBlogId(WordPress.currentBlog.getLocalTableBlogId());
+ WordPress.wpDB.updateLastBlogId(WordPress.getCurrentLocalTableBlogId());
// the menu may have changed, we need to change the selection if the selected item
// is not available in the menu anymore
Iterator<MenuDrawerItem> itemIterator = mMenuItems.iterator();
View
2  src/org/wordpress/android/ui/comments/CommentAdapter.java
@@ -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;
View
27 src/org/wordpress/android/ui/comments/CommentsListFragment.java
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.