From ac5292681d95a7dc5221515b76c97b818d445cb6 Mon Sep 17 00:00:00 2001 From: hsp1020 <125277818+hsp1020@users.noreply.github.com> Date: Sun, 1 Mar 2026 16:35:31 +0900 Subject: [PATCH] Auto-scroll to first non-empty search item --- .../cloudstream3/ui/search/SearchFragment.kt | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index 6bbd569b7f..4c07a692a1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -521,7 +521,38 @@ class SearchFragment : BaseFragment( } submitList(newItems) - //notifyDataSetChanged() + + val firstNonEmptyIndex = newItems.indexOfFirst { it.list.list.isNotEmpty() } + if (firstNonEmptyIndex != -1 && pinnedOrder.isNotEmpty()) { + val masterRecycler = binding.searchMasterRecycler + + masterRecycler.post { + try { + masterRecycler.scrollToPosition(firstNonEmptyIndex) + + masterRecycler.post { + val parentVH = masterRecycler.findViewHolderForAdapterPosition(firstNonEmptyIndex) + val parentView = parentVH?.itemView + ?: masterRecycler.layoutManager?.findViewByPosition(firstNonEmptyIndex) + + val childRecycler = parentView + ?.findViewById(R.id.home_child_recyclerview) + + childRecycler?.post { + val firstChild = + childRecycler.layoutManager?.findViewByPosition(0) + ?: childRecycler.findViewHolderForAdapterPosition(0)?.itemView + + firstChild?.let { view -> + view.isFocusableInTouchMode = true + view.requestFocus() + } + } + } + } catch (_: Throwable) { + } + } + } } } catch (e: Exception) { logError(e)