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.utils.viewbindingdelegate.viewBinding
/**
* 网络一键导入
*/
class OnLineImportActivity :
VMBaseActivity<ActivityTranslucenceBinding, OnLineImportViewModel>(theme = Theme.Transparent) {
@ -27,6 +30,8 @@ class OnLineImportActivity :
"rssSource" -> importRssSource(url)
"replaceRule" -> importReplaceRule(url)
"textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
"theme" -> viewModel.importTheme(url, this::finallyDialog)
else -> {
}
}

@ -4,6 +4,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS
import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.http.newCall
import io.legado.app.help.http.okHttpClient
@ -20,7 +21,7 @@ class OnLineImportViewModel(app: App) : BaseViewModel(app) {
}.text("utf-8").let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let {
appDb.txtTocRuleDao.insert(*it.toTypedArray())
}
} ?: throw Exception("格式不对")
}
}.onSuccess {
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.app.DownloadManager
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.Configuration
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.ImportReplaceRuleActivity
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.FilePickerParam
import io.legado.app.utils.*
@ -332,41 +332,39 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
}
private fun shouldOverrideUrlLoading(url: Uri): Boolean {
if (url.scheme == "http" || url.scheme == "https") {
return false
} else if (url.scheme == "yuedu") {
when (url.host) {
"booksource" -> {
val intent = Intent(
this@ReadRssActivity,
ImportBookSourceActivity::class.java
)
intent.data = url
startActivity(intent)
when (url.scheme) {
"http", "https" -> {
return false
}
"legado" -> {
when (url.host) {
"import" -> startActivity<OnLineImportActivity> {
data = url
}
}
"rsssource" -> {
val intent = Intent(
this@ReadRssActivity,
ImportRssSourceActivity::class.java
)
intent.data = url
startActivity(intent)
return true
}
"yuedu" -> {
when (url.host) {
"booksource" -> startActivity<ImportBookSourceActivity> {
data = url
}
"rsssource" -> startActivity<ImportRssSourceActivity> {
data = url
}
"replace" -> startActivity<ImportReplaceRuleActivity> {
data = url
}
}
"replace" -> {
val intent = Intent(
this@ReadRssActivity,
ImportReplaceRuleActivity::class.java
)
intent.data = url
startActivity(intent)
return true
}
else -> {
binding.root.longSnackbar("跳转其它应用", "确认") {
openUrl(url)
}
return true
}
return true
}
binding.root.longSnackbar("跳转其它应用", "确认") {
openUrl(url)
}
return true
}
}

Loading…
Cancel
Save