Merge pull request #6335 from Bnyro/master

fix: crash when search view destroyed before suggestions fetched
This commit is contained in:
Bnyro 2024-08-10 13:23:24 +02:00 committed by GitHub
commit 459b5df474
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,14 +92,18 @@ class SearchSuggestionsFragment : Fragment() {
}
private fun showHistory() {
val searchView = runCatching {
(activity as MainActivity).searchView
}.getOrNull()
lifecycleScope.launch {
val historyList = withContext(Dispatchers.IO) {
Database.searchHistoryDao().getAll().map { it.query }
}
if (historyList.isNotEmpty()) {
if (historyList.isNotEmpty() && searchView != null) {
binding.suggestionsRecycler.adapter = SearchHistoryAdapter(
historyList,
(activity as MainActivity).searchView
searchView
)
} else {
binding.suggestionsRecycler.isGone = true