pull/1327/head
gedoor 3 years ago
parent 4d4cb31fe0
commit 393a749eb3
  1. 34
      app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt
  2. 11
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  3. 6
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -31,6 +31,16 @@ fun Context.selector(
} }
} }
fun <T> Context.selector(
items: List<T>,
onClick: (DialogInterface, T, Int) -> Unit
) {
with(AndroidAlertBuilder(this)) {
items(items, onClick)
show()
}
}
fun Context.selector( fun Context.selector(
title: CharSequence, title: CharSequence,
items: List<CharSequence>, items: List<CharSequence>,
@ -43,6 +53,18 @@ fun Context.selector(
} }
} }
fun <T> Context.selector(
title: CharSequence,
items: List<T>,
onClick: (DialogInterface, T, Int) -> Unit
) {
with(AndroidAlertBuilder(this)) {
this.setTitle(title)
items(items, onClick)
show()
}
}
fun Context.selector( fun Context.selector(
titleSource: Int, titleSource: Int,
items: List<CharSequence>, items: List<CharSequence>,
@ -54,3 +76,15 @@ fun Context.selector(
show() show()
} }
} }
fun <T> Context.selector(
titleSource: Int,
items: List<T>,
onClick: (DialogInterface, T, Int) -> Unit
) {
with(AndroidAlertBuilder(this)) {
this.setTitle(titleSource)
items(items, onClick)
show()
}
}

@ -24,6 +24,7 @@ import io.legado.app.databinding.ItemHttpTtsBinding
import io.legado.app.help.DirectLinkUpload import io.legado.app.help.DirectLinkUpload
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
@ -148,13 +149,11 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val ttsItems = viewModel.tts.engines.map { val ttsItems = viewModel.tts.engines.map {
SelectItem(it.label, it.name) SelectItem(it.label, it.name)
} }
alert(R.string.system_tts) { context?.selector(R.string.system_tts, ttsItems) { _, item, _ ->
items(ttsItems) { _, item, index -> item.value
removePref(PreferKey.speakEngine)
} dismissAllowingStateLoss()
} }
removePref(PreferKey.speakEngine)
dismissAllowingStateLoss()
} }
private fun importAlert() { private fun importAlert() {

@ -167,7 +167,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
} else { } else {
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.defaultCover) removePref(PreferKey.defaultCover)
CoverImageView.upDefaultCover() CoverImageView.upDefaultCover()
@ -180,7 +180,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) { if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) {
selectImage.launch(requestCodeCoverDark) selectImage.launch(requestCodeCoverDark)
} else { } else {
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.defaultCoverDark) removePref(PreferKey.defaultCoverDark)
CoverImageView.upDefaultCover() CoverImageView.upDefaultCover()
@ -226,7 +226,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
if (!getPrefString(bgKey).isNullOrEmpty()) { if (!getPrefString(bgKey).isNullOrEmpty()) {
actions.add(getString(R.string.delete)) actions.add(getString(R.string.delete))
} }
selector(items = actions) { _, i -> context?.selector(items = actions) { _, i ->
when (i) { when (i) {
0 -> alertImageBlurring(blurringKey) { 0 -> alertImageBlurring(blurringKey) {
upTheme(isNight) upTheme(isNight)

Loading…
Cancel
Save