From 2b187b63954e6c2514a42d05d736d50ac93b2737 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 15 May 2020 18:03:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/OldRule.kt | 4 +++- .../app/ui/book/source/manage/BookSourceViewModel.kt | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index f5919eb2c..b69b35526 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.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 } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 5077a71cf..c6dc63c8e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -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() val items: List> = 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 } } \ No newline at end of file