Merge pull request #3082 from ByteHamster/mobile-updates
Mobile updates: Allow images
This commit is contained in:
commit
7a98e3c231
|
@ -16,10 +16,11 @@
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/download_pref_details">
|
<PreferenceCategory android:title="@string/download_pref_details">
|
||||||
<SwitchPreference
|
<ListPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="images"
|
||||||
android:enabled="true"
|
android:entries="@array/mobile_update_entries"
|
||||||
android:key="prefMobileUpdate"
|
android:entryValues="@array/mobile_update_values"
|
||||||
|
android:key="prefMobileUpdateAllowed"
|
||||||
android:summary="@string/pref_mobileUpdate_sum"
|
android:summary="@string/pref_mobileUpdate_sum"
|
||||||
android:title="@string/pref_mobileUpdate_title"/>
|
android:title="@string/pref_mobileUpdate_title"/>
|
||||||
<de.danoeh.antennapod.preferences.NumberPickerPreference
|
<de.danoeh.antennapod.preferences.NumberPickerPreference
|
||||||
|
|
|
@ -71,6 +71,11 @@ class UpdateManager {
|
||||||
UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24);
|
UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24);
|
||||||
} // else 0 or special negative values, no change needed
|
} // else 0 or special negative values, no change needed
|
||||||
}
|
}
|
||||||
|
if (oldVersionCode < 1070197) {
|
||||||
|
if (prefs.getBoolean("prefMobileUpdate", false)) {
|
||||||
|
prefs.edit().putString(UserPreferences.PREF_MOBILE_UPDATE, "everything").apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,6 @@ public class ApGlideModule extends AppGlideModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
||||||
registry.append(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
registry.replace(String.class, InputStream.class, new ApOkHttpUrlLoader.Factory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.service.download.HttpDownloader;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.*;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.internal.http.RealResponseBody;
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
|
* @see com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
|
||||||
|
@ -111,10 +109,16 @@ class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response intercept(Chain chain) throws IOException {
|
public Response intercept(Chain chain) throws IOException {
|
||||||
if (NetworkUtils.isDownloadAllowed()) {
|
if (NetworkUtils.isImageAllowed()) {
|
||||||
return chain.proceed(chain.request());
|
return chain.proceed(chain.request());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return new Response.Builder()
|
||||||
|
.protocol(Protocol.HTTP_2)
|
||||||
|
.code(420)
|
||||||
|
.message("Policy Not Fulfilled")
|
||||||
|
.body(ResponseBody.create(null, new byte[0]))
|
||||||
|
.request(chain.request())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class UserPreferences {
|
||||||
// Network
|
// Network
|
||||||
private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded";
|
private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded";
|
||||||
public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
|
public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
|
||||||
private static final String PREF_MOBILE_UPDATE = "prefMobileUpdate";
|
public static final String PREF_MOBILE_UPDATE = "prefMobileUpdateAllowed";
|
||||||
public static final String PREF_EPISODE_CLEANUP = "prefEpisodeCleanup";
|
public static final String PREF_EPISODE_CLEANUP = "prefEpisodeCleanup";
|
||||||
public static final String PREF_PARALLEL_DOWNLOADS = "prefParallelDownloads";
|
public static final String PREF_PARALLEL_DOWNLOADS = "prefParallelDownloads";
|
||||||
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
|
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
|
||||||
|
@ -380,8 +380,16 @@ public class UserPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMobileUpdatesEnabled() {
|
||||||
|
return prefs.getString(PREF_MOBILE_UPDATE, "images");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAllowMobileUpdate() {
|
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() {
|
public static int getParallelDownloads() {
|
||||||
|
|
|
@ -90,9 +90,13 @@ public class NetworkUtils {
|
||||||
return info != null && info.isConnected();
|
return info != null && info.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDownloadAllowed() {
|
public static boolean isDownloadAllowed() {
|
||||||
return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
|
return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isImageAllowed() {
|
||||||
|
return UserPreferences.isAllowMobileImages() || !NetworkUtils.isNetworkMetered();
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isNetworkMetered() {
|
private static boolean isNetworkMetered() {
|
||||||
ConnectivityManager connManager = (ConnectivityManager) context
|
ConnectivityManager connManager = (ConnectivityManager) context
|
||||||
|
|
|
@ -55,6 +55,18 @@
|
||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</string-array>
|
</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">
|
<string-array name="episode_cleanup_entries">
|
||||||
<item>@string/episode_cleanup_queue_removal</item>
|
<item>@string/episode_cleanup_queue_removal</item>
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
|
|
|
@ -388,6 +388,9 @@
|
||||||
<string name="pref_unpauseOnBluetoothReconnect_title">Bluetooth Reconnect</string>
|
<string name="pref_unpauseOnBluetoothReconnect_title">Bluetooth Reconnect</string>
|
||||||
<string name="pref_mobileUpdate_title">Mobile Updates</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_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="refreshing_label">Refreshing</string>
|
||||||
<string name="flattr_settings_label">Flattr settings</string>
|
<string name="flattr_settings_label">Flattr settings</string>
|
||||||
<string name="pref_flattr_auth_title">Flattr sign-in</string>
|
<string name="pref_flattr_auth_title">Flattr sign-in</string>
|
||||||
|
|
Loading…
Reference in New Issue