Skip to content

Commit 68c599c

Browse files
committed
fix(ui): make sure sound package configs are showed in the picker
1 parent 6de7617 commit 68c599c

File tree

1 file changed

+14
-16
lines changed
  • app/src/main/java/com/osfans/trime/ui/main

1 file changed

+14
-16
lines changed

app/src/main/java/com/osfans/trime/ui/main/Pickers.kt

+14-16
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,21 @@ suspend fun Context.schemaPicker(
9494
}.create()
9595
}
9696

97-
suspend fun Context.soundPicker(
97+
fun Context.soundPicker(
9898
@StyleRes themeResId: Int = 0
9999
): AlertDialog {
100-
return CoroutineChoiceDialog(this, themeResId).apply {
101-
title = getString(R.string.keyboard__key_sound_package_title)
102-
initDispatcher = Dispatchers.IO
103-
onInit {
104-
items = SoundManager.getAllSounds()
105-
.map { it.substringBeforeLast('.') }
106-
.toTypedArray()
107-
val current = SoundManager.getActiveSound()
108-
.substringBeforeLast('.')
109-
checkedItem = items.indexOf(current)
100+
val all = SoundManager.getAllSounds().map { it.substringBeforeLast('.') }
101+
val current = SoundManager.getActiveSound().substringBeforeLast('.')
102+
var checked = all.indexOf(current)
103+
return AlertDialog.Builder(this, themeResId)
104+
.setTitle(R.string.keyboard__key_sound_package_title)
105+
.setSingleChoiceItems(
106+
all.toTypedArray(),
107+
checked
108+
) { _, id -> checked = id }
109+
.setPositiveButton(android.R.string.ok) { _, _ ->
110+
SoundManager.switchSound("${all[checked]}.sound")
110111
}
111-
postiveDispatcher = Dispatchers.Default
112-
onOKButton {
113-
SoundManager.switchSound("${items[checkedItem]}.sound")
114-
}
115-
}.create()
112+
.setNegativeButton(android.R.string.cancel, null)
113+
.create()
116114
}

0 commit comments

Comments
 (0)