diff options
author | ByteHamster <info@bytehamster.com> | 2019-04-02 16:06:07 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-04-02 17:41:15 +0200 |
commit | 0fda36b9b3cd698a0d43f7041324dad234e8252c (patch) | |
tree | 4e0e0a04a4d034a042b1fe353dd1426980cf1287 /core | |
parent | 56de034c7c6cb419c72b1d4d218b33f74ab5e0d0 (diff) | |
download | AntennaPod-0fda36b9b3cd698a0d43f7041324dad234e8252c.zip |
Add preference to allow mobile updates of images
Diffstat (limited to 'core')
6 files changed, 48 insertions, 11 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java index 29e2456b2..fb1990370 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java @@ -71,6 +71,11 @@ class UpdateManager { UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24); } // else 0 or special negative values, no change needed } + if (oldVersionCode < 1070197) { + if (prefs.getBoolean(UserPreferences.PREF_MOBILE_UPDATE_OLD, false)) { + prefs.edit().putString(UserPreferences.PREF_MOBILE_UPDATE, "everything").apply(); + } + } } } 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 bd5276100..06dea83f3 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,10 +21,8 @@ import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.core.service.download.HttpDownloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.NetworkUtils; -import okhttp3.Interceptor; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; +import okhttp3.*; +import okhttp3.internal.http.RealResponseBody; /** * @see com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader @@ -111,10 +109,16 @@ class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> { @Override public Response intercept(Chain chain) throws IOException { - if (NetworkUtils.isDownloadAllowed()) { + if (NetworkUtils.isImageAllowed()) { return chain.proceed(chain.request()); } else { - return null; + return new Response.Builder() + .code(420) + .protocol(Protocol.HTTP_2) + .message("Dummy response") + .body(new RealResponseBody(null, 0, null)) + .request(chain.request()) + .build(); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 1feecd849..eb07a0977 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -77,7 +77,8 @@ public class UserPreferences { // Network private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded"; public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall"; - private static final String PREF_MOBILE_UPDATE = "prefMobileUpdate"; + public static final String PREF_MOBILE_UPDATE_OLD = "prefMobileUpdate"; + public static final String PREF_MOBILE_UPDATE = "prefMobileUpdateAllowed"; public static final String PREF_EPISODE_CLEANUP = "prefEpisodeCleanup"; public static final String PREF_PARALLEL_DOWNLOADS = "prefParallelDownloads"; public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; @@ -380,8 +381,16 @@ public class UserPreferences { } } + public static String getMobileUpdatesEnabled() { + return prefs.getString(PREF_MOBILE_UPDATE, "images"); + } + public static boolean isAllowMobileUpdate() { - return prefs.getBoolean(PREF_MOBILE_UPDATE, false); + return getMobileUpdatesEnabled().equals("everything"); + } + + public static boolean isAllowMobileImages() { + return isAllowMobileUpdate() || getMobileUpdatesEnabled().equals("images"); } public static int getParallelDownloads() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java index b34ba196d..9bdd375ce 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java @@ -90,9 +90,13 @@ public class NetworkUtils { return info != null && info.isConnected(); } - public static boolean isDownloadAllowed() { - return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered(); - } + public static boolean isDownloadAllowed() { + return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered(); + } + + public static boolean isImageAllowed() { + return UserPreferences.isAllowMobileImages() || !NetworkUtils.isNetworkMetered(); + } private static boolean isNetworkMetered() { ConnectivityManager connManager = (ConnectivityManager) context diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 157b040e1..6d310e0e5 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -55,6 +55,18 @@ <item>-1</item> </string-array> + <string-array name="mobile_update_entries"> + <item>@string/pref_mobileUpdate_nothing</item> + <item>@string/pref_mobileUpdate_images</item> + <item>@string/pref_mobileUpdate_everything</item> + </string-array> + + <string-array name="mobile_update_values"> + <item>nothing</item> + <item>images</item> + <item>everything</item> + </string-array> + <string-array name="episode_cleanup_entries"> <item>@string/episode_cleanup_queue_removal</item> <item>0</item> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 374cd7360..e47f7f198 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -373,6 +373,9 @@ <string name="pref_unpauseOnBluetoothReconnect_title">Bluetooth Reconnect</string> <string name="pref_mobileUpdate_title">Mobile Updates</string> <string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string> + <string name="pref_mobileUpdate_nothing">Nothing</string> + <string name="pref_mobileUpdate_images">Images only</string> + <string name="pref_mobileUpdate_everything">Everything</string> <string name="refreshing_label">Refreshing</string> <string name="flattr_settings_label">Flattr settings</string> <string name="pref_flattr_auth_title">Flattr sign-in</string> |