Merge pull request #5308 from ByteHamster/remove-cache-size
Remove image cache size setting and choose size automatically
This commit is contained in:
commit
324761fd09
@ -1,7 +1,6 @@
|
|||||||
package de.danoeh.antennapod.fragment.preferences;
|
package de.danoeh.antennapod.fragment.preferences;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||||
@ -43,22 +42,6 @@ public class StoragePreferencesFragment extends PreferenceFragmentCompat {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
findPreference(UserPreferences.PREF_IMAGE_CACHE_SIZE).setOnPreferenceChangeListener(
|
|
||||||
(preference, o) -> {
|
|
||||||
if (o instanceof String) {
|
|
||||||
int newValue = Integer.parseInt((String) o) * 1024 * 1024;
|
|
||||||
if (newValue != UserPreferences.getImageCacheSize()) {
|
|
||||||
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
|
|
||||||
dialog.setTitle(android.R.string.dialog_alert_title);
|
|
||||||
dialog.setMessage(R.string.pref_restart_required);
|
|
||||||
dialog.setPositiveButton(android.R.string.ok, null);
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
findPreference(PREF_IMPORT_EXPORT).setOnPreferenceClickListener(
|
findPreference(PREF_IMPORT_EXPORT).setOnPreferenceClickListener(
|
||||||
preference -> {
|
preference -> {
|
||||||
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_import_export);
|
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_import_export);
|
||||||
|
@ -6,13 +6,6 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:title="@string/choose_data_directory"
|
android:title="@string/choose_data_directory"
|
||||||
android:key="prefChooseDataDir"/>
|
android:key="prefChooseDataDir"/>
|
||||||
<ListPreference
|
|
||||||
android:entryValues="@array/image_cache_size_values"
|
|
||||||
android:entries="@array/image_cache_size_options"
|
|
||||||
android:title="@string/pref_image_cache_size_title"
|
|
||||||
android:key="prefImageCacheSize"
|
|
||||||
android:summary="@string/pref_image_cache_size_sum"
|
|
||||||
android:defaultValue="100"/>
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package de.danoeh.antennapod.core.glide;
|
package de.danoeh.antennapod.core.glide;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
@ -16,7 +18,6 @@ import de.danoeh.antennapod.core.util.EmbeddedChapterImage;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,12 +25,18 @@ import java.nio.ByteBuffer;
|
|||||||
*/
|
*/
|
||||||
@GlideModule
|
@GlideModule
|
||||||
public class ApGlideModule extends AppGlideModule {
|
public class ApGlideModule extends AppGlideModule {
|
||||||
|
private static final String TAG = "ApGlideModule";
|
||||||
|
private static final long MEGABYTES = 1024 * 1024;
|
||||||
|
private static final long GIGABYTES = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
|
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
|
||||||
builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
|
builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
|
||||||
builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
|
@SuppressLint("UsableSpace")
|
||||||
UserPreferences.getImageCacheSize()));
|
long spaceAvailable = context.getCacheDir().getUsableSpace();
|
||||||
|
long imageCacheSize = (spaceAvailable > 2 * GIGABYTES) ? (250 * MEGABYTES) : (50 * MEGABYTES);
|
||||||
|
Log.d(TAG, "Free space on cache dir: " + spaceAvailable + ", using image cache size: " + imageCacheSize);
|
||||||
|
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, imageCacheSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,7 +116,6 @@ public class UserPreferences {
|
|||||||
|
|
||||||
// Other
|
// Other
|
||||||
private static final String PREF_DATA_FOLDER = "prefDataFolder";
|
private static final String PREF_DATA_FOLDER = "prefDataFolder";
|
||||||
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
|
|
||||||
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
|
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
|
||||||
public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
|
public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
|
||||||
|
|
||||||
@ -129,8 +128,6 @@ public class UserPreferences {
|
|||||||
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
|
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
|
||||||
private static final String PREF_REWIND_SECS = "prefRewindSecs";
|
private static final String PREF_REWIND_SECS = "prefRewindSecs";
|
||||||
private static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
|
private static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
|
||||||
private static final String IMAGE_CACHE_DEFAULT_VALUE = "100";
|
|
||||||
private static final int IMAGE_CACHE_SIZE_MINIMUM = 20;
|
|
||||||
private static final String PREF_LEFT_VOLUME = "prefLeftVolume";
|
private static final String PREF_LEFT_VOLUME = "prefLeftVolume";
|
||||||
private static final String PREF_RIGHT_VOLUME = "prefRightVolume";
|
private static final String PREF_RIGHT_VOLUME = "prefRightVolume";
|
||||||
|
|
||||||
@ -616,18 +613,6 @@ public class UserPreferences {
|
|||||||
return Build.VERSION.SDK_INT < 29 && prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
|
return Build.VERSION.SDK_INT < 29 && prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getImageCacheSize() {
|
|
||||||
String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE);
|
|
||||||
int cacheSizeInt = Integer.parseInt(cacheSizeString);
|
|
||||||
// if the cache size is too small the user won't get any images at all
|
|
||||||
// that's bad, force it back to the default.
|
|
||||||
if (cacheSizeInt < IMAGE_CACHE_SIZE_MINIMUM) {
|
|
||||||
prefs.edit().putString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE).apply();
|
|
||||||
cacheSizeInt = Integer.parseInt(IMAGE_CACHE_DEFAULT_VALUE);
|
|
||||||
}
|
|
||||||
return cacheSizeInt * 1024 * 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getFastForwardSecs() {
|
public static int getFastForwardSecs() {
|
||||||
return prefs.getInt(PREF_FAST_FORWARD_SECS, 30);
|
return prefs.getInt(PREF_FAST_FORWARD_SECS, 30);
|
||||||
}
|
}
|
||||||
|
@ -270,22 +270,6 @@
|
|||||||
<item>DURATION_LONG_SHORT</item>
|
<item>DURATION_LONG_SHORT</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="image_cache_size_options">
|
|
||||||
<item>20 MiB</item>
|
|
||||||
<item>50 MiB</item>
|
|
||||||
<item>100 MiB</item>
|
|
||||||
<item>250 MiB</item>
|
|
||||||
<item>500 MiB</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="image_cache_size_values">
|
|
||||||
<item>20</item>
|
|
||||||
<item>50</item>
|
|
||||||
<item>100</item>
|
|
||||||
<item>250</item>
|
|
||||||
<item>500</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="compact_notification_buttons_options">
|
<string-array name="compact_notification_buttons_options">
|
||||||
<item>@string/rewind_label</item>
|
<item>@string/rewind_label</item>
|
||||||
<item>@string/fast_forward_label</item>
|
<item>@string/fast_forward_label</item>
|
||||||
|
@ -484,8 +484,6 @@
|
|||||||
<string name="enqueue_location_front">Front</string>
|
<string name="enqueue_location_front">Front</string>
|
||||||
<string name="enqueue_location_after_current">After current episode</string>
|
<string name="enqueue_location_after_current">After current episode</string>
|
||||||
<string name="pref_smart_mark_as_played_disabled">Disabled</string>
|
<string name="pref_smart_mark_as_played_disabled">Disabled</string>
|
||||||
<string name="pref_image_cache_size_title">Image Cache Size</string>
|
|
||||||
<string name="pref_image_cache_size_sum">Size of the disk cache for images.</string>
|
|
||||||
<string name="documentation_support">Documentation & Support</string>
|
<string name="documentation_support">Documentation & Support</string>
|
||||||
<string name="visit_user_forum">User forum</string>
|
<string name="visit_user_forum">User forum</string>
|
||||||
<string name="bug_report_title">Report bug</string>
|
<string name="bug_report_title">Report bug</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user