Skip to content

Commit

Permalink
filter by collection
Browse files Browse the repository at this point in the history
add CHANGELOG.md

closes gotson/komga#211
  • Loading branch information
gotson committed Jun 26, 2020
1 parent b1c7da6 commit 1fb2dcd
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 6 deletions.
84 changes: 84 additions & 0 deletions src/all/komga/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
## [1.2.12]

Requires Komga `0.41.0`

### Features

* filter by collection

## [1.2.11]

Requires Komga `0.35.2`

### Features

* Set password preferences inputTypes

## [1.2.10]

Requires Komga `0.35.2`

### Features

* unread only filter (closes gotson/komga#180)
* prefix book titles with number (closes gotson/komga#169)

## [1.2.9]

Requires Komga `0.22.0`

### Features

* use SourceFactory to have multiple Komga servers (3 for the moment)

## [1.2.8]

Requires Komga `0.22.0`

### Features

* use book metadata title for chapter display name
* use book metadata sort number for chapter number

## [1.2.7]

### Features

* use series metadata title for display name
* filter on series status

## [1.2.6]

### Features

* Add support for AndroidX preferences

## [1.2.5]

### Features

* add sort options in filter

## [1.2.4]

### Features

* better handling of authentication

## [1.2.3]

### Features

* filters by library

## [1.2.2]

### Features

* request converted image from server if format is not supported

## [1.2.1]

### Features

* first version
2 changes: 1 addition & 1 deletion src/all/komga/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Komga'
pkgNameSuffix = 'all.komga'
extClass = '.KomgaFactory'
extVersionCode = 11
extVersionCode = 12
libVersion = '1.2'
}

Expand Down
39 changes: 34 additions & 5 deletions src/all/komga/src/eu/kanade/tachiyomi/extension/all/komga/Komga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.BookDto
import eu.kanade.tachiyomi.extension.all.komga.dto.CollectionDto
import eu.kanade.tachiyomi.extension.all.komga.dto.LibraryDto
import eu.kanade.tachiyomi.extension.all.komga.dto.PageDto
import eu.kanade.tachiyomi.extension.all.komga.dto.PageWrapperDto
Expand All @@ -23,10 +24,6 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import okhttp3.Credentials
import okhttp3.Headers
import okhttp3.HttpUrl
Expand All @@ -38,6 +35,10 @@ import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
override fun popularMangaRequest(page: Int): Request =
Expand Down Expand Up @@ -73,6 +74,17 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
url.addQueryParameter("library_id", libraryToInclude.joinToString(","))
}
}
is CollectionGroup -> {
val collectionToInclude = mutableListOf<Long>()
filter.state.forEach { content ->
if (content.state) {
collectionToInclude.add(content.id)
}
}
if (collectionToInclude.isNotEmpty()) {
url.addQueryParameter("collection_id", collectionToInclude.joinToString(","))
}
}
is StatusGroup -> {
val statusToInclude = mutableListOf<String>()
filter.state.forEach { content ->
Expand Down Expand Up @@ -187,6 +199,8 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {

private class LibraryFilter(val id: Long, name: String) : Filter.CheckBox(name, false)
private class LibraryGroup(libraries: List<LibraryFilter>) : Filter.Group<LibraryFilter>("Libraries", libraries)
private class CollectionFilter(val id: Long, name: String) : Filter.CheckBox(name, false)
private class CollectionGroup(collections: List<CollectionFilter>) : Filter.Group<CollectionFilter>("Collections", collections)
private class SeriesSort : Filter.Sort("Sort", arrayOf("Alphabetically", "Date added", "Date updated"), Selection(0, true))
private class StatusFilter(name: String) : Filter.CheckBox(name, false)
private class StatusGroup(filters: List<StatusFilter>) : Filter.Group<StatusFilter>("Status", filters)
Expand All @@ -195,12 +209,14 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
override fun getFilterList(): FilterList =
FilterList(
UnreadOnly(),
LibraryGroup(libraries.map { LibraryFilter(it.id, it.name) }.sortedBy { it.name }),
LibraryGroup(libraries.map { LibraryFilter(it.id, it.name) }.sortedBy { it.name.toLowerCase() }),
CollectionGroup(collections.map { CollectionFilter(it.id, it.name) }.sortedBy { it.name.toLowerCase() }),
StatusGroup(listOf("Ongoing", "Ended", "Abandoned", "Hiatus").map { StatusFilter(it) }),
SeriesSort()
)

private var libraries = emptyList<LibraryDto>()
private var collections = emptyList<CollectionDto>()

override val name = "Komga${if (suffix.isNotBlank()) " ($suffix)" else ""}"
override val lang = "en"
Expand Down Expand Up @@ -311,6 +327,19 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
emptyList()
}
}, {})

Single.fromCallable {
client.newCall(GET("$baseUrl/api/v1/collections?unpaged=true", headers)).execute()
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
collections = try {
gson.fromJson<PageWrapperDto<CollectionDto>>(it.body()?.charStream()!!).content
} catch (e: Exception) {
emptyList()
}
}, {})
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ data class AuthorDto(
val name: String,
val role: String
)

data class CollectionDto(
val id: Long,
val name: String,
val ordered: Boolean,
val seriesIds: List<Long>,
val createdDate: String,
val lastModifiedDate: String,
val filtered: Boolean
)

0 comments on commit 1fb2dcd

Please sign in to comment.