pull/1171/head
gedoor 3 years ago
parent 843c935e3e
commit 1f57bae657
  1. 7
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 19
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  3. 13
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  4. 10
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
  5. 13
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 3
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  8. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -5,6 +5,7 @@ import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -19,6 +20,12 @@ class FileAssociationActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()
viewModel.onLineImportLive.observe(this) {
startActivity<OnLineImportActivity> {
data = it
}
finish()
}
viewModel.importBookSourceLive.observe(this) { viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it, true) ImportBookSourceDialog.start(supportFragmentManager, it, true)

@ -6,15 +6,14 @@ import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.help.IntentDataHelp
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJson
import io.legado.app.utils.isJsonObject
import io.legado.app.utils.readText import io.legado.app.utils.readText
import java.io.File import java.io.File
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { class FileAssociationViewModel(application: Application) : BaseViewModel(application) {
val onLineImportLive = MutableLiveData<Uri>()
val importBookSourceLive = MutableLiveData<String>() val importBookSourceLive = MutableLiveData<String>()
val importRssSourceLive = MutableLiveData<String>() val importRssSourceLive = MutableLiveData<String>()
val importReplaceRuleLive = MutableLiveData<String>() val importReplaceRuleLive = MutableLiveData<String>()
@ -31,20 +30,20 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
} else { } else {
DocumentFile.fromSingleUri(context, uri)?.readText(context) DocumentFile.fromSingleUri(context, uri)?.readText(context)
} }
if (content != null) { content?.let {
if (content.isJsonObject() || content.isJsonArray()) { if (it.isJson()) {
//暂时根据文件内容判断属于什么 //暂时根据文件内容判断属于什么
when { when {
content.contains("bookSourceUrl") -> { content.contains("bookSourceUrl") -> {
importBookSourceLive.postValue(IntentDataHelp.putData(content)) importBookSourceLive.postValue(it)
return@execute return@execute
} }
content.contains("sourceUrl") -> { content.contains("sourceUrl") -> {
importRssSourceLive.postValue(IntentDataHelp.putData(content)) importRssSourceLive.postValue(it)
return@execute return@execute
} }
content.contains("pattern") -> { content.contains("pattern") -> {
importReplaceRuleLive.postValue(IntentDataHelp.putData(content)) importReplaceRuleLive.postValue(it)
return@execute return@execute
} }
} }
@ -57,9 +56,9 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
val intent = Intent(context, ReadBookActivity::class.java) val intent = Intent(context, ReadBookActivity::class.java)
intent.putExtra("bookUrl", book.bookUrl) intent.putExtra("bookUrl", book.bookUrl)
successLiveData.postValue(intent) successLiveData.postValue(intent)
} ?: throw Exception("文件不存在")
} else { } else {
throw Exception("文件不存在") onLineImportLive.postValue(uri)
}
} }
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()

@ -24,11 +24,13 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.WaitDialog 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/** /**
@ -135,12 +137,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
dismiss() dismiss()
return return
} }
when { viewModel.importSource(source)
source.isAbsUrl() || source.isJson() -> viewModel.importSource(source)
else -> IntentDataHelp.getData<String>(source)?.let {
viewModel.importSource(it)
}
}
} }
private fun upSelectText() { private fun upSelectText() {

@ -16,10 +16,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.IntentDataHelp
import io.legado.app.ui.widget.dialog.WaitDialog 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible import io.legado.app.utils.visible
@ -122,12 +119,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() {
dismiss() dismiss()
return return
} }
when { viewModel.import(source)
source.isAbsUrl() || source.isJson() -> viewModel.import(source)
else -> IntentDataHelp.getData<String>(source)?.let {
viewModel.import(it)
}
}
} }
private fun upSelectText() { private fun upSelectText() {

@ -24,11 +24,13 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.WaitDialog 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/** /**
* 导入rss源弹出窗口 * 导入rss源弹出窗口
@ -133,12 +135,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
dismiss() dismiss()
return return
} }
when { viewModel.importSource(source)
source.isAbsUrl() || source.isJson() -> viewModel.importSource(source)
else -> IntentDataHelp.getData<String>(source)?.let {
viewModel.importSource(it)
}
}
} }
private fun upSelectText() { private fun upSelectText() {

@ -21,7 +21,6 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookSourceBinding import io.legado.app.databinding.ActivityBookSourceBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -69,8 +68,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
try { try {
uri.readText(this)?.let { uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) ImportBookSourceDialog.start(supportFragmentManager, it)
ImportBookSourceDialog.start(supportFragmentManager, dataKey)
} }
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}") toastOnUi("readTextError:${e.localizedMessage}")

@ -22,7 +22,6 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceRuleBinding import io.legado.app.databinding.ActivityReplaceRuleBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -74,7 +73,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(FilePicker()) { uri -> private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching { kotlin.runCatching {
uri?.readText(this)?.let { uri?.readText(this)?.let {
ImportReplaceRuleDialog.start(supportFragmentManager, IntentDataHelp.putData(it)) ImportReplaceRuleDialog.start(supportFragmentManager, it)
} }
}.onFailure { }.onFailure {
toastOnUi("readTextError:${it.localizedMessage}") toastOnUi("readTextError:${it.localizedMessage}")

@ -19,7 +19,6 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ActivityRssSourceBinding import io.legado.app.databinding.ActivityRssSourceBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
@ -62,8 +61,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private val importDoc = registerForActivityResult(FilePicker()) { uri -> private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching { kotlin.runCatching {
uri?.readText(this)?.let { uri?.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) ImportRssSourceDialog.start(supportFragmentManager, it)
ImportRssSourceDialog.start(supportFragmentManager, dataKey)
} }
}.onFailure { }.onFailure {
toastOnUi("readTextError:${it.localizedMessage}") toastOnUi("readTextError:${it.localizedMessage}")

Loading…
Cancel
Save