diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt index 08047ea19..c09adc7c0 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt @@ -31,6 +31,16 @@ fun Context.selector( } } +fun Context.selector( + items: List, + onClick: (DialogInterface, T, Int) -> Unit +) { + with(AndroidAlertBuilder(this)) { + items(items, onClick) + show() + } +} + fun Context.selector( title: CharSequence, items: List, @@ -43,6 +53,18 @@ fun Context.selector( } } +fun Context.selector( + title: CharSequence, + items: List, + onClick: (DialogInterface, T, Int) -> Unit +) { + with(AndroidAlertBuilder(this)) { + this.setTitle(title) + items(items, onClick) + show() + } +} + fun Context.selector( titleSource: Int, items: List, @@ -54,3 +76,15 @@ fun Context.selector( show() } } + +fun Context.selector( + titleSource: Int, + items: List, + onClick: (DialogInterface, T, Int) -> Unit +) { + with(AndroidAlertBuilder(this)) { + this.setTitle(titleSource) + items(items, onClick) + show() + } +} diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 3d193aaef..2ed613f23 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -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,13 +149,11 @@ 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() } - removePref(PreferKey.speakEngine) - dismissAllowingStateLoss() } private fun importAlert() { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index ddead89b4..775956ee1 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -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)