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. 21
      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.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<OnLineImportActivity> {
data = it
}
finish()
}
viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it, true)

@ -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<Uri>()
val importBookSourceLive = MutableLiveData<String>()
val importRssSourceLive = MutableLiveData<String>()
val importReplaceRuleLive = MutableLiveData<String>()
@ -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()

@ -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<String>(source)?.let {
viewModel.importSource(it)
}
}
viewModel.importSource(source)
}
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.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<String>(source)?.let {
viewModel.import(it)
}
}
viewModel.import(source)
}
private fun upSelectText() {

@ -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<String>(source)?.let {
viewModel.importSource(it)
}
}
viewModel.importSource(source)
}
private fun upSelectText() {

@ -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<ActivityBookSourceBinding, BookSourceV
uri ?: return@registerForActivityResult
try {
uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
ImportBookSourceDialog.start(supportFragmentManager, dataKey)
ImportBookSourceDialog.start(supportFragmentManager, it)
}
} catch (e: Exception) {
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.DialogEditTextBinding
import io.legado.app.help.ContentProcessor
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
@ -74,7 +73,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
ImportReplaceRuleDialog.start(supportFragmentManager, IntentDataHelp.putData(it))
ImportReplaceRuleDialog.start(supportFragmentManager, it)
}
}.onFailure {
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.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<ActivityRssSourceBinding, RssSourceView
private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
ImportRssSourceDialog.start(supportFragmentManager, dataKey)
ImportRssSourceDialog.start(supportFragmentManager, it)
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")

Loading…
Cancel
Save