优化
This commit is contained in:
@@ -16,6 +16,8 @@ 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.Item1lineTextBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.ui.replace.edit.ReplaceEditActivity
|
||||
@@ -30,6 +32,7 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
|
||||
private val viewModel by activityViewModels<ReadBookViewModel>()
|
||||
private val adapter by lazy { ReplaceAdapter(requireContext()) }
|
||||
private val chineseConvert by lazy { ReplaceRule(0, "繁简转换") }
|
||||
|
||||
private var isEdit = false
|
||||
|
||||
@@ -52,8 +55,11 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
ReadBook.curTextChapter?.effectiveReplaceRules?.let {
|
||||
adapter.setItems(it)
|
||||
val effectiveReplaceRules = ReadBook.curTextChapter?.effectiveReplaceRules ?: emptyList()
|
||||
if (AppConfig.chineseConverterType > 0) {
|
||||
adapter.setItems(effectiveReplaceRules + chineseConvert)
|
||||
} else {
|
||||
adapter.setItems(effectiveReplaceRules)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +69,17 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
viewModel.replaceRuleChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showChineseConvertAlert() {
|
||||
alert(titleResource = R.string.chinese_converter) {
|
||||
items(resources.getStringArray(R.array.chinese_mode).toList()) { _, i ->
|
||||
if (AppConfig.chineseConverterType != i) {
|
||||
AppConfig.chineseConverterType = i
|
||||
isEdit = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class ReplaceAdapter(context: Context) :
|
||||
RecyclerAdapter<ReplaceRule, Item1lineTextBinding>(context) {
|
||||
@@ -74,6 +91,10 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
override fun registerListener(holder: ItemViewHolder, binding: Item1lineTextBinding) {
|
||||
binding.root.setOnClickListener {
|
||||
getItem(holder.layoutPosition)?.let { item ->
|
||||
if (item == chineseConvert) {
|
||||
showChineseConvertAlert()
|
||||
return@let
|
||||
}
|
||||
editActivity.launch(ReplaceEditActivity.startIntent(requireContext(), item.id))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user