mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
feat: added external memory cache option
This commit is contained in:
parent
c4e8fe5261
commit
477331da6f
7 changed files with 188 additions and 4 deletions
|
|
@ -38,11 +38,13 @@ public final class DownloadUtil {
|
|||
public static final String DOWNLOAD_NOTIFICATION_SUCCESSFUL_GROUP = "com.cappielloantonio.tempo.SuccessfulDownload";
|
||||
public static final String DOWNLOAD_NOTIFICATION_FAILED_GROUP = "com.cappielloantonio.tempo.FailedDownload";
|
||||
|
||||
private static final String STREAMING_CACHE_CONTENT_DIRECTORY = "streaming_cache";
|
||||
private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads";
|
||||
|
||||
private static DataSource.Factory dataSourceFactory;
|
||||
private static DataSource.Factory httpDataSourceFactory;
|
||||
private static DatabaseProvider databaseProvider;
|
||||
private static File streamingCacheDirectory;
|
||||
private static File downloadDirectory;
|
||||
private static Cache downloadCache;
|
||||
private static SimpleCache streamingCache;
|
||||
|
|
@ -135,7 +137,7 @@ public final class DownloadUtil {
|
|||
|
||||
private static synchronized SimpleCache getStreamingCache(Context context) {
|
||||
if (streamingCache == null) {
|
||||
File streamingCacheDirectory = new File(context.getCacheDir(), "streamingCache");
|
||||
File streamingCacheDirectory = new File(getStreamingCacheDirectory(context), STREAMING_CACHE_CONTENT_DIRECTORY);
|
||||
|
||||
streamingCache = new SimpleCache(
|
||||
streamingCacheDirectory,
|
||||
|
|
@ -169,6 +171,27 @@ public final class DownloadUtil {
|
|||
return databaseProvider;
|
||||
}
|
||||
|
||||
private static synchronized File getStreamingCacheDirectory(Context context) {
|
||||
if (streamingCacheDirectory == null) {
|
||||
if (Preferences.getStreamingCacheStoragePreference() == 0) {
|
||||
streamingCacheDirectory = context.getExternalFilesDirs(null)[0];
|
||||
if (streamingCacheDirectory == null) {
|
||||
streamingCacheDirectory = context.getFilesDir();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
streamingCacheDirectory = context.getExternalFilesDirs(null)[1];
|
||||
} catch (Exception exception) {
|
||||
streamingCacheDirectory = context.getExternalFilesDirs(null)[0];
|
||||
Preferences.setStreamingCacheStoragePreference(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return streamingCacheDirectory;
|
||||
}
|
||||
|
||||
private static synchronized File getDownloadDirectory(Context context) {
|
||||
if (downloadDirectory == null) {
|
||||
if (Preferences.getDownloadStoragePreference() == 0) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ object Preferences {
|
|||
private const val MUSIC_DIRECTORY_SECTION_VISIBILITY = "music_directory_section_visibility"
|
||||
private const val REPLAY_GAIN_MODE = "replay_gain_mode"
|
||||
private const val AUDIO_TRANSCODE_PRIORITY = "audio_transcode_priority"
|
||||
private const val STREAMING_CACHE_STORAGE = "streaming_cache_storage"
|
||||
private const val DOWNLOAD_STORAGE = "download_storage"
|
||||
private const val DEFAULT_DOWNLOAD_VIEW_TYPE = "default_download_view_type"
|
||||
private const val AUDIO_TRANSCODE_DOWNLOAD = "audio_transcode_download"
|
||||
|
|
@ -310,6 +311,19 @@ object Preferences {
|
|||
return App.getInstance().preferences.getBoolean(AUDIO_TRANSCODE_PRIORITY, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getStreamingCacheStoragePreference(): Int {
|
||||
return App.getInstance().preferences.getString(STREAMING_CACHE_STORAGE, "0")!!.toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStreamingCacheStoragePreference(streamingCachePreference: Int) {
|
||||
return App.getInstance().preferences.edit().putString(
|
||||
STREAMING_CACHE_STORAGE,
|
||||
streamingCachePreference.toString()
|
||||
).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDownloadStoragePreference(): Int {
|
||||
return App.getInstance().preferences.getString(DOWNLOAD_STORAGE, "0")!!.toInt()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue