From ad1c6996f5e8d061bcbcb17af4d0a99118e22051 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Sat, 5 Aug 2023 23:18:08 +0200 Subject: [PATCH] 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 --- .../lineageos/glimpse/thumbnail/ThumbnailLayoutManager.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailLayoutManager.kt b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailLayoutManager.kt index c82e6a6..faaa839 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailLayoutManager.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailLayoutManager.kt @@ -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,