feat: filter by authors (#6014)
This commit is contained in:
parent
b6a2651d06
commit
6a813c9ab8
@ -1,3 +1,11 @@
|
||||
## 1.2.20
|
||||
|
||||
Minimum Komga version required: `0.75.0`
|
||||
|
||||
### Features
|
||||
|
||||
* filter by authors, grouped by role
|
||||
|
||||
## 1.2.19
|
||||
|
||||
Minimum Komga version required: `0.68.0`
|
||||
|
@ -5,7 +5,7 @@ ext {
|
||||
extName = 'Komga'
|
||||
pkgNameSuffix = 'all.komga'
|
||||
extClass = '.KomgaFactory'
|
||||
extVersionCode = 19
|
||||
extVersionCode = 20
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import android.widget.Toast
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import com.google.gson.Gson
|
||||
import eu.kanade.tachiyomi.extension.BuildConfig
|
||||
import eu.kanade.tachiyomi.extension.all.komga.dto.AuthorDto
|
||||
import eu.kanade.tachiyomi.extension.all.komga.dto.BookDto
|
||||
import eu.kanade.tachiyomi.extension.all.komga.dto.CollectionDto
|
||||
import eu.kanade.tachiyomi.extension.all.komga.dto.LibraryDto
|
||||
@ -128,6 +129,17 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
|
||||
url.addQueryParameter("publisher", publisherToInclude.joinToString(","))
|
||||
}
|
||||
}
|
||||
is AuthorGroup -> {
|
||||
val authorToInclude = mutableListOf<AuthorDto>()
|
||||
filter.state.forEach { content ->
|
||||
if (content.state) {
|
||||
authorToInclude.add(content.author)
|
||||
}
|
||||
}
|
||||
authorToInclude.forEach {
|
||||
url.addQueryParameter("author", "${it.name},${it.role}")
|
||||
}
|
||||
}
|
||||
is Filter.Sort -> {
|
||||
var sortCriteria = when (filter.state?.index) {
|
||||
0 -> "metadata.titleSort"
|
||||
@ -265,6 +277,8 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
|
||||
private class TagGroup(tags: List<TagFilter>) : Filter.Group<TagFilter>("Tags", tags)
|
||||
private class PublisherFilter(publisher: String) : Filter.CheckBox(publisher, false)
|
||||
private class PublisherGroup(publishers: List<PublisherFilter>) : Filter.Group<PublisherFilter>("Publishers", publishers)
|
||||
private class AuthorFilter(val author: AuthorDto) : Filter.CheckBox(author.name, false)
|
||||
private class AuthorGroup(role: String, authors: List<AuthorFilter>) : Filter.Group<AuthorFilter>(role, authors)
|
||||
|
||||
override fun getFilterList(): FilterList =
|
||||
FilterList(
|
||||
@ -275,6 +289,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
|
||||
GenreGroup(genres.map { GenreFilter(it) }),
|
||||
TagGroup(tags.map { TagFilter(it) }),
|
||||
PublisherGroup(publishers.map { PublisherFilter(it) }),
|
||||
*authors.map { (role, authors) -> AuthorGroup(role, authors.map { AuthorFilter(it) }) }.toTypedArray(),
|
||||
SeriesSort()
|
||||
)
|
||||
|
||||
@ -283,6 +298,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
|
||||
private var genres = emptySet<String>()
|
||||
private var tags = emptySet<String>()
|
||||
private var publishers = emptySet<String>()
|
||||
private var authors = emptyMap<String, List<AuthorDto>>() // roles to list of authors
|
||||
|
||||
override val name = "Komga${if (suffix.isNotBlank()) " ($suffix)" else ""}"
|
||||
override val lang = "en"
|
||||
@ -458,6 +474,23 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
Single.fromCallable {
|
||||
client.newCall(GET("$baseUrl/api/v1/authors", headers)).execute()
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{ response ->
|
||||
authors = try {
|
||||
val list: List<AuthorDto> = gson.fromJson(response.body()?.charStream()!!)
|
||||
list.groupBy({ it.role }, { it })
|
||||
} catch (e: Exception) {
|
||||
emptyMap()
|
||||
}
|
||||
},
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Loading…
x
Reference in New Issue
Block a user