Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Mar 21, 2023
1 parent 40c300e commit 0c2293b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/io/legado/app/data/entities/BookSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,25 @@ data class BookSource(

companion object {

private val gson = GSON.newBuilder()
.registerTypeAdapter(ExploreRule::class.java, ExploreRule.jsonDeserializer)
.registerTypeAdapter(SearchRule::class.java, SearchRule.jsonDeserializer)
.registerTypeAdapter(BookInfoRule::class.java, BookInfoRule.jsonDeserializer)
.registerTypeAdapter(TocRule::class.java, TocRule.jsonDeserializer)
.registerTypeAdapter(ContentRule::class.java, ContentRule.jsonDeserializer)
.registerTypeAdapter(ReviewRule::class.java, ReviewRule.jsonDeserializer)
.create()

fun fromJson(json: String): Result<BookSource> {
return GSON.fromJsonObject(json)
return gson.fromJsonObject(json)
}

fun fromJsonArray(json: String): Result<List<BookSource>> {
return GSON.fromJsonArray(json)
return gson.fromJsonArray(json)
}

fun fromJsonArray(inputStream: InputStream): Result<List<BookSource>> {
return GSON.fromJsonArray(inputStream)
return gson.fromJsonArray(inputStream)
}

}
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/io/legado/app/utils/GsonExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ val GSON: Gson by lazy {
)
.registerTypeAdapter(Int::class.java, IntJsonDeserializer())
.registerTypeAdapter(String::class.java, StringJsonDeserializer())
.registerTypeAdapter(ExploreRule::class.java, ExploreRule.jsonDeserializer)
// .registerTypeAdapter(SearchRule::class.java, SearchRule.jsonDeserializer)
// .registerTypeAdapter(BookInfoRule::class.java, BookInfoRule.jsonDeserializer)
// .registerTypeAdapter(TocRule::class.java, TocRule.jsonDeserializer)
// .registerTypeAdapter(ContentRule::class.java, ContentRule.jsonDeserializer)
// .registerTypeAdapter(ReviewRule::class.java, ReviewRule.jsonDeserializer)
.disableHtmlEscaping()
.setPrettyPrinting()
.create()
Expand Down

0 comments on commit 0c2293b

Please sign in to comment.