pull/1319/head
gedoor 3 years ago
parent e24f62186a
commit 38d278f46c
  1. 2
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
  3. 13
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  4. 12
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt

@ -35,7 +35,7 @@ class FileAssociationActivity :
} }
viewModel.importReplaceRuleLive.observe(this) { viewModel.importReplaceRuleLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
ImportReplaceRuleDialog.start(supportFragmentManager, it, true) supportFragmentManager.showDialog(ImportReplaceRuleDialog(it, true))
} }
viewModel.errorLiveData.observe(this, { viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -9,7 +9,6 @@ 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.FragmentManager
import androidx.fragment.app.viewModels 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
@ -26,26 +25,21 @@ import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
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
class ImportReplaceRuleDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class ImportReplaceRuleDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
companion object { constructor(source: String, finishOnDismiss: Boolean = false) : this() {
arguments = Bundle().apply {
fun start(
fragmentManager: FragmentManager,
source: String,
finishOnDismiss: Boolean = false
) {
fragmentManager.showDialog<ImportReplaceRuleDialog> {
putString("source", source) putString("source", source)
putBoolean("finishOnDismiss", finishOnDismiss) putBoolean("finishOnDismiss", finishOnDismiss)
} }
} }
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by viewModels<ImportReplaceRuleViewModel>() private val viewModel by viewModels<ImportReplaceRuleViewModel>()
private val adapter by lazy { SourcesAdapter(requireContext()) } private val adapter by lazy { SourcesAdapter(requireContext()) }

@ -28,8 +28,9 @@ class OnLineImportActivity :
) )
"rssSource" -> ImportRssSourceDialog "rssSource" -> ImportRssSourceDialog
.start(supportFragmentManager, it.second, true) .start(supportFragmentManager, it.second, true)
"replaceRule" -> ImportReplaceRuleDialog "replaceRule" -> supportFragmentManager.showDialog(
.start(supportFragmentManager, it.second, true) ImportReplaceRuleDialog(it.second, true)
)
} }
} }
viewModel.errorLive.observe(this) { viewModel.errorLive.observe(this) {
@ -46,7 +47,9 @@ class OnLineImportActivity :
ImportBookSourceDialog(url, true) ImportBookSourceDialog(url, true)
) )
"/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "/replaceRule" -> supportFragmentManager.showDialog(
ImportReplaceRuleDialog(url, true)
)
"/textTocRule" -> viewModel.getText(url) { json -> "/textTocRule" -> viewModel.getText(url) { json ->
viewModel.importTextTocRule(json, this::finallyDialog) viewModel.importTextTocRule(json, this::finallyDialog)
} }
@ -64,7 +67,9 @@ class OnLineImportActivity :
ImportBookSourceDialog(url, true) ImportBookSourceDialog(url, true)
) )
"rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "replace" -> supportFragmentManager.showDialog(
ImportReplaceRuleDialog(url, true)
)
else -> { else -> {
toastOnUi("url error") toastOnUi("url error")
finish() finish()

@ -61,7 +61,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private var dataInit = false private var dataInit = false
private val qrCodeResult = registerForActivityResult(QrCodeResult()) { private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
ImportReplaceRuleDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(
ImportReplaceRuleDialog(it)
)
} }
private val editActivity = private val editActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
@ -72,7 +74,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(HandleFileContract()) { uri -> private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
kotlin.runCatching { kotlin.runCatching {
uri?.readText(this)?.let { uri?.readText(this)?.let {
ImportReplaceRuleDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(
ImportReplaceRuleDialog(it)
)
} }
}.onFailure { }.onFailure {
toastOnUi("readTextError:${it.localizedMessage}") toastOnUi("readTextError:${it.localizedMessage}")
@ -279,7 +283,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
ImportReplaceRuleDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(
ImportReplaceRuleDialog(it)
)
} }
} }
cancelButton() cancelButton()

@ -75,9 +75,9 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
1 -> { 1 -> {
ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url) ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url)
} }
2 -> { 2 -> supportFragmentManager.showDialog(
ImportReplaceRuleDialog.start(supportFragmentManager, ruleSub.url) ImportReplaceRuleDialog(ruleSub.url)
} )
} }
} }

Loading…
Cancel
Save