feat: 优化

pull/219/head
kunfei 5 years ago
parent 9222c4b73b
commit 2b187b6395
  1. 4
      app/src/main/java/io/legado/app/help/storage/OldRule.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@ -20,7 +20,7 @@ object OldRule {
} catch (e: Exception) {
null
}
runCatching {
try {
if (sourceAny?.ruleToc == null) {
source.apply {
val jsonItem = jsonPath.parse(json.trim())
@ -125,6 +125,8 @@ object OldRule {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleContent))
}
}
} catch (e: Exception) {
e.printStackTrace()
}
return source
}

@ -233,6 +233,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
else -> "格式不对"
}
}.onError {
it.printStackTrace()
finally(it.localizedMessage ?: "")
}.onSuccess {
finally(it)
@ -240,7 +241,11 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}
private fun importSourceUrl(url: String): Int {
HttpHelper.simpleGet(url, "UTF-8")?.let { body ->
HttpHelper.simpleGet(url, "UTF-8").let { body ->
if (body == null) {
toast("访问网站失败")
return 0
}
val bookSources = mutableListOf<BookSource>()
val items: List<Map<String, Any>> = jsonPath.parse(body).read("$")
for (item in items) {
@ -252,6 +257,5 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
App.db.bookSourceDao().insert(*bookSources.toTypedArray())
return bookSources.size
}
return 0
}
}
Loading…
Cancel
Save