pull/1171/head
gedoor 3 years ago
parent 268f1b8a75
commit 8e334a3f90
  1. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  3. 53
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  4. 41
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  5. 14
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  6. 7
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt

@ -23,6 +23,10 @@ class FileAssociationActivity :
binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it)
}
viewModel.importRssSourceLive.observe(this) {
binding.rotateLoading.hide()
ImportRssSourceDialog.start(supportFragmentManager, it)
}
viewModel.importReplaceRuleLive.observe(this) {
binding.rotateLoading.hide()
ImportReplaceRuleDialog.start(supportFragmentManager, it)

@ -16,6 +16,7 @@ import java.io.File
class FileAssociationViewModel(application: Application) : BaseViewModel(application) {
val importBookSourceLive = MutableLiveData<String>()
val importRssSourceLive = MutableLiveData<String>()
val importReplaceRuleLive = MutableLiveData<String>()
val successLiveData = MutableLiveData<Intent>()
val errorLiveData = MutableLiveData<String>()
@ -39,15 +40,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
return@execute
}
content.contains("sourceUrl") -> {
successLiveData.postValue(
Intent(
context,
ImportRssSourceActivity::class.java
).apply {
val dataKey = IntentDataHelp.putData(content)
putExtra("dataKey", dataKey)
}
)
importRssSourceLive.postValue(IntentDataHelp.putData(content))
return@execute
}
content.contains("pattern") -> {

@ -9,7 +9,8 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
@ -23,21 +24,29 @@ 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.dp
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/**
* 导入rss源弹出窗口
*/
class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
companion object {
fun start(fragmentManager: FragmentManager, source: String) {
ImportRssSourceDialog().apply {
arguments = Bundle().apply {
putString("source", source)
}
}.show(fragmentManager, "importRssSource")
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by activityViewModels<ImportRssSourceViewModel>()
private val viewModel by viewModels<ImportRssSourceViewModel>()
lateinit var adapter: SourcesAdapter
override fun onStart() {
@ -58,6 +67,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_rss_source)
binding.rotateLoading.show()
initMenu()
adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
@ -88,6 +98,37 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
adapter.notifyDataSetChanged()
upSelectText()
}
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
binding.tvMsg.apply {
text = it
visible()
}
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
adapter.setItems(viewModel.allSources)
} else {
binding.tvMsg.apply {
setText(R.string.wrong_format)
visible()
}
}
})
val source = arguments?.getString("source")
if (source.isNullOrEmpty()) {
dismiss()
return
}
if (source.isAbsUrl()) {
viewModel.importSource(source)
} else {
IntentDataHelp.getData<String>(source)?.let {
viewModel.importSource(it)
return
}
}
}
private fun upSelectText() {

@ -2,7 +2,6 @@ package io.legado.app.ui.association
import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding
@ -29,7 +28,7 @@ class OnLineImportActivity :
}
when (it.path) {
"/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"/rssSource" -> importRssSource(url)
"/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
"/textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"/httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
@ -37,7 +36,7 @@ class OnLineImportActivity :
"/readConfig" -> viewModel.importReadConfig(url, this::finallyDialog)
"/importonline" -> when (it.host) {
"booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"rsssource" -> importRssSource(url)
"rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
else -> {
toastOnUi("url error")
@ -48,42 +47,6 @@ class OnLineImportActivity :
}
}
private fun importRssSource(url: String) {
val viewModel by viewModels<ImportRssSourceViewModel>()
binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
finallyDialog(getString(R.string.error), it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
ImportRssSourceDialog().show(supportFragmentManager, "rssSource")
} else {
finallyDialog(getString(R.string.error), getString(R.string.wrong_format))
}
})
viewModel.importSource(url)
}
private fun importReplaceRule(url: String) {
val viewModel by viewModels<ImportReplaceRuleViewModel>()
binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
finallyDialog(getString(R.string.error), it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
ImportReplaceRuleDialog().show(supportFragmentManager, "replaceRule")
} else {
finallyDialog(getString(R.string.error), getString(R.string.wrong_format))
}
})
viewModel.import(url)
}
private fun finallyDialog(title: String, msg: String) {
alert(title, msg) {
okButton()

@ -23,7 +23,7 @@ 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
import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.association.ImportRssSourceDialog
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.qrcode.QrCodeResult
@ -57,17 +57,13 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private var groupMenu: SubMenu? = null
private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
ImportRssSourceDialog.start(supportFragmentManager, it)
}
private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
startActivity<ImportRssSourceActivity> {
putExtra("dataKey", dataKey)
}
ImportRssSourceDialog.start(supportFragmentManager, dataKey)
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")
@ -284,9 +280,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
ImportRssSourceDialog.start(supportFragmentManager, it)
}
}
cancelButton()

@ -15,9 +15,8 @@ import io.legado.app.databinding.DialogRuleSubEditBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.association.ImportRssSourceDialog
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
@ -77,9 +76,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
ImportBookSourceDialog.start(supportFragmentManager, ruleSub.url)
}
1 -> {
startActivity<ImportRssSourceActivity> {
putExtra("source", ruleSub.url)
}
ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url)
}
2 -> {
ImportReplaceRuleDialog.start(supportFragmentManager, ruleSub.url)

Loading…
Cancel
Save