Add auto download on mobile connection option

This commit is contained in:
Anders Bo Rasmussen 2017-09-21 23:25:18 +02:00
parent f20a656e62
commit 7060e56a69
4 changed files with 25 additions and 0 deletions

View File

@ -218,6 +218,11 @@
android:title="@string/pref_automatic_download_on_battery_title" android:title="@string/pref_automatic_download_on_battery_title"
android:summary="@string/pref_automatic_download_on_battery_sum" android:summary="@string/pref_automatic_download_on_battery_sum"
android:defaultValue="true"/> android:defaultValue="true"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadOnMobile"
android:title="@string/pref_autodl_allow_on_mobile_title"
android:summary="@string/pref_autodl_allow_on_mobile_sum"
android:defaultValue="false"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference <de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadWifiFilter" android:key="prefEnableAutoDownloadWifiFilter"
android:title="@string/pref_autodl_wifi_filter_title" android:title="@string/pref_autodl_wifi_filter_title"

View File

@ -83,6 +83,7 @@ public class UserPreferences {
public static final String PREF_ENABLE_AUTODL = "prefEnableAutoDl"; 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_ON_BATTERY = "prefEnableAutoDownloadOnBattery";
public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter";
public static final String PREF_ENABLE_AUTODL_ON_MOBILE = "prefEnableAutoDownloadOnMobile";
public static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; public static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
public static final String PREF_PROXY_TYPE = "prefProxyType"; public static final String PREF_PROXY_TYPE = "prefProxyType";
public static final String PREF_PROXY_HOST = "prefProxyHost"; public static final String PREF_PROXY_HOST = "prefProxyHost";
@ -396,6 +397,11 @@ public class UserPreferences {
return prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false); 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() { public static int getImageCacheSize() {
String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE); String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE);
int cacheSizeInt = Integer.parseInt(cacheSizeString); int cacheSizeInt = Integer.parseInt(cacheSizeString);

View File

@ -66,6 +66,18 @@ public class NetworkUtils {
} }
} }
} }
} else {
if (!UserPreferences.isEnableAutodownloadOnMobile())
{
Log.d(TAG, "Auto Download not enabled on Mobile");
return false;
}
if (networkInfo.isRoaming())
{
Log.d(TAG, "Roaming on foreign network");
return false;
}
return true;
} }
} }
Log.d(TAG, "Network for auto-dl is not available"); Log.d(TAG, "Network for auto-dl is not available");

View File

@ -363,6 +363,8 @@
<string name="pref_automatic_download_sum">Configure the automatic download of episodes.</string> <string name="pref_automatic_download_sum">Configure the automatic download of episodes.</string>
<string name="pref_autodl_wifi_filter_title">Enable Wi-Fi filter</string> <string name="pref_autodl_wifi_filter_title">Enable Wi-Fi filter</string>
<string name="pref_autodl_wifi_filter_sum">Allow automatic download only for selected Wi-Fi networks.</string> <string name="pref_autodl_wifi_filter_sum">Allow automatic download only for selected Wi-Fi networks.</string>
<string name="pref_autodl_allow_on_mobile_title">Download on mobile connection</string>
<string name="pref_autodl_allow_on_mobile_sum">Allow automatic download over the mobile data connection.</string>
<string name="pref_automatic_download_on_battery_title">Download when not charging</string> <string name="pref_automatic_download_on_battery_title">Download when not charging</string>
<string name="pref_automatic_download_on_battery_sum">Allow automatic download when the battery is not charging</string> <string name="pref_automatic_download_on_battery_sum">Allow automatic download when the battery is not charging</string>
<string name="pref_parallel_downloads_title">Parallel Downloads</string> <string name="pref_parallel_downloads_title">Parallel Downloads</string>