pull/1171/head
gedoor 3 years ago
parent 1c10b4e7fe
commit 268f1b8a75
  1. 5
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  3. 11
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  4. 19
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  5. 60
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  6. 49
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
  7. 26
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  8. 15
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  9. 6
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  10. 9
      app/src/main/res/layout/dialog_recycler_view.xml

@ -340,11 +340,6 @@
android:name=".ui.association.ImportRssSourceActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent" />
<!-- 导入替换规则 -->
<activity
android:name=".ui.association.ImportReplaceRuleActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent" />
<!-- 打开文件 -->
<activity
android:name=".ui.association.FileAssociationActivity"

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

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

@ -101,14 +101,20 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
}
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
errorDialog(it)
binding.tvMsg.apply {
text = it
visible()
}
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
adapter.setItems(viewModel.allSources)
} else {
errorDialog(getString(R.string.wrong_format))
binding.tvMsg.apply {
setText(R.string.wrong_format)
visible()
}
}
})
val source = arguments?.getString("source")
@ -182,15 +188,6 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
return false
}
private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) {
okButton { }
onDismiss {
}
}.show()
}
inner class SourcesAdapter(context: Context) :
RecyclerAdapter<BookSource, ItemSourceImportBinding>(context) {

@ -1,60 +0,0 @@
package io.legado.app.ui.association
import android.os.Bundle
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.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ImportReplaceRuleActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportReplaceRuleViewModel>(
theme = Theme.Transparent
) {
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel by viewModels<ImportReplaceRuleViewModel>()
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
errorDialog(it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
ImportReplaceRuleDialog().show(supportFragmentManager, "importReplaceRule")
} else {
errorDialog("格式不对")
}
})
initData()
}
private fun initData() {
intent.getStringExtra("dataKey")?.let {
IntentDataHelp.getData<String>(it)?.let { source ->
viewModel.import(source)
return
}
}
intent.getStringExtra("source")?.let {
viewModel.import(it)
return
}
finish()
}
private fun errorDialog(msg: String) {
alert("导入出错", msg) {
okButton { }
onDismiss {
finish()
}
}.show()
}
}

@ -6,7 +6,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
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
@ -15,14 +16,26 @@ 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
class ImportReplaceRuleDialog : BaseDialogFragment() {
companion object {
fun start(fragmentManager: FragmentManager, source: String) {
ImportReplaceRuleDialog().apply {
arguments = Bundle().apply {
putString("source", source)
}
}.show(fragmentManager, "importReplaceRule")
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by activityViewModels<ImportReplaceRuleViewModel>()
private val viewModel by viewModels<ImportReplaceRuleViewModel>()
lateinit var adapter: SourcesAdapter
override fun onStart() {
@ -43,6 +56,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_replace_rule)
binding.rotateLoading.show()
adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter
@ -72,6 +86,37 @@ class ImportReplaceRuleDialog : BaseDialogFragment() {
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.allRules)
} else {
binding.tvMsg.apply {
setText(R.string.wrong_format)
visible()
}
}
})
val source = arguments?.getString("source")
if (source.isNullOrEmpty()) {
dismiss()
return
}
if (source.isAbsUrl()) {
viewModel.import(source)
} else {
IntentDataHelp.getData<String>(source)?.let {
viewModel.import(it)
return
}
}
}
private fun upSelectText() {

@ -28,17 +28,17 @@ class OnLineImportActivity :
return
}
when (it.path) {
"/bookSource" -> importBookSource(url)
"/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"/rssSource" -> importRssSource(url)
"/replaceRule" -> importReplaceRule(url)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
"/textTocRule" -> viewModel.importTextTocRule(url, this::finallyDialog)
"/httpTTS" -> viewModel.importHttpTTS(url, this::finallyDialog)
"/theme" -> viewModel.importTheme(url, this::finallyDialog)
"/readConfig" -> viewModel.importReadConfig(url, this::finallyDialog)
"/importonline" -> when (it.host) {
"booksource" -> importBookSource(url)
"booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url)
"rsssource" -> importRssSource(url)
"replace" -> importReplaceRule(url)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url)
else -> {
toastOnUi("url error")
finish()
@ -48,24 +48,6 @@ class OnLineImportActivity :
}
}
private fun importBookSource(url: String) {
val viewModel by viewModels<ImportBookSourceViewModel>()
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) {
ImportBookSourceDialog().show(supportFragmentManager, "bookSource")
} else {
finallyDialog(getString(R.string.error), getString(R.string.wrong_format))
}
})
viewModel.importSource(url)
}
private fun importRssSource(url: String) {
val viewModel by viewModels<ImportRssSourceViewModel>()
binding.rotateLoading.show()

@ -27,7 +27,7 @@ import io.legado.app.help.coroutine.Coroutine
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.ImportReplaceRuleActivity
import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.qrcode.QrCodeResult
@ -63,9 +63,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private var dataInit = false
private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
ImportReplaceRuleDialog.start(supportFragmentManager, it)
}
private val editActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
@ -76,10 +74,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(FilePicker()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
startActivity<ImportReplaceRuleActivity> {
putExtra("dataKey", dataKey)
}
ImportReplaceRuleDialog.start(supportFragmentManager, IntentDataHelp.putData(it))
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")
@ -276,9 +271,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
ImportReplaceRuleDialog.start(supportFragmentManager, it)
}
}
cancelButton()

@ -14,7 +14,7 @@ import io.legado.app.databinding.ActivityRuleSubBinding
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.ImportReplaceRuleActivity
import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
@ -82,9 +82,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
}
}
2 -> {
startActivity<ImportReplaceRuleActivity> {
putExtra("source", ruleSub.url)
}
ImportReplaceRuleDialog.start(supportFragmentManager, ruleSub.url)
}
}
}

@ -34,6 +34,15 @@
android:layout_gravity="center"
app:loading_width="2dp" />
<TextView
android:id="@+id/tv_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_gravity="center"
android:visibility="gone"
android:textColor="@color/secondaryText" />
</FrameLayout>
<com.google.android.flexbox.FlexboxLayout

Loading…
Cancel
Save