summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hennen <tom.hennen@gmail.com>2015-08-19 21:03:31 -0400
committerTom Hennen <tom.hennen@gmail.com>2015-08-19 21:03:31 -0400
commit1e1b5ff99b0d0ffb8c5948ba96d01e410905177c (patch)
tree5d0286cc6056a2e5c7061453d2bb1e4b29a19cc9
parentb7ac013b5b45ca5c601a7d05e2b0e54e84c6779b (diff)
downloadAntennaPod-1e1b5ff99b0d0ffb8c5948ba96d01e410905177c.zip
Can now download things while on mobile.
The glide url loader now uses its own OkHttpClient. The result is that we can now search for podcasts and download them while on mobile even if the user doesn't allow mobile downloads (NOTE that we don't do anything they haven't asked us to do while on mobile). fixes AntennaPod/AntennaPod#1101
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java46
2 files changed, 30 insertions, 18 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
index c7ac146b5..cf3af7d4c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java
@@ -43,7 +43,7 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
if (internalClient == null) {
synchronized (Factory.class) {
if (internalClient == null) {
- internalClient = AntennapodHttpClient.getHttpClient();
+ internalClient = AntennapodHttpClient.newHttpClient();
internalClient.interceptors().add(new NetworkAllowanceInterceptor());
internalClient.interceptors().add(new BasicAuthenticationInterceptor());
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
index ec3d3e2fe..012678cd0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
@@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.service.download;
+import android.support.annotation.NonNull;
import android.util.Log;
import com.squareup.okhttp.OkHttpClient;
@@ -30,29 +31,40 @@ public class AntennapodHttpClient {
public static synchronized OkHttpClient getHttpClient() {
if (httpClient == null) {
- if (BuildConfig.DEBUG) Log.d(TAG, "Creating new instance of HTTP client");
+ httpClient = newHttpClient();
+ }
+ return httpClient;
+ }
- System.setProperty("http.maxConnections", String.valueOf(MAX_CONNECTIONS));
+ /**
+ * Creates a new HTTP client. Most users should just use
+ * getHttpClient() to get the standard AntennaPod client,
+ * but sometimes it's necessary for others to have their own
+ * copy so that the clients don't share state.
+ * @return http client
+ */
+ @NonNull
+ public static OkHttpClient newHttpClient() {
+ Log.d(TAG, "Creating new instance of HTTP client");
- OkHttpClient client = new OkHttpClient();
+ System.setProperty("http.maxConnections", String.valueOf(MAX_CONNECTIONS));
- // set cookie handler
- CookieManager cm = new CookieManager();
- cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
- client.setCookieHandler(cm);
+ OkHttpClient client = new OkHttpClient();
- // set timeouts
- client.setConnectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- client.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
- client.setWriteTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
+ // set cookie handler
+ CookieManager cm = new CookieManager();
+ cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
+ client.setCookieHandler(cm);
- // configure redirects
- client.setFollowRedirects(true);
- client.setFollowSslRedirects(true);
+ // set timeouts
+ client.setConnectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+ client.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
+ client.setWriteTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
- httpClient = client;
- }
- return httpClient;
+ // configure redirects
+ client.setFollowRedirects(true);
+ client.setFollowSslRedirects(true);
+ return client;
}
/**