mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-03 23:58:55 +01:00 
			
		
		
		
	Decrease debounce time for library search
Async library search code cleanup Rename LoadingTools -> LoaderManager
This commit is contained in:
		@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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 -->
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								app/src/main/java/exh/util/CoroutineUtil.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/src/main/java/exh/util/CoroutineUtil.kt
									
									
									
									
									
										Normal 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()
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user