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. 9
      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(
title: 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(
titleSource: Int,
items: List<CharSequence>,
@ -54,3 +76,15 @@ fun Context.selector(
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.lib.dialogs.SelectItem
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.primaryColor
import io.legado.app.model.ReadAloud
@ -148,14 +149,12 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val ttsItems = viewModel.tts.engines.map {
SelectItem(it.label, it.name)
}
alert(R.string.system_tts) {
items(ttsItems) { _, item, index ->
}
}
context?.selector(R.string.system_tts, ttsItems) { _, item, _ ->
item.value
removePref(PreferKey.speakEngine)
dismissAllowingStateLoss()
}
}
private fun importAlert() {
val aCache = ACache.get(requireContext(), cacheDir = false)

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

Loading…
Cancel
Save