From bb0eb83e61e2514c61bd9a42f641b2fca546232a Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 22 Jul 2021 20:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/association/OnLineImportActivity.kt | 5 ++ .../ui/association/OnLineImportViewModel.kt | 23 ++++++- .../legado/app/ui/rss/read/ReadRssActivity.kt | 60 +++++++++---------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt index 7e44b1251..cd2104167 100644 --- a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.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(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 -> { } } diff --git a/app/src/main/java/io/legado/app/ui/association/OnLineImportViewModel.kt b/app/src/main/java/io/legado/app/ui/association/OnLineImportViewModel.kt index c3eab090d..2e07cb09a 100644 --- a/app/src/main/java/io/legado/app/ui/association/OnLineImportViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportViewModel.kt @@ -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(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(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) { + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 73bfd6e24..9884af35e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -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 } 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 { + data = url + } } - "rsssource" -> { - val intent = Intent( - this@ReadRssActivity, - ImportRssSourceActivity::class.java - ) - intent.data = url - startActivity(intent) + return true + } + "yuedu" -> { + when (url.host) { + "booksource" -> startActivity { + data = url + } + "rsssource" -> startActivity { + data = url + } + "replace" -> startActivity { + 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 } }