Add utility functions

pull/19/head
Koitharu 4 years ago
parent b3905b66eb
commit 423b965905
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -51,7 +51,7 @@ afterEvaluate {
} }
dependencies { dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
implementation 'com.squareup.okhttp3:okhttp:4.9.3' implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'com.squareup.okio:okio:3.1.0' implementation 'com.squareup.okio:okio:3.1.0'
implementation 'org.jsoup:jsoup:1.15.1' implementation 'org.jsoup:jsoup:1.15.1'

@ -76,6 +76,10 @@ class Manga(
val hasRating: Boolean val hasRating: Boolean
get() = rating in 0f..1f get() = rating in 0f..1f
fun getChapters(branch: String?): List<MangaChapter>? {
return chapters?.filter { x -> x.branch == branch }
}
@InternalParsersApi @InternalParsersApi
fun copy( fun copy(
title: String = this.title, title: String = this.title,

@ -94,6 +94,16 @@ fun JSONObject.getDoubleOrDefault(name: String, defaultValue: Double): Double {
} }
} }
fun JSONObject.getFloatOrDefault(name: String, defaultValue: Float): Float {
return when (val rawValue = opt(name)) {
null, JSONObject.NULL -> defaultValue
is Float -> rawValue
is Number -> rawValue.toFloat()
is String -> rawValue.toFloatOrNull() ?: defaultValue
else -> defaultValue
}
}
fun JSONArray.JSONIterator(): Iterator<JSONObject> = JSONIterator(this) fun JSONArray.JSONIterator(): Iterator<JSONObject> = JSONIterator(this)
fun JSONArray.stringIterator(): Iterator<String> = JSONStringIterator(this) fun JSONArray.stringIterator(): Iterator<String> = JSONStringIterator(this)

Loading…
Cancel
Save