feat: 优化代码

pull/132/head
kunfei 5 years ago
parent 97293894ae
commit e2dd408a1c
  1. 15
      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<TxtTocRule>(json)?.let {
App.db.txtTocRule().insert(*it.toTypedArray())
}
}
}.onSuccess {
finally("导入成功")
}.onError {
finally("导入失败")
}
}

Loading…
Cancel
Save