diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index b8b6c7f90..016ca3914 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -5,6 +5,7 @@ import androidx.activity.viewModels import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Theme import io.legado.app.databinding.ActivityTranslucenceBinding +import io.legado.app.utils.startActivity import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -19,6 +20,12 @@ class FileAssociationActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { binding.rotateLoading.show() + viewModel.onLineImportLive.observe(this) { + startActivity { + data = it + } + finish() + } viewModel.importBookSourceLive.observe(this) { binding.rotateLoading.hide() ImportBookSourceDialog.start(supportFragmentManager, it, true) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 26e099e52..4d009981b 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -6,15 +6,14 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel -import io.legado.app.help.IntentDataHelp import io.legado.app.model.localBook.LocalBook import io.legado.app.ui.book.read.ReadBookActivity -import io.legado.app.utils.isJsonArray -import io.legado.app.utils.isJsonObject +import io.legado.app.utils.isJson import io.legado.app.utils.readText import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { + val onLineImportLive = MutableLiveData() val importBookSourceLive = MutableLiveData() val importRssSourceLive = MutableLiveData() val importReplaceRuleLive = MutableLiveData() @@ -31,20 +30,20 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica } else { DocumentFile.fromSingleUri(context, uri)?.readText(context) } - if (content != null) { - if (content.isJsonObject() || content.isJsonArray()) { + content?.let { + if (it.isJson()) { //暂时根据文件内容判断属于什么 when { content.contains("bookSourceUrl") -> { - importBookSourceLive.postValue(IntentDataHelp.putData(content)) + importBookSourceLive.postValue(it) return@execute } content.contains("sourceUrl") -> { - importRssSourceLive.postValue(IntentDataHelp.putData(content)) + importRssSourceLive.postValue(it) return@execute } content.contains("pattern") -> { - importReplaceRuleLive.postValue(IntentDataHelp.putData(content)) + importReplaceRuleLive.postValue(it) return@execute } } @@ -57,9 +56,9 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica val intent = Intent(context, ReadBookActivity::class.java) intent.putExtra("bookUrl", book.bookUrl) successLiveData.postValue(intent) - } else { - throw Exception("文件不存在") - } + } ?: throw Exception("文件不存在") + } else { + onLineImportLive.postValue(uri) } }.onError { it.printStackTrace() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index b323bb59f..3d12fe06b 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -24,11 +24,13 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig -import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.* +import io.legado.app.utils.dp +import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.splitNotBlank import io.legado.app.utils.viewbindingdelegate.viewBinding +import io.legado.app.utils.visible /** @@ -135,12 +137,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList dismiss() return } - when { - source.isAbsUrl() || source.isJson() -> viewModel.importSource(source) - else -> IntentDataHelp.getData(source)?.let { - viewModel.importSource(it) - } - } + viewModel.importSource(source) } private fun upSelectText() { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt index fd6458eb0..435517065 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt @@ -16,10 +16,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.ReplaceRule import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding -import io.legado.app.help.IntentDataHelp import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.isJson import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible @@ -122,12 +119,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { dismiss() return } - when { - source.isAbsUrl() || source.isJson() -> viewModel.import(source) - else -> IntentDataHelp.getData(source)?.let { - viewModel.import(it) - } - } + viewModel.import(source) } private fun upSelectText() { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 4ff2f8f5f..821ab2986 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -24,11 +24,13 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig -import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.* +import io.legado.app.utils.dp +import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.splitNotBlank import io.legado.app.utils.viewbindingdelegate.viewBinding +import io.legado.app.utils.visible /** * 导入rss源弹出窗口 @@ -133,12 +135,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe dismiss() return } - when { - source.isAbsUrl() || source.isJson() -> viewModel.importSource(source) - else -> IntentDataHelp.getData(source)?.let { - viewModel.importSource(it) - } - } + viewModel.importSource(source) } private fun upSelectText() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index f59a8ded5..c116fbb9e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -21,7 +21,6 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.databinding.ActivityBookSourceBinding import io.legado.app.databinding.DialogEditTextBinding -import io.legado.app.help.IntentDataHelp import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH @@ -69,8 +68,7 @@ class BookSourceActivity : VMBaseActivity kotlin.runCatching { uri?.readText(this)?.let { - ImportReplaceRuleDialog.start(supportFragmentManager, IntentDataHelp.putData(it)) + ImportReplaceRuleDialog.start(supportFragmentManager, it) } }.onFailure { toastOnUi("readTextError:${it.localizedMessage}") diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 257e0a5ac..c2df2bd56 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -19,7 +19,6 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ActivityRssSourceBinding import io.legado.app.databinding.DialogEditTextBinding -import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor @@ -62,8 +61,7 @@ class RssSourceActivity : VMBaseActivity kotlin.runCatching { uri?.readText(this)?.let { - val dataKey = IntentDataHelp.putData(it) - ImportRssSourceDialog.start(supportFragmentManager, dataKey) + ImportRssSourceDialog.start(supportFragmentManager, it) } }.onFailure { toastOnUi("readTextError:${it.localizedMessage}")