diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index 32c54219e6..bfd8d8148b 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -111,7 +111,6 @@ object PreferenceKeys { // Advanced const val AUTOMATIC_UPDATE_CHECKS = "automatic_update_checks" const val DATA_SAVER_MODE = "data_saver_mode_key" - const val MAX_IMAGE_CACHE = "image_cache_size" const val RESET_SETTINGS = "reset_settings" const val CLEAR_SEARCH_HISTORY = "clear_search_history" const val CLEAR_WATCH_HISTORY = "clear_watch_history" @@ -119,7 +118,6 @@ object PreferenceKeys { const val SHARE_WITH_TIME_CODE = "share_with_time_code" const val SELECTED_SHARE_HOST = "selected_share_host" const val CLEAR_BOOKMARKS = "clear_bookmarks" - const val MAX_CONCURRENT_DOWNLOADS = "max_parallel_downloads" const val EXTERNAL_DOWNLOAD_PROVIDER = "external_download_provider" const val FULL_LOCAL_MODE = "full_local_mode" const val LOCAL_RYD = "local_return_youtube_dislikes" diff --git a/app/src/main/java/com/github/libretube/helpers/DownloadHelper.kt b/app/src/main/java/com/github/libretube/helpers/DownloadHelper.kt index c91c58d934..15127343f8 100644 --- a/app/src/main/java/com/github/libretube/helpers/DownloadHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DownloadHelper.kt @@ -39,6 +39,7 @@ object DownloadHelper { const val PLAYLIST_THUMBNAIL_DIR = "playlist_thumbnail" const val DOWNLOAD_CHUNK_SIZE = 8L * 1024 const val DEFAULT_TIMEOUT = 15 * 1000 + const val MAX_CONCURRENT_DOWNLOADS = 6 private const val VIDEO_MIMETYPE = "video/*" fun getDownloadDir(context: Context, path: String): Path { @@ -51,13 +52,6 @@ object DownloadHelper { return (storageDir.toPath() / path).createDirectories() } - fun getMaxConcurrentDownloads(): Int { - return PreferenceHelper.getString( - PreferenceKeys.MAX_CONCURRENT_DOWNLOADS, - "6" - ).toFloat().toInt() - } - fun startDownloadService(context: Context, downloadData: DownloadData? = null) { val intent = Intent(context, DownloadService::class.java) .putExtra(IntentData.downloadData, downloadData) @@ -171,4 +165,4 @@ object DownloadHelper { DatabaseHolder.Database.downloadDao().deleteDownload(download) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt index 18ea30daf7..06b53b1d2f 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt @@ -4,7 +4,9 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.Color import android.net.Uri +import android.os.storage.StorageManager import android.widget.ImageView +import androidx.core.content.getSystemService import androidx.core.net.toUri import coil3.ImageLoader import coil3.disk.DiskCache @@ -16,14 +18,12 @@ import coil3.request.ImageRequest import coil3.request.crossfade import coil3.toBitmap import com.github.libretube.BuildConfig -import com.github.libretube.constants.PreferenceKeys import com.github.libretube.extensions.toAndroidUri import com.github.libretube.util.DataSaverMode import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor -import java.io.File import java.nio.file.Path object ImageHelper { @@ -36,8 +36,6 @@ object ImageHelper { * Initialize the image loader */ fun initializeImageLoader(context: Context) { - val maxCacheSize = PreferenceHelper.getString(PreferenceKeys.MAX_IMAGE_CACHE, "128") - val httpClient = OkHttpClient().newBuilder() if (BuildConfig.DEBUG) { @@ -56,26 +54,20 @@ object ImageHelper { ) } .apply { - if (maxCacheSize.isEmpty()) { - diskCachePolicy(CachePolicy.DISABLED) - } else { - diskCachePolicy(CachePolicy.ENABLED) - memoryCachePolicy(CachePolicy.ENABLED) - - val diskCache = generateDiskCache( - directory = context.coilFile, - size = maxCacheSize.toInt() - ) - diskCache(diskCache) - } - } - .build() - } + diskCachePolicy(CachePolicy.ENABLED) + memoryCachePolicy(CachePolicy.ENABLED) - private fun generateDiskCache(directory: File, size: Int): DiskCache { - return DiskCache.Builder() - .directory(directory) - .maxSizeBytes(size * 1024 * 1024L) + val storageManager = context.getSystemService()!! + val availableCache = storageManager.getCacheQuotaBytes( + storageManager.getUuidForPath(context.coilFile) + ) + val diskCache = DiskCache.Builder() + .directory(context.coilFile) + // only use a certain percentage of the available cache size for images + .maxSizeBytes(availableCache) + .build() + diskCache(diskCache) + } .build() } diff --git a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt index 3961098c67..f603711f06 100644 --- a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt @@ -10,7 +10,6 @@ import com.github.libretube.R import com.github.libretube.api.TrendingCategory import com.github.libretube.constants.PreferenceKeys import com.github.libretube.enums.SbSkipOptions -import com.github.libretube.extensions.round import com.github.libretube.helpers.LocaleHelper.getDetectedCountry import kotlin.math.roundToInt @@ -147,6 +146,10 @@ object PreferenceHelper { PreferenceMigration(6, 7) { remove("disable_video_image_proxy") }, + PreferenceMigration(7, 8) { + remove("image_cache_size") + remove("max_parallel_downloads") + } ) /** diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 6587f3101f..a9a3407fd2 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -442,7 +442,7 @@ class DownloadService : LifecycleService() { */ private fun mayStartNewDownload(): Boolean { val downloadCount = downloadQueue.valueIterator().asSequence().count { it } - return downloadCount < DownloadHelper.getMaxConcurrentDownloads() + return downloadCount < DownloadHelper.MAX_CONCURRENT_DOWNLOADS } /** @@ -518,9 +518,8 @@ class DownloadService : LifecycleService() { } } - val max = DownloadHelper.getMaxConcurrentDownloads() val current = downloadQueue.valueIterator().asSequence().count { it } - val slotsToFill = max - current + val slotsToFill = DownloadHelper.MAX_CONCURRENT_DOWNLOADS - current if (slotsToFill > 0) { val candidates = incompleteItems.filter { !downloadQueue[it.id] } @@ -742,4 +741,4 @@ class DownloadService : LifecycleService() { var IS_DOWNLOAD_RUNNING = false } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt index a375cc682d..adc4704fec 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt @@ -11,7 +11,6 @@ import com.github.libretube.BuildConfig import com.github.libretube.R import com.github.libretube.constants.PreferenceKeys import com.github.libretube.extensions.toastFromMainThread -import com.github.libretube.helpers.ImageHelper import com.github.libretube.helpers.LocaleHelper import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.ui.base.BasePreferenceFragment @@ -73,12 +72,6 @@ class GeneralSettings : BasePreferenceFragment() { true } - val maxImageCache = findPreference(PreferenceKeys.MAX_IMAGE_CACHE) - maxImageCache?.setOnPreferenceChangeListener { _, _ -> - ImageHelper.initializeImageLoader(requireContext()) - true - } - val resetSettings = findPreference(PreferenceKeys.RESET_SETTINGS) resetSettings?.setOnPreferenceClickListener { showResetDialog() diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 0f0803c459..dc4d2bc6e8 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -225,26 +225,6 @@ unlimited - - 16MB - 32MB - 64MB - 128MB - 256MB - 512MB - @string/limit_to_runtime - - - - 16 - 32 - 64 - 128 - 256 - 512 - - - @string/creation_date @string/creation_date_reversed diff --git a/app/src/main/res/xml/general_settings.xml b/app/src/main/res/xml/general_settings.xml index b7b620fc8e..cfc0ba5e31 100644 --- a/app/src/main/res/xml/general_settings.xml +++ b/app/src/main/res/xml/general_settings.xml @@ -48,15 +48,6 @@ - - - -