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,35 +20,43 @@ import com.github.libretube.util.DataSaverMode
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
object ImageHelper {
|
object ImageHelper {
|
||||||
lateinit var imageLoader: ImageLoader
|
lateinit var imageLoader: ImageLoader
|
||||||
|
|
||||||
|
private val Context.coilFile get() = cacheDir.resolve("coil")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the image loader
|
* Initialize the image loader
|
||||||
*/
|
*/
|
||||||
fun initializeImageLoader(context: Context) {
|
fun initializeImageLoader(context: Context) {
|
||||||
val maxImageCacheSize = PreferenceHelper.getString(
|
val maxCacheSize = PreferenceHelper.getString(PreferenceKeys.MAX_IMAGE_CACHE, "128")
|
||||||
PreferenceKeys.MAX_IMAGE_CACHE,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
imageLoader = ImageLoader.Builder(context)
|
imageLoader = ImageLoader.Builder(context)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
|
.crossfade(true)
|
||||||
.apply {
|
.apply {
|
||||||
when (maxImageCacheSize) {
|
if (maxCacheSize.isEmpty()) {
|
||||||
"" -> {
|
|
||||||
diskCachePolicy(CachePolicy.DISABLED)
|
diskCachePolicy(CachePolicy.DISABLED)
|
||||||
|
} else {
|
||||||
|
diskCachePolicy(CachePolicy.ENABLED)
|
||||||
|
memoryCachePolicy(CachePolicy.ENABLED)
|
||||||
|
|
||||||
|
val diskCache = generateDiskCache(
|
||||||
|
directory = context.coilFile,
|
||||||
|
size = maxCacheSize.toInt()
|
||||||
|
)
|
||||||
|
diskCache(diskCache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> diskCache(
|
private fun generateDiskCache(directory: File, size: Int): DiskCache {
|
||||||
DiskCache.Builder()
|
return DiskCache.Builder()
|
||||||
.directory(context.cacheDir.resolve("coil"))
|
.directory(directory)
|
||||||
.maxSizeBytes(maxImageCacheSize.toInt() * 1024 * 1024L)
|
.maxSizeBytes(size * 1024 * 1024L)
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +65,7 @@ object ImageHelper {
|
|||||||
*/
|
*/
|
||||||
fun loadImage(url: String?, target: ImageView) {
|
fun loadImage(url: String?, target: ImageView) {
|
||||||
// only load the image if the data saver mode is disabled
|
// 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 urlToLoad = ProxyHelper.unwrapImageUrl(url)
|
||||||
|
|
||||||
val request = ImageRequest.Builder(target.context)
|
val request = ImageRequest.Builder(target.context)
|
||||||
|
@ -167,6 +167,7 @@ class HomeFragment : Fragment() {
|
|||||||
filteredFeed.take(20).toMutableList(),
|
filteredFeed.take(20).toMutableList(),
|
||||||
forceMode = VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
|
forceMode = VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
|
||||||
)
|
)
|
||||||
|
binding.featuredRV.setHasFixedSize(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadBookmarks() {
|
private suspend fun loadBookmarks() {
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
android:id="@+id/featuredRV"
|
android:id="@+id/featuredRV"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="10dp"
|
android:paddingHorizontal="10dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
android:nestedScrollingEnabled="false"
|
android:nestedScrollingEnabled="false"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
@ -48,7 +49,8 @@
|
|||||||
android:id="@+id/watchingRV"
|
android:id="@+id/watchingRV"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="10dp"
|
android:paddingHorizontal="10dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
android:nestedScrollingEnabled="false"
|
android:nestedScrollingEnabled="false"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user