|
|
|
@ -5,11 +5,6 @@ import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.data.appDb |
|
|
|
|
import io.legado.app.data.entities.TxtTocRule |
|
|
|
|
import io.legado.app.help.DefaultData |
|
|
|
|
import io.legado.app.help.http.newCallResponseBody |
|
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
|
import io.legado.app.help.http.text |
|
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
import io.legado.app.utils.fromJsonArray |
|
|
|
|
|
|
|
|
|
class TocRegexViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
@ -28,20 +23,4 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun importOnLine(url: String, finally: (msg: String) -> Unit) { |
|
|
|
|
execute { |
|
|
|
|
okHttpClient.newCallResponseBody { |
|
|
|
|
url(url) |
|
|
|
|
}.text("utf-8").let { json -> |
|
|
|
|
GSON.fromJsonArray<TxtTocRule>(json).getOrThrow()?.let { |
|
|
|
|
appDb.txtTocRuleDao.insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onSuccess { |
|
|
|
|
finally("导入成功") |
|
|
|
|
}.onError { |
|
|
|
|
finally("导入失败\n${it.localizedMessage}") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |