Fix crashes
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user