Local genre tag searching (#2423)

Using the search bar in My Library, you can search tags for manga (ie. "Romance") or exclude (ie. "-Comedy") You can also search multiple by seperating by commas (ie. "Romance, -Comedy")

Clicking the tag in manga info from the library also performs a local serach
This commit is contained in:
Jays2Kings
2020-01-16 18:45:37 -08:00
committed by arkon
parent 8b0458cdf6
commit 01f9b25be2
4 changed files with 42 additions and 3 deletions
@@ -342,6 +342,10 @@ class LibraryController(
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
}
fun search(query:String) {
this.query = query
}
override fun onPrepareOptionsMenu(menu: Menu) {
val navView = navView ?: return
@@ -59,7 +59,22 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
*/
override fun filter(constraint: String): Boolean {
return manga.title.contains(constraint, true) ||
(manga.author?.contains(constraint, true) ?: false)
(manga.author?.contains(constraint, true) ?: false) ||
if (constraint.contains(",")) {
val genres = manga.genre?.split(", ")
constraint.split(",").all { containsGenre(it.trim(), genres) }
}
else containsGenre(constraint, manga.genre?.split(", "))
}
private fun containsGenre(tag: String, genres: List<String>?): Boolean {
return if (tag.startsWith("-"))
genres?.find {
it.trim().toLowerCase() == tag.substringAfter("-").toLowerCase()
} == null
else
genres?.find {
it.trim().toLowerCase() == tag.toLowerCase() } != null
}
override fun equals(other: Any?): Boolean {