android: Expose audio output engine setting

master
Charles Lombardo 2023-06-15 22:15:33 +07:00
parent 13a4de647d
commit 9f92104f3e
7 changed files with 58 additions and 20 deletions

@ -8,6 +8,7 @@ enum class StringSetting(
override val section: String, override val section: String,
override val defaultValue: String override val defaultValue: String
) : AbstractStringSetting { ) : AbstractStringSetting {
AUDIO_OUTPUT_ENGINE("output_engine", Settings.SECTION_AUDIO, "auto"),
CUSTOM_RTC("custom_rtc", Settings.SECTION_SYSTEM, "0"); CUSTOM_RTC("custom_rtc", Settings.SECTION_SYSTEM, "0");
override var string: String = defaultValue override var string: String = defaultValue

@ -7,20 +7,20 @@ import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting
import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractStringSetting
class StringSingleChoiceSetting( class StringSingleChoiceSetting(
val key: String? = null,
setting: AbstractSetting?, setting: AbstractSetting?,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
val choicesId: Array<String>, val choices: Array<String>,
private val valuesId: Array<String>?, val values: Array<String>?,
val key: String? = null,
private val defaultValue: String? = null private val defaultValue: String? = null
) : SettingsItem(setting, titleId, descriptionId) { ) : SettingsItem(setting, titleId, descriptionId) {
override val type = TYPE_STRING_SINGLE_CHOICE override val type = TYPE_STRING_SINGLE_CHOICE
fun getValueAt(index: Int): String? { fun getValueAt(index: Int): String? {
if (valuesId == null) return null if (values == null) return null
return if (index >= 0 && index < valuesId.size) { return if (index >= 0 && index < values.size) {
valuesId[index] values[index]
} else { } else {
"" ""
} }
@ -36,8 +36,8 @@ class StringSingleChoiceSetting(
val selectValueIndex: Int val selectValueIndex: Int
get() { get() {
val selectedValue = selectedValue val selectedValue = selectedValue
for (i in valuesId!!.indices) { for (i in values!!.indices) {
if (valuesId[i] == selectedValue) { if (values[i] == selectedValue) {
return i return i
} }
} }

@ -138,7 +138,7 @@ class SettingsAdapter(
clickedItem = item clickedItem = item
dialog = MaterialAlertDialogBuilder(context) dialog = MaterialAlertDialogBuilder(context)
.setTitle(item.nameId) .setTitle(item.nameId)
.setSingleChoiceItems(item.choicesId, item.selectValueIndex, this) .setSingleChoiceItems(item.choices, item.selectValueIndex, this)
.show() .show()
} }

@ -353,7 +353,19 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
private fun addAudioSettings(sl: ArrayList<SettingsItem>) { private fun addAudioSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_audio)) settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_audio))
sl.add( sl.apply {
add(
StringSingleChoiceSetting(
StringSetting.AUDIO_OUTPUT_ENGINE,
R.string.audio_output_engine,
0,
settingsActivity.resources.getStringArray(R.array.outputEngineEntries),
settingsActivity.resources.getStringArray(R.array.outputEngineValues),
StringSetting.AUDIO_OUTPUT_ENGINE.key,
StringSetting.AUDIO_OUTPUT_ENGINE.defaultValue
)
)
add(
SliderSetting( SliderSetting(
IntSetting.AUDIO_VOLUME, IntSetting.AUDIO_VOLUME,
R.string.audio_volume, R.string.audio_volume,
@ -366,6 +378,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
) )
) )
} }
}
private fun addThemeSettings(sl: ArrayList<SettingsItem>) { private fun addThemeSettings(sl: ArrayList<SettingsItem>) {
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_theme)) settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_theme))

@ -26,6 +26,14 @@ class SingleChoiceViewHolder(val binding: ListItemSettingBinding, adapter: Setti
for (i in values.indices) { for (i in values.indices) {
if (values[i] == item.selectedValue) { if (values[i] == item.selectedValue) {
binding.textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i] binding.textSettingDescription.text = resMgr.getStringArray(item.choicesId)[i]
return
}
}
} else if (item is StringSingleChoiceSetting) {
for (i in item.values!!.indices) {
if (item.values[i] == item.selectedValue) {
binding.textSettingDescription.text = item.choices[i]
return
} }
} }
} else { } else {

@ -236,4 +236,15 @@
<item>2</item> <item>2</item>
</integer-array> </integer-array>
<string-array name="outputEngineEntries">
<item>@string/auto</item>
<item>@string/cubeb</item>
<item>@string/string_null</item>
</string-array>
<string-array name="outputEngineValues">
<item>auto</item>
<item>cubeb</item>
<item>null</item>
</string-array>
</resources> </resources>

@ -185,6 +185,7 @@
<string name="fastmem">Fastmem</string> <string name="fastmem">Fastmem</string>
<!-- Audio settings strings --> <!-- Audio settings strings -->
<string name="audio_output_engine">Output engine</string>
<string name="audio_volume">Volume</string> <string name="audio_volume">Volume</string>
<string name="audio_volume_description">Specifies the volume of audio output.</string> <string name="audio_volume_description">Specifies the volume of audio output.</string>
@ -203,6 +204,7 @@
<string name="learn_more">Learn more</string> <string name="learn_more">Learn more</string>
<string name="auto">Auto</string> <string name="auto">Auto</string>
<string name="submit">Submit</string> <string name="submit">Submit</string>
<string name="string_null">Null</string>
<!-- GPU driver installation --> <!-- GPU driver installation -->
<string name="select_gpu_driver">Select GPU driver</string> <string name="select_gpu_driver">Select GPU driver</string>
@ -373,6 +375,9 @@
<string name="theme_mode_light">Light</string> <string name="theme_mode_light">Light</string>
<string name="theme_mode_dark">Dark</string> <string name="theme_mode_dark">Dark</string>
<!-- Audio output engines -->
<string name="cubeb">cubeb</string>
<!-- Black backgrounds theme --> <!-- Black backgrounds theme -->
<string name="use_black_backgrounds">Black backgrounds</string> <string name="use_black_backgrounds">Black backgrounds</string>
<string name="use_black_backgrounds_description">When using the dark theme, apply black backgrounds.</string> <string name="use_black_backgrounds_description">When using the dark theme, apply black backgrounds.</string>