pull/1327/head
gedoor 3 years ago
parent 919bce4430
commit 4d4cb31fe0
  1. 37
      app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  5. 7
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  6. 18
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt

@ -20,59 +20,36 @@ package io.legado.app.lib.dialogs
import android.content.Context
import android.content.DialogInterface
import androidx.fragment.app.Fragment
inline fun Fragment.selector(
title: CharSequence? = null,
items: List<CharSequence>,
noinline onClick: (DialogInterface, Int) -> Unit
) = activity?.selector(title, items, onClick)
fun Context.selector(
title: CharSequence? = null,
items: List<CharSequence>,
onClick: (DialogInterface, Int) -> Unit
) {
with(AndroidAlertBuilder(this)) {
if (title != null) {
this.setTitle(title)
}
items(items, onClick)
show()
}
}
fun Context.selector(
titleSource: Int? = null,
title: CharSequence,
items: List<CharSequence>,
onClick: (DialogInterface, Int) -> Unit
) {
with(AndroidAlertBuilder(this)) {
if (titleSource != null) {
this.setTitle(titleSource)
}
this.setTitle(title)
items(items, onClick)
show()
}
}
inline fun <D : DialogInterface> Fragment.selector(
noinline factory: AlertBuilderFactory<D>,
title: CharSequence? = null,
items: List<CharSequence>,
noinline onClick: (DialogInterface, CharSequence, Int) -> Unit
) = requireActivity().selector(factory, title, items, onClick)
fun <D : DialogInterface> Context.selector(
factory: AlertBuilderFactory<D>,
title: CharSequence? = null,
fun Context.selector(
titleSource: Int,
items: List<CharSequence>,
onClick: (DialogInterface, CharSequence, Int) -> Unit
onClick: (DialogInterface, Int) -> Unit
) {
with(factory(this)) {
if (title != null) {
this.setTitle(title)
}
with(AndroidAlertBuilder(this)) {
this.setTitle(titleSource)
items(items, onClick)
show()
}

@ -155,7 +155,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
binding.tvRestore.setOnClickListener {
val defaultConfigs = DefaultData.readConfigs
val layoutNames = defaultConfigs.map { it.name }
selector("选择预设布局", layoutNames) { _, i ->
context?.selector("选择预设布局", layoutNames) { _, i ->
if (i >= 0) {
ReadBookConfig.durConfig = defaultConfigs[i]
initData()

@ -122,7 +122,7 @@ class ClickActionConfigDialog : BaseDialogFragment() {
}
private fun selectAction(success: (action: Int) -> Unit) {
selector(
context?.selector(
getString(R.string.select_action),
actions.values.toList()
) { _, index ->

@ -113,7 +113,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
childFragmentManager.showDialog<FontSelectDialog>()
}
tvTextIndent.setOnClickListener {
selector(
context?.selector(
title = getString(R.string.text_indent),
items = resources.getStringArray(R.array.indent).toList()
) { _, index ->

@ -146,7 +146,12 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun selectSysTts() {
val ttsItems = viewModel.tts.engines.map {
SelectItem(it.label, 0)
SelectItem(it.label, it.name)
}
alert(R.string.system_tts) {
items(ttsItems) { _, item, index ->
}
}
removePref(PreferKey.speakEngine)
dismissAllowingStateLoss()

@ -93,7 +93,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
llHeaderShow.setOnClickListener {
val headerModes = ReadTipConfig.getHeaderModes(requireContext())
selector(items = headerModes.values.toList()) { _, i ->
context?.selector(items = headerModes.values.toList()) { _, i ->
ReadTipConfig.headerMode = headerModes.keys.toList()[i]
tvHeaderShow.text = headerModes[ReadTipConfig.headerMode]
postEvent(EventBus.UP_CONFIG, true)
@ -101,14 +101,14 @@ class TipConfigDialog : BaseDialogFragment() {
}
llFooterShow.setOnClickListener {
val footerModes = ReadTipConfig.getFooterModes(requireContext())
selector(items = footerModes.values.toList()) { _, i ->
context?.selector(items = footerModes.values.toList()) { _, i ->
ReadTipConfig.footerMode = footerModes.keys.toList()[i]
tvFooterShow.text = footerModes[ReadTipConfig.footerMode]
postEvent(EventBus.UP_CONFIG, true)
}
}
llHeaderLeft.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipHeaderLeft = i
tvHeaderLeft.text = ReadTipConfig.tips[i]
@ -116,7 +116,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llHeaderMiddle.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipHeaderMiddle = i
tvHeaderMiddle.text = ReadTipConfig.tips[i]
@ -124,7 +124,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llHeaderRight.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipHeaderRight = i
tvHeaderRight.text = ReadTipConfig.tips[i]
@ -132,7 +132,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llFooterLeft.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipFooterLeft = i
tvFooterLeft.text = ReadTipConfig.tips[i]
@ -140,7 +140,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llFooterMiddle.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipFooterMiddle = i
tvFooterMiddle.text = ReadTipConfig.tips[i]
@ -148,7 +148,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llFooterRight.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i ->
context?.selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i)
ReadTipConfig.tipFooterRight = i
tvFooterRight.text = ReadTipConfig.tips[i]
@ -156,7 +156,7 @@ class TipConfigDialog : BaseDialogFragment() {
}
}
llTipColor.setOnClickListener {
selector(items = arrayListOf("跟随正文", "自定义")) { _, i ->
context?.selector(items = arrayListOf("跟随正文", "自定义")) { _, i ->
when (i) {
0 -> {
ReadTipConfig.tipColor = 0

Loading…
Cancel
Save