Add utility functions

This commit is contained in:
2022-06-15 11:42:11 +03:00
parent b3905b66eb
commit 423b965905
3 changed files with 15 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ afterEvaluate {
}
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.okio:okio:3.1.0'
implementation 'org.jsoup:jsoup:1.15.1'

View File

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

View File

@@ -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.stringIterator(): Iterator<String> = JSONStringIterator(this)