diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-08-02 17:51:33 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-08-02 17:51:33 +0200 |
commit | 4165d848d8d8956c4fa14002920ec17729551b34 (patch) | |
tree | 75db60891a063b04a730cc8f1e2758ddfee59aef | |
parent | 2bc1183e45ac0608acbdb6968c603804d7bd0664 (diff) | |
download | AntennaPod-4165d848d8d8956c4fa14002920ec17729551b34.zip |
Respect the mobile download settings
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java | 18 |
1 files changed, 17 insertions, 1 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 33290723b..433ba8db4 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 @@ -21,18 +21,20 @@ import java.net.HttpURLConnection; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.service.download.HttpDownloader; import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.util.NetworkUtils; /** * @see com.bumptech.glide.integration.okhttp.OkHttpUrlLoader */ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> { - private static final String TAG = "ApOkHttpUrlLoader"; + private static final String TAG = ApOkHttpUrlLoader.class.getSimpleName(); /** * The default factory for {@link ApOkHttpUrlLoader}s. */ public static class Factory implements ModelLoaderFactory<GlideUrl, InputStream> { + private static volatile OkHttpClient internalClient; private OkHttpClient client; @@ -41,6 +43,7 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> { synchronized (Factory.class) { if (internalClient == null) { internalClient = new OkHttpClient(); + internalClient.interceptors().add(new NetworkAllowanceInterceptor()); internalClient.interceptors().add(new BasicAuthenticationInterceptor()); } } @@ -84,6 +87,19 @@ public class ApOkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> { return new OkHttpStreamFetcher(client, model); } + private static class NetworkAllowanceInterceptor implements Interceptor { + + @Override + public Response intercept(Chain chain) throws IOException { + if (NetworkUtils.isDownloadAllowed()) { + return chain.proceed(chain.request()); + } else { + return null; + } + } + + } + private static class BasicAuthenticationInterceptor implements Interceptor { @Override |