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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.wordpress.android.util.ptr.PullToRefreshHelper;
import org.wordpress.android.util.ptr.PullToRefreshHelper.RefreshListener;
import org.xmlrpc.android.ApiHelper;
import org.xmlrpc.android.ApiHelper.ErrorType;
import org.xmlrpc.android.XMLRPCFault;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -406,12 +408,12 @@ void updateComments(boolean loadMore) {
* task to retrieve latest comments from server
*/
private class UpdateCommentsTask extends AsyncTask<Void, Void, CommentList> {
boolean isError;
final boolean isLoadingMore;
ErrorType mErrorType = ErrorType.NO_ERROR;
final boolean mIsLoadingMore;
boolean mRetryOnCancelled;

private UpdateCommentsTask(boolean loadMore) {
isLoadingMore = loadMore;
mIsLoadingMore = loadMore;
}

public void setRetryOnCancelled(boolean retryOnCancelled) {
Expand All @@ -422,7 +424,7 @@ public void setRetryOnCancelled(boolean retryOnCancelled) {
protected void onPreExecute() {
super.onPreExecute();
mIsUpdatingComments = true;
if (isLoadingMore) {
if (mIsLoadingMore) {
showLoadingProgress();
}
}
Expand All @@ -447,19 +449,19 @@ protected CommentList doInBackground(Void... args) {

Blog blog = WordPress.getCurrentBlog();
if (blog == null) {
isError = true;
mErrorType = ErrorType.INVALID_CURRENT_BLOG;
return null;
}

// the first time this is called, make sure comments deleted on server are removed
// from the local database
if (!mHasCheckedDeletedComments && !isLoadingMore) {
if (!mHasCheckedDeletedComments && !mIsLoadingMore) {
mHasCheckedDeletedComments = true;
ApiHelper.removeDeletedComments(blog);
}

Map<String, Object> hPost = new HashMap<String, Object>();
if (isLoadingMore) {
if (mIsLoadingMore) {
int numExisting = getCommentAdapter().getCount();
hPost.put("offset", numExisting);
hPost.put("number", COMMENTS_PER_PAGE);
Expand All @@ -473,10 +475,15 @@ protected CommentList doInBackground(Void... args) {
hPost };
try {
return ApiHelper.refreshComments(getActivity(), blog, params);
} catch (XMLRPCFault xmlrpcFault) {
mErrorType = ErrorType.UNKNOWN_ERROR;
if (xmlrpcFault.getFaultCode() == 401) {
mErrorType = ErrorType.UNAUTHORIZED;
}
} catch (Exception e) {
isError = true;
return null;
mErrorType = ErrorType.UNKNOWN_ERROR;
}
return null;
}

protected void onPostExecute(CommentList comments) {
Expand All @@ -485,7 +492,7 @@ protected void onPostExecute(CommentList comments) {
if (!isAdded()) {
return;
}
if (isLoadingMore) {
if (mIsLoadingMore) {
hideLoadingProgress();
}
mPullToRefreshHelper.setRefreshing(false);
Expand All @@ -496,13 +503,16 @@ protected void onPostExecute(CommentList comments) {
mCanLoadMoreComments = (comments != null && comments.size() > 0);

// result will be null on error OR if no more comments exists
if (comments == null) {
if (isError && !getActivity().isFinishing()) {
ToastUtils.showToast(getActivity(), getString(R.string.error_refresh_comments));
if (comments == null && !getActivity().isFinishing() && mErrorType != ErrorType.NO_ERROR) {
switch (mErrorType) {
case UNAUTHORIZED:
ToastUtils.showToast(getActivity(), getString(R.string.error_refresh_unauthorized_comments));
return;
default:
ToastUtils.showToast(getActivity(), getString(R.string.error_refresh_comments));
return;
}
return;
}

if (comments.size() > 0) {
getCommentAdapter().loadComments();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,19 @@ public void onFailure(ApiHelper.ErrorType errorType, String errorMessage, Throwa
if (mProgressFooterView != null) {
mProgressFooterView.setVisibility(View.GONE);
}
if (errorType != ErrorType.TASK_CANCELLED) {
ToastUtils.showToast(getActivity(),
mIsPage ? R.string.error_refresh_pages : R.string.error_refresh_posts, Duration.LONG);
if (errorType != ErrorType.TASK_CANCELLED && errorType != ErrorType.NO_ERROR) {
switch (errorType) {
case UNAUTHORIZED:
ToastUtils.showToast(getActivity(),
mIsPage ? R.string.error_refresh_unauthorized_pages : R.string.error_refresh_unauthorized_posts,
Duration.LONG);
return;
default:
ToastUtils.showToast(getActivity(),
mIsPage ? R.string.error_refresh_pages : R.string.error_refresh_posts,
Duration.LONG);
return;
}
}
}
});
Expand Down
14 changes: 12 additions & 2 deletions WordPress/src/main/java/org/xmlrpc/android/ApiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@

public class ApiHelper {
public enum ErrorType {
NO_ERROR, INVALID_CURRENT_BLOG, NETWORK_XMLRPC, INVALID_CONTEXT,
INVALID_RESULT, NO_UPLOAD_FILES_CAP, CAST_EXCEPTION, TASK_CANCELLED}
NO_ERROR, UNKNOWN_ERROR, INVALID_CURRENT_BLOG, NETWORK_XMLRPC, INVALID_CONTEXT,
INVALID_RESULT, NO_UPLOAD_FILES_CAP, CAST_EXCEPTION, TASK_CANCELLED, UNAUTHORIZED
}

public static final Map<String, String> blogOptionsXMLRPCParameters = new HashMap<String, String>();

Expand Down Expand Up @@ -470,11 +471,20 @@ protected Boolean doInBackground(List<?>... params) {
WordPress.wpDB.savePosts(postsList, blog.getLocalTableBlogId(), isPage, !loadMore);
}
return true;
} catch (XMLRPCFault e) {
mErrorType = ErrorType.NETWORK_XMLRPC;
if (e.getFaultCode() == 401) {
mErrorType = ErrorType.UNAUTHORIZED;
}
mErrorMessage = e.getMessage();
} catch (XMLRPCException e) {
mErrorType = ErrorType.NETWORK_XMLRPC;
mErrorMessage = e.getMessage();
} catch (IOException e) {
mErrorType = ErrorType.INVALID_RESULT;
mErrorMessage = e.getMessage();
} catch (XmlPullParserException e) {
mErrorType = ErrorType.INVALID_RESULT;
mErrorMessage = e.getMessage();
}

Expand Down
6 changes: 5 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,17 @@

<!-- Error Messages -->
<string name="error_delete_post">An error occurred while deleting the %s</string>
<!-- The 4 following messages can\'t be factorized due to i18n -->
<!-- The following messages can\'t be factorized due to i18n -->
<string name="error_refresh_posts">Posts couldn\'t be refreshed at this time</string>
<string name="error_refresh_pages">Pages couldn\'t be refreshed at this time</string>
<string name="error_refresh_notifications">Notifications couldn\'t be refreshed at this time</string>
<string name="error_refresh_comments">Comments couldn\'t be refreshed at this time</string>
<string name="error_refresh_stats">Stats couldn\'t be refreshed at this time</string>
<string name="error_refresh_media">Something went wrong while refreshing the media library. Try again later.</string>

<string name="error_refresh_unauthorized_comments">You don\'t have permission to view or edit comments</string>
<string name="error_refresh_unauthorized_pages">You don\'t have permission to view or edit pages</string>
<string name="error_refresh_unauthorized_posts">You don\'t have permission to view or edit posts</string>
<string name="error_generic">An error occurred</string>
<string name="error_parsing_response">An error occurred while fetching data</string>
<string name="error_moderate_comment">An error occurred while moderating</string>
Expand Down