mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixed search query for intent
This commit is contained in:
parent
4d98690adb
commit
20da3807a2
2 changed files with 19 additions and 8 deletions
|
@ -286,7 +286,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
*
|
||||
* This is a very bad solution but I was unable to find a better one.
|
||||
**/
|
||||
private var nextSearchQuery: String? = null
|
||||
var nextSearchQuery: String? = null
|
||||
|
||||
/**
|
||||
* Fires every time a new batch of plugins have been loaded, no guarantee about how often this is run and on which thread
|
||||
|
@ -362,9 +362,14 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
loadRepository(url)
|
||||
return true
|
||||
} else if (safeURI(str)?.scheme == appStringSearch) {
|
||||
val query = str.substringAfter("$appStringSearch://")
|
||||
nextSearchQuery =
|
||||
URLDecoder.decode(str.substringAfter("$appStringSearch://"), "UTF-8")
|
||||
|
||||
try {
|
||||
URLDecoder.decode(query, "UTF-8")
|
||||
} catch (t : Throwable) {
|
||||
logError(t)
|
||||
query
|
||||
}
|
||||
// Use both navigation views to support both layouts.
|
||||
// It might be better to use the QuickSearch.
|
||||
activity?.findViewById<BottomNavigationView>(R.id.nav_view)?.selectedItemId =
|
||||
|
@ -1315,7 +1320,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
if (navDestination.matchDestination(R.id.navigation_search) && !nextSearchQuery.isNullOrBlank()) {
|
||||
bundle?.apply {
|
||||
this.putString(SearchFragment.SEARCH_QUERY, nextSearchQuery)
|
||||
nextSearchQuery = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class SearchFragment : Fragment() {
|
|||
|
||||
fun newInstance(query: String): Bundle {
|
||||
return Bundle().apply {
|
||||
putString(SEARCH_QUERY, query)
|
||||
if(query.isNotBlank()) putString(SEARCH_QUERY, query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ class SearchFragment : Fragment() {
|
|||
reloadRepos()
|
||||
|
||||
binding?.apply {
|
||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? =
|
||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
||||
SearchAdapter(
|
||||
ArrayList(),
|
||||
searchAutofitResults,
|
||||
|
@ -530,11 +530,18 @@ class SearchFragment : Fragment() {
|
|||
searchMasterRecycler.layoutManager = GridLayoutManager(context, 1)
|
||||
|
||||
// Automatically search the specified query, this allows the app search to launch from intent
|
||||
arguments?.getString(SEARCH_QUERY)?.let { query ->
|
||||
var sq = arguments?.getString(SEARCH_QUERY) ?: savedInstanceState?.getString(SEARCH_QUERY)
|
||||
if(sq.isNullOrBlank()) {
|
||||
sq = MainActivity.nextSearchQuery
|
||||
}
|
||||
|
||||
sq?.let { query ->
|
||||
if (query.isBlank()) return@let
|
||||
mainSearch.setQuery(query, true)
|
||||
// Clear the query as to not make it request the same query every time the page is opened
|
||||
arguments?.putString(SEARCH_QUERY, null)
|
||||
arguments?.remove(SEARCH_QUERY)
|
||||
savedInstanceState?.remove(SEARCH_QUERY)
|
||||
MainActivity.nextSearchQuery = null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue