Add preference to allow mobile updates of images
This commit is contained in:
parent
56de034c7c
commit
0fda36b9b3
|
@ -16,10 +16,11 @@
|
|||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/download_pref_details">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefMobileUpdate"
|
||||
<ListPreference
|
||||
android:defaultValue="images"
|
||||
android:entries="@array/mobile_update_entries"
|
||||
android:entryValues="@array/mobile_update_values"
|
||||
android:key="prefMobileUpdateAllowed"
|
||||
android:summary="@string/pref_mobileUpdate_sum"
|
||||
android:title="@string/pref_mobileUpdate_title"/>
|
||||
<de.danoeh.antennapod.preferences.NumberPickerPreference
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue