From 278ba4ea32d7b90997255ee0255ff71334a04a5f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 7 May 2024 12:28:14 +0200 Subject: [PATCH] fix: crash when trying to dearrow feed items --- .../ui/fragments/SubscriptionsFragment.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index e90de2371..dba5c6d15 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -212,17 +212,19 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() { if (viewModel.videoFeed.value != null && !isCurrentTabSubChannels && !binding.subRefresh.isRefreshing && hasMore) { binding.subRefresh.isRefreshing = true - lifecycleScope.launch(Dispatchers.IO) { + lifecycleScope.launch { val toIndex = minOf(feedAdapter.itemCount + 10, sortedFeed.size) - val streamItemsToInsert = sortedFeed + var streamItemsToInsert = sortedFeed .subList(feedAdapter.itemCount, toIndex) - .deArrow() + .toList() - withContext(Dispatchers.Main) { - feedAdapter.insertItems(streamItemsToInsert) - binding.subRefresh.isRefreshing = false + withContext(Dispatchers.IO) { + runCatching { streamItemsToInsert = streamItemsToInsert.deArrow() } } + + feedAdapter.insertItems(streamItemsToInsert) + binding.subRefresh.isRefreshing = false } } }