Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Support lazy loading #24

Closed
Closed
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
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 HttpURLConnectionClient getHttpUrlConnectionClientInstance() {
return HttpURLClientLazySingletonHolder.INSTANCE;
}

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