add preference for media cache size

This commit is contained in:
dkanada 2020-10-23 05:47:08 +09:00
commit ccce5623b1
4 changed files with 22 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import com.dkanada.gramophone.R;
import com.dkanada.gramophone.model.Song; import com.dkanada.gramophone.model.Song;
import com.dkanada.gramophone.service.playback.Playback; import com.dkanada.gramophone.service.playback.Playback;
import com.dkanada.gramophone.util.MusicUtil; import com.dkanada.gramophone.util.MusicUtil;
import com.dkanada.gramophone.util.PreferenceUtil;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -142,7 +143,8 @@ public class MultiPlayer implements Playback {
exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF); exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF);
if (simpleCache != null) simpleCache.release(); if (simpleCache != null) simpleCache.release();
LeastRecentlyUsedCacheEvictor recentlyUsedCache = new LeastRecentlyUsedCacheEvictor(Long.MAX_VALUE); long cacheSize = PreferenceUtil.getInstance(context).getMediaCacheSize();
LeastRecentlyUsedCacheEvictor recentlyUsedCache = new LeastRecentlyUsedCacheEvictor(cacheSize);
ExoDatabaseProvider databaseProvider = new ExoDatabaseProvider(context); ExoDatabaseProvider databaseProvider = new ExoDatabaseProvider(context);
File file = new File(App.getInstance().getApplicationInfo().dataDir + "/Gelli/exoplayer"); File file = new File(App.getInstance().getApplicationInfo().dataDir + "/Gelli/exoplayer");

View file

@ -83,6 +83,7 @@ public final class PreferenceUtil {
public static final String REMEMBER_QUEUE = "remember_queue"; public static final String REMEMBER_QUEUE = "remember_queue";
public static final String IMAGE_CACHE_SIZE = "image_cache_size"; public static final String IMAGE_CACHE_SIZE = "image_cache_size";
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
private static PreferenceUtil sInstance; private static PreferenceUtil sInstance;
@ -391,6 +392,10 @@ public final class PreferenceUtil {
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000")); return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
} }
public final int getMediaCacheSize() {
return Integer.parseInt(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
}
public List<CategoryInfo> getCategories() { public List<CategoryInfo> getCategories() {
String data = mPreferences.getString(CATEGORIES, null); String data = mPreferences.getString(CATEGORIES, null);
if (data != null) { if (data != null) {

View file

@ -100,7 +100,7 @@
<string name="pref_header_colors">Colors</string> <string name="pref_header_colors">Colors</string>
<string name="pref_header_now_playing_screen">Now Playing</string> <string name="pref_header_now_playing_screen">Now Playing</string>
<string name="pref_header_audio">Audio</string> <string name="pref_header_audio">Audio</string>
<string name="pref_header_images">Images</string> <string name="pref_header_cache">Cache</string>
<string name="pref_header_library">Library</string> <string name="pref_header_library">Library</string>
<string name="pref_header_lock_screen">Lock Screen</string> <string name="pref_header_lock_screen">Lock Screen</string>
<string name="pref_header_notification">Notification</string> <string name="pref_header_notification">Notification</string>
@ -123,7 +123,8 @@
<string name="pref_title_remember_shuffle">Remember Shuffle</string> <string name="pref_title_remember_shuffle">Remember Shuffle</string>
<string name="pref_title_remember_queue">Remember Queue</string> <string name="pref_title_remember_queue">Remember Queue</string>
<string name="pref_title_page_size">Page Size</string> <string name="pref_title_page_size">Page Size</string>
<string name="pref_title_image_cache_size">Cache Size</string> <string name="pref_title_image_cache_size">Images</string>
<string name="pref_title_media_cache_size">Media</string>
<string name="pref_summary_primary_color">The primary theme color for control elements.</string> <string name="pref_summary_primary_color">The primary theme color for control elements.</string>
<string name="pref_summary_accent_color">An alternate color used to accent elements.</string> <string name="pref_summary_accent_color">An alternate color used to accent elements.</string>

View file

@ -2,7 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_images"> <com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_cache">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference <com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
@ -14,6 +14,16 @@
android:positiveButtonText="@null" android:positiveButtonText="@null"
android:title="@string/pref_title_image_cache_size" /> android:title="@string/pref_title_image_cache_size" />
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
app:iconSpaceReserved="false"
android:defaultValue="400000000"
android:entries="@array/pref_cache_size_titles"
android:entryValues="@array/pref_cache_size_values"
android:key="media_cache_size"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_title_media_cache_size" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory> </com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>