apply PR suggestion on safely handling null values, and remove redundant code
This commit is contained in:
parent
2073d6bdda
commit
5f81f24261
1 changed files with 9 additions and 7 deletions
|
@ -138,14 +138,13 @@ object SAnimeDeserializer : DeserializationStrategy<SAnime> {
|
||||||
it.jsonObject["en_title"]?.jsonPrimitive?.content
|
it.jsonObject["en_title"]?.jsonPrimitive?.content
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
val language = jsonObject["videoLanguages"]?.jsonObject?.get("en_title")?.jsonPrimitive?.content
|
val language = jsonObject["videoLanguages"]?.jsonObject?.get("en_title")?.jsonPrimitive?.content
|
||||||
|
val genreText = (categories + language).mapNotNull { it }.joinToString()
|
||||||
val genreText = (categories + language).joinToString(", ")
|
val directors = jsonObject["directorsInfo"]?.jsonArray?.mapNotNull {
|
||||||
val directors = jsonObject["directorsInfo"]?.jsonArray?.map {
|
|
||||||
it.jsonObject["name"]?.jsonPrimitive?.content
|
it.jsonObject["name"]?.jsonPrimitive?.content
|
||||||
}?.joinToString(", ")
|
}?.joinToString()
|
||||||
val actors = jsonObject["actorsInfo"]?.jsonArray?.map {
|
val actors = jsonObject["actorsInfo"]?.jsonArray?.mapNotNull {
|
||||||
it.jsonObject["name"]?.jsonPrimitive?.content
|
it.jsonObject["name"]?.jsonPrimitive?.content
|
||||||
}?.joinToString(", ")
|
}?.joinToString()
|
||||||
val enContent = jsonObject["en_content"]?.jsonPrimitive?.content
|
val enContent = jsonObject["en_content"]?.jsonPrimitive?.content
|
||||||
val year = jsonObject["year"]?.jsonPrimitive?.content ?: "N/A"
|
val year = jsonObject["year"]?.jsonPrimitive?.content ?: "N/A"
|
||||||
val stars = jsonObject["stars"]?.jsonPrimitive?.content?.parseAs<Float>()?.toInt() ?: 0
|
val stars = jsonObject["stars"]?.jsonPrimitive?.content?.parseAs<Float>()?.toInt() ?: 0
|
||||||
|
@ -161,7 +160,10 @@ object SAnimeDeserializer : DeserializationStrategy<SAnime> {
|
||||||
genre = genreText
|
genre = genreText
|
||||||
author = directors
|
author = directors
|
||||||
artist = actors
|
artist = actors
|
||||||
description = "$year | $starsText | $likes\uD83D\uDC4D $dislikes\uD83D\uDC4E\n\n$enContent"
|
description = listOfNotNull(
|
||||||
|
"$year | $starsText | $likes\uD83D\uDC4D $dislikes\uD83D\uDC4E",
|
||||||
|
enContent,
|
||||||
|
).joinToString("\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue