Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jul 20, 2024
1 parent 2939012 commit 4d8b859
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
}
}

Expand All @@ -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) {
Expand All @@ -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))
}
}
Expand Down

0 comments on commit 4d8b859

Please sign in to comment.