mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix: crash when search view destroyed before suggestions fetched
This commit is contained in:
parent
52fb2a9861
commit
bedcb0c616
@ -92,14 +92,18 @@ class SearchSuggestionsFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showHistory() {
|
private fun showHistory() {
|
||||||
|
val searchView = runCatching {
|
||||||
|
(activity as MainActivity).searchView
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val historyList = withContext(Dispatchers.IO) {
|
val historyList = withContext(Dispatchers.IO) {
|
||||||
Database.searchHistoryDao().getAll().map { it.query }
|
Database.searchHistoryDao().getAll().map { it.query }
|
||||||
}
|
}
|
||||||
if (historyList.isNotEmpty()) {
|
if (historyList.isNotEmpty() && searchView != null) {
|
||||||
binding.suggestionsRecycler.adapter = SearchHistoryAdapter(
|
binding.suggestionsRecycler.adapter = SearchHistoryAdapter(
|
||||||
historyList,
|
historyList,
|
||||||
(activity as MainActivity).searchView
|
searchView
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
binding.suggestionsRecycler.isGone = true
|
binding.suggestionsRecycler.isGone = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user