Decrease debounce time for library search

Async library search code cleanup
Rename LoadingTools -> LoaderManager
This commit is contained in:
NerdNumber9 2019-04-12 12:16:52 -04:00
parent 6f2ff6a77e
commit 9b3579acf6
4 changed files with 18 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import exh.isLewdSource
import exh.metadata.sql.tables.SearchMetadataTable
import exh.search.SearchEngine
import exh.util.cancellable
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.filter
@ -77,24 +78,24 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) :
.args(*sqlQuery.second.toTypedArray())
.build())
if(!isActive) return@launch // Fail early when cancelled
ensureActive() // Fail early when cancelled
val convertedResult = LongArray(queryResult.count)
if(convertedResult.isNotEmpty()) {
val mangaIdCol = queryResult.getColumnIndex(SearchMetadataTable.COL_MANGA_ID)
queryResult.moveToFirst()
while (!queryResult.isAfterLast) {
if(!isActive) return@launch // Fail early when cancelled
ensureActive() // Fail early when cancelled
convertedResult[queryResult.position] = queryResult.getLong(mangaIdCol)
queryResult.moveToNext()
}
}
if(!isActive) return@launch // Fail early when cancelled
ensureActive() // Fail early when cancelled
// Flow the mangas to allow cancellation of this filter operation
mangas.asFlow().filter { item ->
mangas.asFlow().cancellable().filter { item ->
if(isLewdSource(item.manga.source)) {
convertedResult.binarySearch(item.manga.id ?: -1) >= 0
} else {

View File

@ -131,7 +131,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
subscriptions += controller.searchRelay
.doOnNext { adapter.searchText = it }
.skip(1)
.debounce(500, TimeUnit.MILLISECONDS)
.debounce(250, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
// EXH -->

View File

@ -0,0 +1,12 @@
package exh.util
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onEach
import kotlin.coroutines.coroutineContext
@FlowPreview
fun <T> Flow<T>.cancellable() = onEach {
coroutineContext.ensureActive()
}