优化
This commit is contained in:
@@ -7,6 +7,7 @@ import com.jayway.jsonpath.JsonPath
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSource
|
||||
@@ -108,22 +109,26 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
||||
}
|
||||
}
|
||||
}
|
||||
mText.isJsonArray() -> GSON.fromJsonArray<BookSource>(mText).getOrThrow().let { items ->
|
||||
allSources.addAll(items)
|
||||
mText.isJsonArray() -> {
|
||||
GSON.fromJsonArray<BookSource>(mText).getOrThrow().let { items ->
|
||||
allSources.addAll(items)
|
||||
}
|
||||
}
|
||||
mText.isAbsUrl() -> {
|
||||
importSourceUrl(mText)
|
||||
}
|
||||
mText.isUri() -> {
|
||||
val uri = Uri.parse(mText)
|
||||
uri.inputStream(context).getOrThrow().let {
|
||||
allSources.addAll(GSON.fromJsonArray<BookSource>(it).getOrThrow())
|
||||
uri.inputStream(context).getOrThrow().use {
|
||||
GSON.fromJsonArray<BookSource>(it).getOrThrow().let {bookSources ->
|
||||
allSources.addAll(bookSources)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> throw NoStackTraceException(context.getString(R.string.wrong_format))
|
||||
}
|
||||
}.onError {
|
||||
it.printOnDebug()
|
||||
AppLog.put("读取书源出错", it)
|
||||
errorLiveData.postValue(it.localizedMessage ?: "")
|
||||
}.onSuccess {
|
||||
comparisonSource()
|
||||
|
||||
@@ -22,12 +22,12 @@ 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)
|
||||
// .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()
|
||||
|
||||
Reference in New Issue
Block a user