diff options
author | ByteHamster <info@bytehamster.com> | 2019-07-25 00:38:00 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-07-25 00:38:00 +0200 |
commit | be42cc0c7176c056a5b1b7c2b0d16ad6e9850312 (patch) | |
tree | 7c3191c842cbc9e2899b608786e80eee7782ab9d /core/src | |
parent | 5173dd0118ab6683013c45297c0eb589d0a52a65 (diff) | |
download | AntennaPod-be42cc0c7176c056a5b1b7c2b0d16ad6e9850312.zip |
Refactored mobile updates setting
Diffstat (limited to 'core/src')
6 files changed, 91 insertions, 26 deletions
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 8f5f5ae1e..bcc4f533e 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 @@ -17,7 +17,9 @@ import java.io.IOException; import java.net.Proxy; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; @@ -78,14 +80,13 @@ public class UserPreferences { // Network private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded"; public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall"; - public static final String PREF_MOBILE_UPDATE = "prefMobileUpdateAllowed"; + private static final String PREF_MOBILE_UPDATE = "prefMobileUpdateTypes"; 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"; public static final String PREF_ENABLE_AUTODL = "prefEnableAutoDl"; public static final String PREF_ENABLE_AUTODL_ON_BATTERY = "prefEnableAutoDownloadOnBattery"; public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; - public static final String PREF_ENABLE_AUTODL_ON_MOBILE = "prefEnableAutoDownloadOnMobile"; private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; private static final String PREF_PROXY_TYPE = "prefProxyType"; private static final String PREF_PROXY_HOST = "prefProxyHost"; @@ -379,16 +380,63 @@ public class UserPreferences { return prefs.getString(PREF_UPDATE_INTERVAL, "").equals("0"); } - public static String getMobileUpdatesEnabled() { - return prefs.getString(PREF_MOBILE_UPDATE, "images"); + private static boolean isAllowMobileFor(String type) { + HashSet<String> defaultValue = new HashSet<>(); + defaultValue.add("images"); + Set<String> allowed = prefs.getStringSet(PREF_MOBILE_UPDATE, defaultValue); + return allowed.contains(type); } - public static boolean isAllowMobileUpdate() { - return getMobileUpdatesEnabled().equals("everything"); + public static boolean isAllowMobileFeedRefresh() { + return isAllowMobileFor("feed_refresh"); + } + + public static boolean isAllowMobileEpisodeDownload() { + return isAllowMobileFor("episode_download"); + } + + public static boolean isAllowMobileAutoDownload() { + return isAllowMobileFor("auto_download"); + } + + public static boolean isAllowMobileStreaming() { + return isAllowMobileFor("streaming"); } public static boolean isAllowMobileImages() { - return isAllowMobileUpdate() || getMobileUpdatesEnabled().equals("images"); + return isAllowMobileFor("images"); + } + + private static void setAllowMobileFor(String type, boolean allow) { + HashSet<String> defaultValue = new HashSet<>(); + defaultValue.add("images"); + Set<String> allowed = prefs.getStringSet(PREF_MOBILE_UPDATE, defaultValue); + if (allow) { + allowed.remove(type); + } else { + allowed.add(type); + } + prefs.edit().putStringSet(PREF_MOBILE_UPDATE, allowed).apply(); + } + + public static void setAllowMobileFeedRefresh(boolean allow) { + setAllowMobileFor("feed_refresh", allow); + } + + public static void setAllowMobileEpisodeDownload(boolean allow) { + setAllowMobileFor("episode_download", allow); + } + + public static void setAllowMobileAutoDownload(boolean allow) { + setAllowMobileFor("auto_download", allow); + } + + public static void setAllowMobileStreaming(boolean allow) { + setAllowMobileFor("streaming", allow); + } + + public static void setAllowMobileImages(boolean allow) { + setAllowMobileFor("images", allow); } public static int getParallelDownloads() { @@ -420,11 +468,6 @@ public class UserPreferences { return prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false); } - public static boolean isEnableAutodownloadOnMobile() { - return prefs.getBoolean(PREF_ENABLE_AUTODL_ON_MOBILE, false); - } - - public static int getImageCacheSize() { String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE); int cacheSizeInt = Integer.parseInt(cacheSizeString); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java index a0195975f..b425687ae 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java @@ -24,7 +24,7 @@ public class FeedUpdateUtils { with().pollInterval(1, TimeUnit.SECONDS) .await() .atMost(10, TimeUnit.SECONDS) - .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()); + .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isFeedRefreshAllowed()); DBTasks.refreshAllFeeds(context, null, callback); } catch (ConditionTimeoutException ignore) { Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); 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 d9431bc5d..ca48c9bc9 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 @@ -74,7 +74,7 @@ public class NetworkUtils { return true; } } else { - if (!UserPreferences.isEnableAutodownloadOnMobile()) { + if (!UserPreferences.isAllowMobileAutoDownload()) { Log.d(TAG, "Auto Download not enabled on Mobile"); return false; } @@ -95,14 +95,28 @@ public class NetworkUtils { return info != null && info.isConnected(); } - public static boolean isDownloadAllowed() { - return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered(); + public static boolean isEpisodeDownloadAllowed() { + return UserPreferences.isAllowMobileEpisodeDownload() || !NetworkUtils.isNetworkMetered(); + } + + public static boolean isEpisodeHeadDownloadAllowed() { + // It is not an image but it is a similarly tiny request + // that is probably not even considered a download by most users + return isImageAllowed(); } public static boolean isImageAllowed() { return UserPreferences.isAllowMobileImages() || !NetworkUtils.isNetworkMetered(); } + public static boolean isStreamingAllowed() { + return UserPreferences.isAllowMobileStreaming() || !NetworkUtils.isNetworkMetered(); + } + + public static boolean isFeedRefreshAllowed() { + return UserPreferences.isAllowMobileFeedRefresh() || !NetworkUtils.isNetworkMetered(); + } + private static boolean isNetworkMetered() { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); @@ -123,7 +137,7 @@ public class NetworkUtils { public static Single<Long> getFeedMediaSizeObservable(FeedMedia media) { return Single.create((SingleOnSubscribe<Long>) emitter -> { - if (!NetworkUtils.isDownloadAllowed()) { + if (!NetworkUtils.isEpisodeHeadDownloadAllowed()) { emitter.onSuccess(0L); return; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java index e5aaa2db0..412b150fa 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java @@ -67,7 +67,7 @@ public class AutoUpdateManager { private static Constraints getConstraints() { Constraints.Builder constraints = new Constraints.Builder(); - if (UserPreferences.isAllowMobileUpdate()) { + if (UserPreferences.isAllowMobileFeedRefresh()) { constraints.setRequiredNetworkType(NetworkType.CONNECTED); } else { constraints.setRequiredNetworkType(NetworkType.UNMETERED); diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 39d1c0a94..d5f1c30b1 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -62,15 +62,19 @@ </string-array> <string-array name="mobile_update_entries"> - <item>@string/pref_mobileUpdate_nothing</item> + <item>@string/pref_mobileUpdate_refresh</item> + <item>@string/pref_mobileUpdate_episode_download</item> + <item>@string/pref_mobileUpdate_auto_download</item> + <item>@string/pref_mobileUpdate_streaming</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>feed_refresh</item> + <item>episode_download</item> + <item>auto_download</item> + <item>streaming</item> <item>images</item> - <item>everything</item> </string-array> <string-array name="episode_cleanup_entries"> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 6025dc888..82a56cf88 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -265,6 +265,8 @@ <string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string> <string name="confirm_mobile_download_dialog_message_not_in_queue">Downloading over mobile data connection is disabled in the settings.\n\nYou can choose to either only add the episode to the queue or you can allow downloading temporarily.\n\n<small>Your choice will be remembered for 10 minutes.</small></string> <string name="confirm_mobile_download_dialog_message">Downloading over mobile data connection is disabled in the settings.\n\nDo you want to allow downloading temporarily?\n\n<small>Your choice will be remembered for 10 minutes.</small></string> + <string name="confirm_mobile_streaming_dialog_title">Confirm Mobile streaming</string> + <string name="confirm_mobile_streaming_dialog_message">Streaming over mobile data connection is disabled in the settings. Do you want to stream anyway?</string> <string name="confirm_mobile_download_dialog_only_add_to_queue">Enqueue</string> <string name="confirm_mobile_download_dialog_enable_temporarily">Allow temporarily</string> @@ -386,10 +388,12 @@ <string name="pref_unpauseOnHeadsetReconnect_title">Headphones Reconnect</string> <string name="pref_unpauseOnBluetoothReconnect_title">Bluetooth Reconnect</string> <string name="pref_mobileUpdate_title">Mobile Updates</string> - <string name="pref_mobileUpdate_sum">Allow updates and manual episode downloads 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="pref_mobileUpdate_sum">Select what should be allowed over the mobile data connection</string> + <string name="pref_mobileUpdate_refresh">Feed refresh</string> + <string name="pref_mobileUpdate_images">Cover images</string> + <string name="pref_mobileUpdate_auto_download">Auto download</string> + <string name="pref_mobileUpdate_episode_download">Episode download</string> + <string name="pref_mobileUpdate_streaming">Streaming</string> <string name="refreshing_label">Refreshing</string> <string name="user_interface_label">User Interface</string> <string name="pref_set_theme_title">Select Theme</string> |