From e2dd408a1c9990b207943870192a121da6cdca2a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Mar 2020 21:45:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/config/TocRegexViewModel.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt index afecf211d..4a63120c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt @@ -4,7 +4,10 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.TxtTocRule +import io.legado.app.help.http.HttpHelper import io.legado.app.model.localBook.AnalyzeTxtFile +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonArray class TocRegexViewModel(application: Application) : BaseViewModel(application) { @@ -30,9 +33,15 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) { fun importOnLine(url: String, finally: (msg: String) -> Unit) { execute { - - }.onFinally { - + HttpHelper.simpleGetAsync(url)?.let { json -> + GSON.fromJsonArray(json)?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + } + } + }.onSuccess { + finally("导入成功") + }.onError { + finally("导入失败") } }