pull/1867/head
kunfei 3 years ago
parent a50e73ef4e
commit e33a6cbe1b
  1. 5
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

@ -24,6 +24,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.ReadBook
import io.legado.app.ui.association.ImportTxtTocRuleDialog
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
@ -153,9 +154,7 @@ class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
cacheUrls.add(0, it)
aCache.put(importTocRuleKey, cacheUrls.joinToString(","))
}
viewModel.importOnLine(it) { msg ->
toastOnUi(msg)
}
showDialogFragment(ImportTxtTocRuleDialog(it))
}
}
cancelButton()

@ -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}")
}
}
}

@ -183,7 +183,7 @@ abstract class PageDelegate(protected val readView: ReadView) {
}
open fun onDestroy() {
// run on destroy
}
}

Loading…
Cancel
Save