From 97e398537d1403ed0e4cc01726f396f0256fb7bf Mon Sep 17 00:00:00 2001 From: ByAyzen <189399597+ByAyzen@users.noreply.github.com> Date: Thu, 27 Aug 2026 01:32:16 +0300 Subject: [PATCH] Fixing search focus and suggestion issues. --- .../lagradost/cloudstream3/MainActivity.kt | 2 +- .../cloudstream3/ui/CustomRecyclerViews.kt | 8 +++--- .../cloudstream3/ui/search/SearchFragment.kt | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 5d39f6554cd..dd30273083a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -764,7 +764,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa // when first loading up the app // R.id.navigation_home -> R.id.home_preview_change_api - R.id.navigation_search -> R.id.main_search + R.id.navigation_search -> R.id.search_autofit_results R.id.navigation_library -> R.id.main_search R.id.navigation_downloads -> R.id.download_appbar else -> null diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/CustomRecyclerViews.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/CustomRecyclerViews.kt index 30235853887..305de7a62f3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/CustomRecyclerViews.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/CustomRecyclerViews.kt @@ -19,7 +19,7 @@ class GrdLayoutManager(val context: Context, spanCount: Int) : ): View? { return try { val fromPos = getPosition(focused) - val nextPos = getNextViewPos(fromPos, focusDirection) + val nextPos = getNextViewPos(fromPos, focusDirection) ?: return null findViewByPosition(nextPos) } catch (e: Exception) { null @@ -50,18 +50,18 @@ class GrdLayoutManager(val context: Context, spanCount: Int) : override fun onInterceptFocusSearch(focused: View, direction: Int): View? { return try { val fromPos = getPosition(focused) - val nextPos = getNextViewPos(fromPos, direction) + val nextPos = getNextViewPos(fromPos, direction) ?: return null findViewByPosition(nextPos) } catch (e: Exception) { null } } - private fun getNextViewPos(fromPos: Int, direction: Int): Int { + private fun getNextViewPos(fromPos: Int, direction: Int): Int? { val offset = calcOffsetToNextView(direction) if (hitBorder(fromPos, offset)) { - return fromPos + return null } return fromPos + offset 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 5f5b064b543..96fc576005f 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 @@ -149,6 +149,7 @@ class SearchFragment : BaseFragment( override fun onResume() { super.onResume() + searchViewModel.clearSuggestions() afterPluginsLoadedEvent += ::reloadRepos } @@ -167,6 +168,7 @@ class SearchFragment : BaseFragment( **/ fun search(query: String?) { if (query == null) return + searchViewModel.clearSuggestions() // don't resume state from prev search (binding?.searchMasterRecycler?.adapter as? BaseAdapter<*, *>)?.clearState() context?.let { ctx -> @@ -202,18 +204,24 @@ class SearchFragment : BaseFragment( private fun reloadRepos(success: Boolean = false) = main { searchViewModel.reloadRepos() context?.filterProviderByPreferredMedia()?.let { validAPIs -> + val isAdvanced = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } + ?.getBoolean("advanced_search", true) ?: true + val nextFocusDownId = if (isAdvanced) R.id.search_master_recycler else R.id.search_autofit_results bindChips( binding?.tvtypesChipsScroll?.tvtypesChips, selectedSearchTypes, - validAPIs.flatMap { api -> api.supportedTypes }.distinct() - ) { list -> - if (selectedSearchTypes.toSet() != list.toSet()) { - DataStoreHelper.searchPreferenceTags = list - selectedSearchTypes.clear() - selectedSearchTypes.addAll(list) - search(binding?.mainSearch?.query?.toString()) - } - } + validAPIs.flatMap { api -> api.supportedTypes }.distinct(), + { list -> + if (selectedSearchTypes.toSet() != list.toSet()) { + DataStoreHelper.searchPreferenceTags = list + selectedSearchTypes.clear() + selectedSearchTypes.addAll(list) + search(binding?.mainSearch?.query?.toString()) + } + }, + nextFocusDown = nextFocusDownId, + nextFocusUp = null + ) } }