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() binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it) ImportBookSourceDialog.start(supportFragmentManager, it)
} }
viewModel.importRssSourceLive.observe(this) {
binding.rotateLoading.hide()
ImportRssSourceDialog.start(supportFragmentManager, it)
}
viewModel.importReplaceRuleLive.observe(this) { viewModel.importReplaceRuleLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
ImportReplaceRuleDialog.start(supportFragmentManager, it) ImportReplaceRuleDialog.start(supportFragmentManager, it)

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

@ -9,7 +9,8 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar 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 androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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.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.dp import io.legado.app.utils.*
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源弹出窗口
*/ */
class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { 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 binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by activityViewModels<ImportRssSourceViewModel>() private val viewModel by viewModels<ImportRssSourceViewModel>()
lateinit var adapter: SourcesAdapter lateinit var adapter: SourcesAdapter
override fun onStart() { override fun onStart() {
@ -58,6 +67,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_rss_source) binding.toolBar.setTitle(R.string.import_rss_source)
binding.rotateLoading.show()
initMenu() initMenu()
adapter = SourcesAdapter(requireContext()) adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
@ -88,6 +98,37 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
upSelectText() 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() { private fun upSelectText() {

@ -2,7 +2,6 @@ package io.legado.app.ui.association
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import io.legado.app.R
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
@ -29,7 +28,7 @@ class OnLineImportActivity :
} }
when (it.path) { when (it.path) {
"/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url) "/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"/rssSource" -> importRssSource(url) "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url) "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
"/textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog) "/textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"/httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog) "/httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
@ -37,7 +36,7 @@ class OnLineImportActivity :
"/readConfig" -> viewModel.importReadConfig(url, this::finallyDialog) "/readConfig" -> viewModel.importReadConfig(url, this::finallyDialog)
"/importonline" -> when (it.host) { "/importonline" -> when (it.host) {
"booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url) "booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"rsssource" -> importRssSource(url) "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url) "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
else -> { else -> {
toastOnUi("url error") 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) { private fun finallyDialog(title: String, msg: String) {
alert(title, msg) { alert(title, msg) {
okButton() okButton()

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

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

Loading…
Cancel
Save