tachiyomi-extensions icon indicating copy to clipboard operation
tachiyomi-extensions copied to clipboard

999hentai tag search

Open Opi-Txm opened this issue 1 year ago • 2 comments

Closes: #18885

I changed the tag search to a Filter.Select type for the following reasons:

  1. When a you search a genre by clicking on a tag, the function below eventually gets called in the main tachiyomi repository. The type Filter.Text won't get catched in this method and ends up just searching for the tag in the search bar. Also after skimming all sources, the only other source that has a genre tag filter of type Filter.Text is nhentai, which has a built-in tag searching algorithm in their website and therefore is appropriate.
//When a Tag gets clicked, performGenreSearch() in app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt 
//gets called, which calls searchGenre() in BrowseSourceScreen.kt in the same folder, which calls the method below

app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt 

fun searchGenre(genreName: String) {
        if (source !is CatalogueSource) return

        val defaultFilters = source.getFilterList()
        var genreExists = false

        filter@ for (sourceFilter in defaultFilters) {
            if (sourceFilter is SourceModelFilter.Group<*>) {
                for (filter in sourceFilter.state) {
                    if (filter is SourceModelFilter<*> && filter.name.equals(genreName, true)) {
                        when (filter) {
                            is SourceModelFilter.TriState -> filter.state = 1
                            is SourceModelFilter.CheckBox -> filter.state = true
                            else -> {}
                        }
                        genreExists = true
                        break@filter
                    }
                }
            } else if (sourceFilter is SourceModelFilter.Select<*>) {
                val index = sourceFilter.values.filterIsInstance<String>()
                    .indexOfFirst { it.equals(genreName, true) }

                if (index != -1) {
                    sourceFilter.state = index
                    genreExists = true
                    break
                }
            }
        }

        mutableState.update {
            val listing = if (genreExists) {
                Listing.Search(query = null, filters = defaultFilters)
            } else {
                Listing.Search(query = genreName, filters = defaultFilters)
            }
            it.copy(
                filters = defaultFilters,
                listing = listing,
                toolbarQuery = listing.query,
            )
        }
    }


  1. The structure of the website 999hentai allows multiple exclusion tags, but only one including tag. If you search multiple tags in the tachiyomi application, e.g. "uncensored, animated", the result is a union of single tag searches, which I don't think is an expected behavior for many users. (For this example, you will have a list of mangas containing either the tag "uncensored" or "animated") Therefore, instead of Filter.Group, I implemented it with Filter.Select.

Also fixed a bug that ignores the filter of min/max pages when only the max amount of pages is set.

Checklist:

  • [x] Updated extVersionCode value in build.gradle for individual extensions
  • [x] Updated overrideVersionCode or baseVersionCode as needed for all multisrc extensions
  • [x] Referenced all related issues in the PR body (e.g. "Closes #xyz")
  • [x] Added the isNsfw = true flag in build.gradle when appropriate
  • [x] Have not changed source names
  • [x] Have explicitly kept the id if a source's name or language were changed
  • [x] Have tested the modifications by compiling and running the extension through Android Studio

Opi-Txm avatar Nov 26 '23 20:11 Opi-Txm