This commit is contained in:
tarsin committed 2022-12-17 14:24:24 +08:00
1 parent b1a9601ae9
commit 82ba22cda2
2 files changed
+12 -1

No files matched your search

@@ -80,11 +80,18 @@ class EhTagDatabase(private val name: String, source: BufferedSource) {
}
/* Construct a cold flow for tag database suggestions */
fun suggestFlow(keyword: String, translate: Boolean): Flow<Pair<String?, String>> = flow {
fun suggestFlow(keyword: String, translate: Boolean, exactly: Boolean = false): Flow<Pair<String?, String>> = flow {
tagList?.forEach {
val tag = it.first
val hint = if (translate) it.second else null
val index = tag.indexOf(':')
if (tag.substring(index + 1).trim() == keyword) {
if (exactly)
emit(Pair(hint, tag))
return@forEach
}
if (exactly)
return@forEach
val keywordMatches: Boolean =
if (index == -1 || index >= tag.length - 1 || keyword.length > 2) {
containsIgnoreSpace(tag, keyword)
@@ -315,6 +315,10 @@ abstract class SearchBarScene : ToolbarScene() {
Settings.getShowTagTranslations() && EhTagDatabase.isTranslatable(
requireContext()
)
suggestFlow(keyword, translate, true).collect {
emit(TagSuggestion(it.first, it.second))
}
suggestFlow(keyword, translate).collect {
emit(TagSuggestion(it.first, it.second))
}