Skip to content

Commit

Permalink
Initialize the HttpURLConnectionClient lazily. Closes parse-community#8
Browse files Browse the repository at this point in the history
  • Loading branch information
vjames19 committed Feb 9, 2016
1 parent 4bb89cb commit 8936721
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions library/src/main/java/com/parse/twitter/Twitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
*/
package com.parse.twitter;

import com.parse.internal.signpost.basic.DefaultOAuthConsumer;
import com.parse.internal.signpost.basic.DefaultOAuthProvider;
import com.parse.internal.signpost.basic.HttpURLConnectionClient;
import org.apache.http.client.methods.HttpUriRequest;

import android.app.ProgressDialog;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.webkit.CookieSyncManager;

import com.parse.oauth.OAuth1FlowDialog;
import com.parse.oauth.OAuth1FlowException;
import com.parse.oauth.OAuth1FlowDialog.FlowResultHandler;
import com.parse.internal.signpost.OAuthConsumer;
import com.parse.internal.signpost.OAuthProvider;
import com.parse.internal.signpost.basic.DefaultOAuthConsumer;
import com.parse.internal.signpost.basic.DefaultOAuthProvider;
import com.parse.internal.signpost.basic.HttpURLConnectionClient;
import com.parse.internal.signpost.commonshttp.CommonsHttpOAuthConsumer;
import com.parse.internal.signpost.http.HttpParameters;
import com.parse.oauth.OAuth1FlowDialog;
import com.parse.oauth.OAuth1FlowDialog.FlowResultHandler;
import com.parse.oauth.OAuth1FlowException;

import org.apache.http.client.methods.HttpUriRequest;

import java.net.HttpURLConnection;

Expand All @@ -52,8 +52,6 @@ public class Twitter {
private String userId;
private String screenName;

private final HttpURLConnectionClient httpURLConnectionClient = HttpURLConnectionClient.create();

public Twitter(String consumerKey, String consumerSecret) {
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
Expand Down Expand Up @@ -137,7 +135,7 @@ public void authorize(final Context context, final AsyncCallback callback) {
}

final OAuthProvider provider = new DefaultOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_URL,
httpURLConnectionClient);
getHttpUrlConnectionClientInstance());
provider.setRequestHeader("User-Agent", USER_AGENT);
final OAuthConsumer consumer = new DefaultOAuthConsumer(getConsumerKey(), getConsumerSecret());

Expand Down Expand Up @@ -247,4 +245,11 @@ protected String doInBackground(Void... params) {
task.execute();
}

private static class HttpURLClientLazySingletonHolder {
static final HttpURLConnectionClient INSTANCE = HttpURLConnectionClient.create();
}

private HttpURLConnectionClient getHttpUrlConnectionClientInstance() {
return HttpURLClientLazySingletonHolder.INSTANCE;
}
}

0 comments on commit 8936721

Please sign in to comment.