Fix crashes

This commit is contained in:
Koitharu
2025-03-16 12:43:31 +02:00
parent 6a0ad7f79b
commit d1d7cc9adf
2 changed files with 11 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ class ExpiringLruCache<T>(
private val cache = SieveCache<CacheKey, ExpiringValue<T>>(maxSize)
@Synchronized
operator fun get(key: CacheKey): T? {
val value = cache[key] ?: return null
if (value.isExpired) {
@@ -22,21 +23,28 @@ class ExpiringLruCache<T>(
}
operator fun set(key: CacheKey, value: T) {
cache.put(key, ExpiringValue(value, lifetime, timeUnit))
val value = ExpiringValue(value, lifetime, timeUnit)
synchronized(this) {
cache.put(key, value)
}
}
@Synchronized
fun clear() {
cache.evictAll()
}
@Synchronized
fun trimToSize(size: Int) {
cache.trimToSize(size)
}
@Synchronized
fun remove(key: CacheKey) {
cache.remove(key)
}
@Synchronized
fun removeAll(source: MangaSource) {
cache.removeIf { key, _ -> key.source == source }
}

View File

@@ -4,6 +4,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.AdapterListUpdateCallback
import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
@@ -26,7 +27,7 @@ class FavouritesContainerAdapter(fragment: Fragment) : FragmentStateAdapter(frag
override fun getItemCount(): Int = differ.currentList.size
override fun getItemId(position: Int): Long {
return differ.currentList[position].id
return differ.currentList.getOrNull(position)?.id ?: RecyclerView.NO_ID
}
override fun containsItem(itemId: Long): Boolean {