Glimpse: ThumbnailLayoutManager: Ignore OOB in onLayoutChildren

When the underlying data is changed when the we're trying to
layout the children on the RecyclerView we can hit that.

TODO: Add proper syncronization and/or switch to ViewModels
Change-Id: I174e6c7c3cca2980ced19a424fc2e12372791d88
This commit is contained in:
Luca Stefani 2023-08-05 23:18:08 +02:00 committed by Sebastiano Barezzi
parent 10a5c8ff04
commit ad1c6996f5
No known key found for this signature in database
GPG Key ID: 763BD3AE91A7A13F
1 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,7 @@ package org.lineageos.glimpse.thumbnail
import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.lineageos.glimpse.ext.px
class ThumbnailLayoutManager(
@ -17,6 +18,13 @@ class ThumbnailLayoutManager(
spanSizeLookup = ThumbnailSpanSizeLookup(adapter, spanCount)
}
override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
try {
super.onLayoutChildren(recycler, state)
} catch (_: IndexOutOfBoundsException) {
}
}
private class ThumbnailSpanSizeLookup(
private val adapter: ThumbnailAdapter,
private val spanCount: Int,