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.Context
import android.content.DialogInterface 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( fun Context.selector(
title: CharSequence? = null,
items: List<CharSequence>, items: List<CharSequence>,
onClick: (DialogInterface, Int) -> Unit onClick: (DialogInterface, Int) -> Unit
) { ) {
with(AndroidAlertBuilder(this)) { with(AndroidAlertBuilder(this)) {
if (title != null) {
this.setTitle(title)
}
items(items, onClick) items(items, onClick)
show() show()
} }
} }
fun Context.selector( fun Context.selector(
titleSource: Int? = null, title: CharSequence,
items: List<CharSequence>, items: List<CharSequence>,
onClick: (DialogInterface, Int) -> Unit onClick: (DialogInterface, Int) -> Unit
) { ) {
with(AndroidAlertBuilder(this)) { with(AndroidAlertBuilder(this)) {
if (titleSource != null) { this.setTitle(title)
this.setTitle(titleSource)
}
items(items, onClick) items(items, onClick)
show() show()
} }
} }
inline fun <D : DialogInterface> Fragment.selector( fun Context.selector(
noinline factory: AlertBuilderFactory<D>, titleSource: Int,
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,
items: List<CharSequence>, items: List<CharSequence>,
onClick: (DialogInterface, CharSequence, Int) -> Unit onClick: (DialogInterface, Int) -> Unit
) { ) {
with(factory(this)) { with(AndroidAlertBuilder(this)) {
if (title != null) { this.setTitle(titleSource)
this.setTitle(title)
}
items(items, onClick) items(items, onClick)
show() show()
} }

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

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

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

@ -146,7 +146,12 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun selectSysTts() { private fun selectSysTts() {
val ttsItems = viewModel.tts.engines.map { 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) removePref(PreferKey.speakEngine)
dismissAllowingStateLoss() dismissAllowingStateLoss()

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

Loading…
Cancel
Save