Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,38 @@ class SearchFragment : BaseFragment<FragmentSearchBinding>(
}

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it impossible for users to scroll down while the results are loading. Make sure the user inputs take precedence over anything you are doing automatically.

This is best tested by installing many providers, you will see it becomes impossible to do anything while new results appear.


masterRecycler.post {
val parentVH = masterRecycler.findViewHolderForAdapterPosition(firstNonEmptyIndex)
val parentView = parentVH?.itemView
?: masterRecycler.layoutManager?.findViewByPosition(firstNonEmptyIndex)

val childRecycler = parentView
?.findViewById<androidx.recyclerview.widget.RecyclerView>(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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not focus the item unless necessary. This steals focus from the user on a TV, and it focuses when the user is on a phone (which should never happen).

}
}
}
} catch (_: Throwable) {
}
}
}
}
} catch (e: Exception) {
logError(e)
Expand Down