diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 042d5c0cf..15bc96ebc 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -66,7 +66,7 @@ object Versions { const val assertj_core: String = "3.25.3" - const val core_testing: String = "2.2.1" + const val core_testing: String = "2.2.0" const val fragment_ktx: String = "1.2.5" @@ -86,7 +86,7 @@ object Versions { const val core_ktx: String = "1.9.0" - const val libkiwix: String = "2.2.0" + const val libkiwix: String = "2.2.1" const val material: String = "1.8.0" diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchState.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchState.kt index 8320f2553..53ba5cb1c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchState.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchState.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.yield import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem +import org.kiwix.kiwixmobile.core.utils.files.Log data class SearchState( val searchTerm: String, @@ -40,23 +41,31 @@ data class SearchState( searchResultsWithTerm.searchMutex.withLock { searchResultsWithTerm.suggestionSearch?.also { yield() }?.let { val searchResults = mutableListOf() - if (job?.isActive == false) { - // if the previous job is cancel then do not execute the code - return@getVisibleResults searchResults - } - val safeEndIndex = startIndex + 100 - yield() - val searchIterator = - it.getResults(startIndex, safeEndIndex) - while (searchIterator.hasNext()) { + try { if (job?.isActive == false) { - // check if the previous job is cancel while retrieving the data for - // previous searched item then break the execution of code. - break + // if the previous job is cancel then do not execute the code + return@getVisibleResults searchResults } + val safeEndIndex = startIndex + 100 yield() - val entry = searchIterator.next() - searchResults.add(SearchListItem.RecentSearchListItem(entry.title, entry.path)) + val searchIterator = + it.getResults(startIndex, safeEndIndex) + while (searchIterator.hasNext()) { + if (job?.isActive == false) { + // check if the previous job is cancel while retrieving the data for + // previous searched item then break the execution of code. + break + } + yield() + val entry = searchIterator.next() + searchResults.add(SearchListItem.RecentSearchListItem(entry.title, entry.path)) + } + } catch (ignore: Exception) { + Log.e( + "SearchState", + "Could not get the searched result for searchTerm $searchTerm\n" + + "Original exception = $ignore" + ) } /** * Returns null if there are no suggestions left in the iterator.