Improving genre search started from the manga page of a popular manga (#4375)

Co-authored-by: E3FxGaming <E3FxGaming@users.noreply.github.com>
This commit is contained in:
arkon 2021-07-10 16:04:28 -04:00
parent 1ef7722504
commit 62955e7385
3 changed files with 74 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.databinding.SourceControllerBinding import eu.kanade.tachiyomi.databinding.SourceControllerBinding
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.FabController import eu.kanade.tachiyomi.ui.base.controller.FabController
@ -335,6 +336,54 @@ open class BrowseSourceController(bundle: Bundle) :
presenter.restartPager(newQuery) presenter.restartPager(newQuery)
} }
/**
* Attempts to restart the request with a new genre-filtered query.
* If the genre name can't be found the filters,
* the standard searchWithQuery search method is used instead.
*
* @param genreName the name of the genre
*/
fun searchWithGenre(genreName: String) {
presenter.sourceFilters = presenter.source.getFilterList()
var filterList: FilterList? = null
filter@ for (sourceFilter in presenter.sourceFilters) {
if (sourceFilter is Filter.Group<*>) {
for (filter in sourceFilter.state) {
if (filter is Filter<*> && filter.name.equals(genreName, true)) {
when (filter) {
is Filter.TriState -> filter.state = 1
is Filter.CheckBox -> filter.state = true
}
filterList = presenter.sourceFilters
break@filter
}
}
} else if (sourceFilter is Filter.Select<*>) {
val index = sourceFilter.values.filterIsInstance<String>()
.indexOfFirst { it.equals(genreName, true) }
if (index != -1) {
sourceFilter.state = index
filterList = presenter.sourceFilters
break
}
}
}
if (filterList != null) {
filterSheet?.setFilters(presenter.filterItems)
showProgressBar()
adapter?.clear()
presenter.restartPager("", filterList)
} else {
searchWithQuery(genreName)
}
}
/** /**
* Called from the presenter when the network request is received. * Called from the presenter when the network request is received.
* *

View File

@ -638,6 +638,29 @@ class MangaController :
} }
} }
/**
* Performs a genre search using the provided genre name.
*
* @param genreName the search genre to the parent controller
*/
fun performGenreSearch(genreName: String) {
if (router.backstackSize < 2) {
return
}
val previousController = router.backstack[router.backstackSize - 2].controller
val presenterSource = presenter.source
if (previousController is BrowseSourceController &&
presenterSource is HttpSource
) {
router.handleBack()
previousController.searchWithGenre(genreName)
} else {
performSearch(genreName)
}
}
private fun shareCover() { private fun shareCover() {
try { try {
val activity = activity!! val activity = activity!!

View File

@ -262,11 +262,11 @@ class MangaInfoHeaderAdapter(
if (!manga.genre.isNullOrBlank()) { if (!manga.genre.isNullOrBlank()) {
binding.mangaGenresTagsCompactChips.setChips( binding.mangaGenresTagsCompactChips.setChips(
manga.getGenres(), manga.getGenres(),
controller::performSearch controller::performGenreSearch
) )
binding.mangaGenresTagsFullChips.setChips( binding.mangaGenresTagsFullChips.setChips(
manga.getGenres(), manga.getGenres(),
controller::performSearch controller::performGenreSearch
) )
} else { } else {
binding.mangaGenresTagsCompactChips.isVisible = false binding.mangaGenresTagsCompactChips.isVisible = false