mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #5443 from RafaelsRamos/imp/feed
fix: Improve home feed layout and fix issue where incorrect cache size was defaulted.
This commit is contained in:
commit
9c2abeeca1
@ -20,44 +20,52 @@ import com.github.libretube.util.DataSaverMode
|
||||
import java.nio.file.Path
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
|
||||
object ImageHelper {
|
||||
lateinit var imageLoader: ImageLoader
|
||||
|
||||
private val Context.coilFile get() = cacheDir.resolve("coil")
|
||||
|
||||
/**
|
||||
* Initialize the image loader
|
||||
*/
|
||||
fun initializeImageLoader(context: Context) {
|
||||
val maxImageCacheSize = PreferenceHelper.getString(
|
||||
PreferenceKeys.MAX_IMAGE_CACHE,
|
||||
""
|
||||
)
|
||||
val maxCacheSize = PreferenceHelper.getString(PreferenceKeys.MAX_IMAGE_CACHE, "128")
|
||||
|
||||
imageLoader = ImageLoader.Builder(context)
|
||||
.callFactory(CronetHelper.callFactory)
|
||||
.crossfade(true)
|
||||
.apply {
|
||||
when (maxImageCacheSize) {
|
||||
"" -> {
|
||||
diskCachePolicy(CachePolicy.DISABLED)
|
||||
}
|
||||
if (maxCacheSize.isEmpty()) {
|
||||
diskCachePolicy(CachePolicy.DISABLED)
|
||||
} else {
|
||||
diskCachePolicy(CachePolicy.ENABLED)
|
||||
memoryCachePolicy(CachePolicy.ENABLED)
|
||||
|
||||
else -> diskCache(
|
||||
DiskCache.Builder()
|
||||
.directory(context.cacheDir.resolve("coil"))
|
||||
.maxSizeBytes(maxImageCacheSize.toInt() * 1024 * 1024L)
|
||||
.build()
|
||||
val diskCache = generateDiskCache(
|
||||
directory = context.coilFile,
|
||||
size = maxCacheSize.toInt()
|
||||
)
|
||||
diskCache(diskCache)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun generateDiskCache(directory: File, size: Int): DiskCache {
|
||||
return DiskCache.Builder()
|
||||
.directory(directory)
|
||||
.maxSizeBytes(size * 1024 * 1024L)
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* load an image from a url into an imageView
|
||||
*/
|
||||
fun loadImage(url: String?, target: ImageView) {
|
||||
// only load the image if the data saver mode is disabled
|
||||
if (DataSaverMode.isEnabled(target.context) || url == null) return
|
||||
if (DataSaverMode.isEnabled(target.context) || url.isNullOrEmpty()) return
|
||||
val urlToLoad = ProxyHelper.unwrapImageUrl(url)
|
||||
|
||||
val request = ImageRequest.Builder(target.context)
|
||||
|
@ -167,6 +167,7 @@ class HomeFragment : Fragment() {
|
||||
filteredFeed.take(20).toMutableList(),
|
||||
forceMode = VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
|
||||
)
|
||||
binding.featuredRV.setHasFixedSize(true)
|
||||
}
|
||||
|
||||
private suspend fun loadBookmarks() {
|
||||
|
@ -35,7 +35,8 @@
|
||||
android:id="@+id/featuredRV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:clipToPadding="false"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
@ -48,7 +49,8 @@
|
||||
android:id="@+id/watchingRV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:clipToPadding="false"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user