mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 06:09:19 +01:00
Optimize searching in library
This commit is contained in:
parent
6dc79ed9e0
commit
477f5cd856
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.util.lang.chop
|
|||||||
import eu.kanade.tachiyomi.util.lang.removeArticles
|
import eu.kanade.tachiyomi.util.lang.removeArticles
|
||||||
import eu.kanade.tachiyomi.util.system.isLTR
|
import eu.kanade.tachiyomi.util.system.isLTR
|
||||||
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||||
|
import eu.kanade.tachiyomi.util.system.withDefContext
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@ -116,6 +117,17 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
|||||||
isLongPressDragEnabled = libraryListener.canDrag() && s.isNullOrBlank()
|
isLongPressDragEnabled = libraryListener.canDrag() && s.isNullOrBlank()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun performFilterAsync() {
|
||||||
|
val s = getFilter(String::class.java)
|
||||||
|
if (s.isNullOrBlank()) {
|
||||||
|
updateDataSet(mangas)
|
||||||
|
} else {
|
||||||
|
val filteredManga = withDefContext { mangas.filter { it.filter(s) } }
|
||||||
|
updateDataSet(filteredManga)
|
||||||
|
}
|
||||||
|
isLongPressDragEnabled = libraryListener.canDrag() && s.isNullOrBlank()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getFirstLetter(name: String): String {
|
private fun getFirstLetter(name: String): String {
|
||||||
val letter = name.firstOrNull() ?: '#'
|
val letter = name.firstOrNull() ?: '#'
|
||||||
return if (letter.isLetter()) getFirstChar(name) else "#"
|
return if (letter.isLetter()) getFirstChar(name) else "#"
|
||||||
|
@ -1111,7 +1111,9 @@ class LibraryController(
|
|||||||
adapter.removeAllScrollableHeaders()
|
adapter.removeAllScrollableHeaders()
|
||||||
}
|
}
|
||||||
adapter.setFilter(query)
|
adapter.setFilter(query)
|
||||||
adapter.performFilter()
|
viewScope.launchUI {
|
||||||
|
adapter.performFilterAsync()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,10 +146,7 @@ class LibraryItem(
|
|||||||
if (manga.isBlank() && manga.title.isBlank()) {
|
if (manga.isBlank() && manga.title.isBlank()) {
|
||||||
return constraint.isEmpty()
|
return constraint.isEmpty()
|
||||||
}
|
}
|
||||||
val sourceManager by injectLazy<SourceManager>()
|
val sourceName by lazy { sourceManager.getOrStub(manga.source).name }
|
||||||
val sourceName = if (manga.source == 0L) "Local" else {
|
|
||||||
sourceManager.getOrStub(manga.source).name
|
|
||||||
}
|
|
||||||
return manga.title.contains(constraint, true) ||
|
return manga.title.contains(constraint, true) ||
|
||||||
(manga.author?.contains(constraint, true) ?: false) ||
|
(manga.author?.contains(constraint, true) ?: false) ||
|
||||||
(manga.artist?.contains(constraint, true) ?: false) ||
|
(manga.artist?.contains(constraint, true) ?: false) ||
|
||||||
@ -162,16 +159,15 @@ class LibraryItem(
|
|||||||
|
|
||||||
private fun containsGenre(tag: String, genres: List<String>?): Boolean {
|
private fun containsGenre(tag: String, genres: List<String>?): Boolean {
|
||||||
if (tag.trim().isEmpty()) return true
|
if (tag.trim().isEmpty()) return true
|
||||||
|
val seriesType by lazy { manga.seriesType(preferences.context, sourceManager) }
|
||||||
return if (tag.startsWith("-")) {
|
return if (tag.startsWith("-")) {
|
||||||
genres?.find {
|
|
||||||
val realTag = tag.substringAfter("-")
|
val realTag = tag.substringAfter("-")
|
||||||
it.trim().equals(realTag, ignoreCase = true) ||
|
genres?.find {
|
||||||
manga.seriesType(preferences.context, sourceManager).equals(realTag, true)
|
it.trim().equals(realTag, ignoreCase = true) || seriesType.equals(realTag, true)
|
||||||
} == null
|
} == null
|
||||||
} else {
|
} else {
|
||||||
genres?.find {
|
genres?.find {
|
||||||
it.trim().equals(tag, ignoreCase = true) ||
|
it.trim().equals(tag, ignoreCase = true) || seriesType.equals(tag, true)
|
||||||
manga.seriesType(preferences.context, sourceManager).equals(tag, true)
|
|
||||||
} != null
|
} != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,3 +26,5 @@ fun CoroutineScope.launchUI(block: suspend CoroutineScope.() -> Unit): Job =
|
|||||||
suspend fun <T> withUIContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.Main, block)
|
suspend fun <T> withUIContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.Main, block)
|
||||||
|
|
||||||
suspend fun <T> withIOContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.IO, block)
|
suspend fun <T> withIOContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.IO, block)
|
||||||
|
|
||||||
|
suspend fun <T> withDefContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.Default, block)
|
||||||
|
Loading…
Reference in New Issue
Block a user