[Komga] rework the load of filter values at startup (#9386)

* rework the load of filter values at startup

* Update CHANGELOG.md
This commit is contained in:
Gauthier 2021-10-07 19:14:08 +08:00 committed by GitHub
parent 0d0f6b5b76
commit 0a0b8bd7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 70 deletions

View File

@ -1,3 +1,11 @@
## 1.2.34
Minimum Komga version required: `0.113.0`
### Fix
* Loading of filter values could fail in some cases
## 1.2.33 ## 1.2.33
Minimum Komga version required: `0.113.0` Minimum Komga version required: `0.113.0`

View File

@ -6,12 +6,12 @@ ext {
extName = 'Komga' extName = 'Komga'
pkgNameSuffix = 'all.komga' pkgNameSuffix = 'all.komga'
extClass = '.KomgaFactory' extClass = '.KomgaFactory'
extVersionCode = 33 extVersionCode = 34
} }
dependencies { dependencies {
implementation 'io.reactivex:rxandroid:1.2.1' compileOnly 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.8' compileOnly 'io.reactivex:rxjava:1.3.8'
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -33,10 +33,8 @@ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import okhttp3.ResponseBody
import rx.Observable import rx.Observable
import rx.Single import rx.Single
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -457,12 +455,8 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
init { init {
if (baseUrl.isNotBlank()) { if (baseUrl.isNotBlank()) {
Single.fromCallable { Single.fromCallable {
client.newCall(GET("$baseUrl/api/v1/libraries", headers)).execute() try {
} client.newCall(GET("$baseUrl/api/v1/libraries", headers)).execute().use { response ->
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
libraries = try { libraries = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
@ -475,19 +469,13 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for libraries filter", e) Log.e(LOG_TAG, "error while decoding JSON for libraries filter", e)
emptyList() emptyList()
} }
},
{ tr ->
Log.e(LOG_TAG, "error while loading libraries for filters", tr)
} }
) } catch (e: Exception) {
Log.e(LOG_TAG, "error while loading libraries for filters", e)
}
Single.fromCallable { try {
client.newCall(GET("$baseUrl/api/v1/collections?unpaged=true", headers)).execute() client.newCall(GET("$baseUrl/api/v1/collections?unpaged=true", headers)).execute().use { response ->
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
collections = try { collections = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
@ -500,19 +488,13 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for collections filter", e) Log.e(LOG_TAG, "error while decoding JSON for collections filter", e)
emptyList() emptyList()
} }
},
{ tr ->
Log.e(LOG_TAG, "error while loading collections for filters", tr)
} }
) } catch (e: Exception) {
Log.e(LOG_TAG, "error while loading collections for filters", e)
}
Single.fromCallable { try {
client.newCall(GET("$baseUrl/api/v1/genres", headers)).execute() client.newCall(GET("$baseUrl/api/v1/genres", headers)).execute().use { response ->
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
genres = try { genres = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
@ -525,19 +507,13 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for genres filter", e) Log.e(LOG_TAG, "error while decoding JSON for genres filter", e)
emptySet() emptySet()
} }
},
{ tr ->
Log.e(LOG_TAG, "error while loading genres for filters", tr)
} }
) } catch (e: Exception) {
Log.e(LOG_TAG, "error while loading genres for filters", e)
}
Single.fromCallable { try {
client.newCall(GET("$baseUrl/api/v1/tags", headers)).execute() client.newCall(GET("$baseUrl/api/v1/tags", headers)).execute().use { response ->
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
tags = try { tags = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
@ -550,19 +526,13 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for tags filter", e) Log.e(LOG_TAG, "error while decoding JSON for tags filter", e)
emptySet() emptySet()
} }
},
{ tr ->
Log.e(LOG_TAG, "error while loading tags for filters", tr)
} }
) } catch (e: Exception) {
Log.e(LOG_TAG, "error while loading tags for filters", e)
}
Single.fromCallable { try {
client.newCall(GET("$baseUrl/api/v1/publishers", headers)).execute() client.newCall(GET("$baseUrl/api/v1/publishers", headers)).execute().use { response ->
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
publishers = try { publishers = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
@ -575,23 +545,17 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for publishers filter", e) Log.e(LOG_TAG, "error while decoding JSON for publishers filter", e)
emptySet() emptySet()
} }
},
{ tr ->
Log.e(LOG_TAG, "error while loading publishers for filters", tr)
} }
) } catch (e: Exception) {
Log.e(LOG_TAG, "error while loading publishers for filters", e)
}
Single.fromCallable { try {
client.newCall(GET("$baseUrl/api/v1/authors", headers)).execute() client.newCall(GET("$baseUrl/api/v1/authors", headers)).execute().use { response ->
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
authors = try { authors = try {
val responseBody = response.body val responseBody = response.body
if (responseBody != null) { if (responseBody != null) {
val list = responseBody.use<ResponseBody, List<AuthorDto>> { json.decodeFromString(it.string()) } val list: List<AuthorDto> = responseBody.use { json.decodeFromString(it.string()) }
list.groupBy { it.role } list.groupBy { it.role }
} else { } else {
Log.e(LOG_TAG, "error while decoding JSON for authors filter: response body is null. Response code: ${response.code}") Log.e(LOG_TAG, "error while decoding JSON for authors filter: response body is null. Response code: ${response.code}")
@ -601,9 +565,17 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
Log.e(LOG_TAG, "error while decoding JSON for authors filter", e) Log.e(LOG_TAG, "error while decoding JSON for authors filter", e)
emptyMap() emptyMap()
} }
}, }
} catch (e: Exception) {
Log.e(LOG_TAG, "error while loading authors for filters", e)
}
}
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(
{},
{ tr -> { tr ->
Log.e(LOG_TAG, "error while loading authors for filters", tr) Log.e(LOG_TAG, "error while doing initial calls", tr)
} }
) )
} }