pull/1155/head
gedoor 3 years ago
parent c09a842fe1
commit bb0eb83e61
  1. 5
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  2. 23
      app/src/main/java/io/legado/app/ui/association/OnLineImportViewModel.kt
  3. 60
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt

@ -9,6 +9,9 @@ import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
* 网络一键导入
*/
class OnLineImportActivity : class OnLineImportActivity :
VMBaseActivity<ActivityTranslucenceBinding, OnLineImportViewModel>(theme = Theme.Transparent) { VMBaseActivity<ActivityTranslucenceBinding, OnLineImportViewModel>(theme = Theme.Transparent) {
@ -27,6 +30,8 @@ class OnLineImportActivity :
"rssSource" -> importRssSource(url) "rssSource" -> importRssSource(url)
"replaceRule" -> importReplaceRule(url) "replaceRule" -> importReplaceRule(url)
"textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog) "textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
"theme" -> viewModel.importTheme(url, this::finallyDialog)
else -> { else -> {
} }
} }

@ -4,6 +4,7 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.http.newCall import io.legado.app.help.http.newCall
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
@ -20,7 +21,7 @@ class OnLineImportViewModel(app: App) : BaseViewModel(app) {
}.text("utf-8").let { json -> }.text("utf-8").let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let { GSON.fromJsonArray<TxtTocRule>(json)?.let {
appDb.txtTocRuleDao.insert(*it.toTypedArray()) appDb.txtTocRuleDao.insert(*it.toTypedArray())
} } ?: throw Exception("格式不对")
} }
}.onSuccess { }.onSuccess {
finally.invoke(context.getString(R.string.success), "导入Txt规则成功") finally.invoke(context.getString(R.string.success), "导入Txt规则成功")
@ -29,5 +30,25 @@ class OnLineImportViewModel(app: App) : BaseViewModel(app) {
} }
} }
fun importHttpTTS(url: String, finally: (title: String, msg: String) -> Unit) {
execute {
okHttpClient.newCall {
url(url)
}.text("utf-8").let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let {
appDb.httpTTSDao.insert(*it.toTypedArray())
return@execute it.size
} ?: throw Exception("格式不对")
}
}.onSuccess {
finally.invoke(context.getString(R.string.success), "导入${it}朗读引擎")
}.onError {
finally.invoke(context.getString(R.string.error), it.localizedMessage ?: "未知错误")
}
}
fun importTheme(url: String, finally: (title: String, msg: String) -> Unit) {
}
} }

@ -2,7 +2,6 @@ package io.legado.app.ui.rss.read
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.DownloadManager import android.app.DownloadManager
import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.net.Uri import android.net.Uri
@ -26,6 +25,7 @@ import io.legado.app.service.help.Download
import io.legado.app.ui.association.ImportBookSourceActivity import io.legado.app.ui.association.ImportBookSourceActivity
import io.legado.app.ui.association.ImportReplaceRuleActivity import io.legado.app.ui.association.ImportReplaceRuleActivity
import io.legado.app.ui.association.ImportRssSourceActivity import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.association.OnLineImportActivity
import io.legado.app.ui.document.FilePicker import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam import io.legado.app.ui.document.FilePickerParam
import io.legado.app.utils.* import io.legado.app.utils.*
@ -332,41 +332,39 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
} }
private fun shouldOverrideUrlLoading(url: Uri): Boolean { private fun shouldOverrideUrlLoading(url: Uri): Boolean {
if (url.scheme == "http" || url.scheme == "https") { when (url.scheme) {
return false "http", "https" -> {
} else if (url.scheme == "yuedu") { return false
when (url.host) { }
"booksource" -> { "legado" -> {
val intent = Intent( when (url.host) {
this@ReadRssActivity, "import" -> startActivity<OnLineImportActivity> {
ImportBookSourceActivity::class.java data = url
) }
intent.data = url
startActivity(intent)
} }
"rsssource" -> { return true
val intent = Intent( }
this@ReadRssActivity, "yuedu" -> {
ImportRssSourceActivity::class.java when (url.host) {
) "booksource" -> startActivity<ImportBookSourceActivity> {
intent.data = url data = url
startActivity(intent) }
"rsssource" -> startActivity<ImportRssSourceActivity> {
data = url
}
"replace" -> startActivity<ImportReplaceRuleActivity> {
data = url
}
} }
"replace" -> { return true
val intent = Intent( }
this@ReadRssActivity, else -> {
ImportReplaceRuleActivity::class.java binding.root.longSnackbar("跳转其它应用", "确认") {
) openUrl(url)
intent.data = url
startActivity(intent)
} }
return true
} }
return true
}
binding.root.longSnackbar("跳转其它应用", "确认") {
openUrl(url)
} }
return true
} }
} }

Loading…
Cancel
Save