Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Feb 26, 2014
2 parents de091bb + cd976c4 commit 96de266
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/org/wordpress/android/ui/ViewSiteActivity.java
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/org/wordpress/android/ui/WPActionBarActivity.java
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/org/wordpress/android/ui/comments/CommentAdapter.java
Expand Up @@ -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;
Expand Down
27 changes: 20 additions & 7 deletions src/org/wordpress/android/ui/comments/CommentsListFragment.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -315,7 +317,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;
Expand Down Expand Up @@ -343,6 +345,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();
Expand All @@ -352,14 +360,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;
}
Expand All @@ -383,8 +391,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;
}

Expand Down
52 changes: 29 additions & 23 deletions src/org/xmlrpc/android/XMLRPCClient.java
Expand Up @@ -29,7 +29,9 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -59,7 +61,7 @@ public class XMLRPCClient implements XMLRPCClientInterface {

private Map<Long,Caller> backgroundCalls = new HashMap<Long, Caller>();

private ConnectionClient client;
private DefaultHttpClient client;
private HttpPost postMethod;
private XmlSerializer serializer;
private HttpParams httpParams;
Expand All @@ -86,24 +88,16 @@ public XMLRPCClient(URI uri, String httpuser, String httppasswd) {
//username & password not needed
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(httpuser, httppasswd);

//this gets connections working over https
if (uri.getScheme() != null){
if(uri.getScheme().equals("https")) {
if(uri.getPort() == -1)
try {
client = new ConnectionClient(creds, 443);
} catch (KeyManagementException e) {
client = new ConnectionClient(creds);
} catch (NoSuchAlgorithmException e) {
client = new ConnectionClient(creds);
} catch (KeyStoreException e) {
client = new ConnectionClient(creds);
} catch (UnrecoverableKeyException e) {
client = new ConnectionClient(creds);
}
else
if(uri.getHost().contains("wordpress.com")) {
client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
} else {
//this gets connections working over https
if (uri.getScheme() != null){
if(uri.getScheme().equals("https")) {
if(uri.getPort() == -1)
try {
client = new ConnectionClient(creds, uri.getPort());
client = new ConnectionClient(creds, 443);
} catch (KeyManagementException e) {
client = new ConnectionClient(creds);
} catch (NoSuchAlgorithmException e) {
Expand All @@ -113,15 +107,27 @@ public XMLRPCClient(URI uri, String httpuser, String httppasswd) {
} catch (UnrecoverableKeyException e) {
client = new ConnectionClient(creds);
}
else
try {
client = new ConnectionClient(creds, uri.getPort());
} catch (KeyManagementException e) {
client = new ConnectionClient(creds);
} catch (NoSuchAlgorithmException e) {
client = new ConnectionClient(creds);
} catch (KeyStoreException e) {
client = new ConnectionClient(creds);
} catch (UnrecoverableKeyException e) {
client = new ConnectionClient(creds);
}
}
else {
client = new ConnectionClient(creds);
}
}
else {
else{
client = new ConnectionClient(creds);
}
}
else{
client = new ConnectionClient(creds);
}

serializer = Xml.newSerializer();
}

Expand Down

0 comments on commit 96de266

Please sign in to comment.