|
|
|
@ -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("导入失败") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|