Added code in arrays.xml to display the buttons.
This code has the buttons display but clicking on them crashes the app. Will debug further. Also replaced setSelectedValues with add and remove SelectedValue for clarity purposes.
This commit is contained in:
parent
334f9385ba
commit
db04f2c29d
6 changed files with 94 additions and 27 deletions
|
|
@ -220,6 +220,8 @@ class Settings {
|
|||
R.string.turbo_limit_hotkey
|
||||
)
|
||||
|
||||
val comboSelection = mutableSetOf<String>()
|
||||
|
||||
const val PREF_FIRST_APP_LAUNCH = "FirstApplicationLaunch"
|
||||
const val PREF_MATERIAL_YOU = "MaterialYouTheme"
|
||||
const val PREF_THEME_MODE = "ThemeMode"
|
||||
|
|
|
|||
|
|
@ -44,21 +44,32 @@ class MultiChoiceSetting(
|
|||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
* Add values to multi choice backing mutable sets.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return the existing setting with the new value applied.
|
||||
* @return the existing setting with the new value added.
|
||||
*/
|
||||
fun setSelectedValues(selection: Int): AbstractMultiIntSetting {
|
||||
fun addSelectedValue(selection: Int): AbstractMultiIntSetting {
|
||||
val intSetting = setting as AbstractMultiIntSetting
|
||||
intSetting.ints.add(selection)
|
||||
return intSetting
|
||||
}
|
||||
|
||||
fun setSelectedValues(selection: Short): AbstractMultiShortSetting {
|
||||
fun addSelectedValue(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts.add(selection)
|
||||
return shortSetting
|
||||
}
|
||||
|
||||
fun removeSelectedValue(selection: Int): AbstractMultiIntSetting {
|
||||
val intSetting = setting as AbstractMultiIntSetting
|
||||
intSetting.ints.remove(selection)
|
||||
return intSetting
|
||||
}
|
||||
|
||||
fun removeSelectedValue(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts.remove(selection)
|
||||
return shortSetting
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,21 +72,32 @@ class StringMultiChoiceSetting(
|
|||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
* Add values to multi choice through the backing mutable sets.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return the existing setting with the new value applied.
|
||||
* @return the existing setting with the new value added.
|
||||
*/
|
||||
fun setSelectedValues(selection: String): AbstractMultiStringSetting {
|
||||
fun addSelectedValue(selection: String): AbstractMultiStringSetting {
|
||||
val stringSetting = setting as AbstractMultiStringSetting
|
||||
stringSetting.strings.add(selection)
|
||||
return stringSetting
|
||||
}
|
||||
|
||||
fun setSelectedValues(selection: Short): AbstractMultiShortSetting {
|
||||
fun addSelectedValue(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts.add(selection)
|
||||
return shortSetting
|
||||
}
|
||||
|
||||
fun removeSelectedValue(selection: String): AbstractMultiStringSetting {
|
||||
val stringSetting = setting as AbstractMultiStringSetting
|
||||
stringSetting.strings.remove(selection)
|
||||
return stringSetting
|
||||
}
|
||||
|
||||
fun removeSelectedValue(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts.remove(selection)
|
||||
return shortSetting
|
||||
}
|
||||
}
|
||||
|
|
@ -716,22 +716,26 @@ class SettingsAdapter(
|
|||
is AbstractMultiIntSetting -> {
|
||||
val value = getValueForMultiChoiceSelection(it, which, is_checked)
|
||||
if (value !in it.selectedValues) {
|
||||
it.removeSelectedValue(value)
|
||||
fragmentView?.onSettingChanged()
|
||||
} else {
|
||||
it.addSelectedValue(value)
|
||||
}
|
||||
it.setSelectedValues(value)
|
||||
}
|
||||
|
||||
is AbstractMultiShortSetting -> {
|
||||
val value = getValueForMultiChoiceSelection(it, which, is_checked).toShort()
|
||||
if (value !in it.selectedValues.map { it.toShort() }) {
|
||||
it.removeSelectedValue(value)
|
||||
fragmentView?.onSettingChanged()
|
||||
} else {
|
||||
it.addSelectedValue(value)
|
||||
}
|
||||
it.setSelectedValues(value)
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException("Unrecognized type used for MultiChoiceSetting!")
|
||||
}
|
||||
fragmentView?.putSetting(setting)
|
||||
fragmentView?.putSetting(setting as AbstractSetting)
|
||||
fragmentView.loadSettingsList()
|
||||
closeDialog()
|
||||
}
|
||||
|
|
@ -743,19 +747,27 @@ class SettingsAdapter(
|
|||
val setting = when (it.setting) {
|
||||
is AbstractMultiStringSetting -> {
|
||||
val value = it.getValueAt(which)
|
||||
if (value !in it.selectedValues ) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValues(value ?: "")
|
||||
if (value !in it.selectedValues ) {
|
||||
it.removeSelectedValue(value ?: "")
|
||||
fragmentView?.onSettingChanged()
|
||||
} else {
|
||||
it.addSelectedValue(value ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
is AbstractMultiShortSetting -> {
|
||||
if (is_checked != it.selectValueIndices[which]) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValues(it.getValueAt(which)?.toShort() ?: 1)
|
||||
if (is_checked != it.selectValueIndices[which]) {
|
||||
it.removeSelectedValue(it.getValueAt(which)?.toShort() ?: 1)
|
||||
fragmentView?.onSettingChanged()
|
||||
} else {
|
||||
it.addSelectedValue(it.getValueAt(which)?.toShort() ?: 1)
|
||||
}
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException("Unrecognized type used for StringMultiChoiceSetting!")
|
||||
}
|
||||
|
||||
fragmentView?.putSetting(setting)
|
||||
fragmentView?.putSetting(setting as AbstractSetting)
|
||||
fragmentView.loadSettingsList()
|
||||
closeDialog()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.citra.citra_emu.display.PortraitScreenLayout
|
|||
import org.citra.citra_emu.display.ScreenLayout
|
||||
import org.citra.citra_emu.features.settings.model.AbstractBooleanSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractIntSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractMultiStringSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractShortSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractStringSetting
|
||||
|
|
@ -38,6 +39,7 @@ import org.citra.citra_emu.features.settings.model.view.SettingsItem
|
|||
import org.citra.citra_emu.features.settings.model.view.SingleChoiceSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.SliderSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.StringInputSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.StringMultiChoiceSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.StringSingleChoiceSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.SubmenuSetting
|
||||
import org.citra.citra_emu.features.settings.model.view.SwitchSetting
|
||||
|
|
@ -809,6 +811,26 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
|||
|
||||
private fun addComboButtonSettings(sl: ArrayList<SettingsItem>) {
|
||||
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.combo_key))
|
||||
val comboSetting = object : AbstractMultiStringSetting {
|
||||
override var strings: MutableSet<String>
|
||||
get() {
|
||||
return Settings.comboSelection
|
||||
}
|
||||
set(values) {
|
||||
for (item in values) {
|
||||
Settings.comboSelection.add(item)
|
||||
}
|
||||
}
|
||||
override val key = null
|
||||
override val section = null
|
||||
override val isRuntimeEditable = false
|
||||
override val valueAsString get() = ""
|
||||
override val defaultValue = ""
|
||||
}
|
||||
|
||||
val buttons = settingsActivity.resources.getStringArray(R.array.n3dsButtons).take(10).toTypedArray()
|
||||
val combo_values = settingsActivity.resources.getStringArray(R.array.combovalues)
|
||||
|
||||
sl.apply {
|
||||
add(
|
||||
SwitchSetting(
|
||||
|
|
@ -819,20 +841,15 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
|||
BooleanSetting.ENABLE_COMBO_KEY.defaultValue,
|
||||
)
|
||||
)
|
||||
add(HeaderSetting(R.string.combo_key_options))
|
||||
// TODO: Implement displaying selectable buttons
|
||||
/*
|
||||
add(
|
||||
StringSingleChoiceSetting(
|
||||
StringMultiChoiceSetting(
|
||||
comboSetting,
|
||||
R.string.emulated_language,
|
||||
R.string.combo_key_options,
|
||||
0,
|
||||
R.array.n3dsButtons,
|
||||
R.array.
|
||||
buttons,
|
||||
combo_values
|
||||
)
|
||||
)
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,20 @@
|
|||
<item>@string/button_turbo</item>
|
||||
</string-array>
|
||||
|
||||
<integer-array name="combovalues">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
<item>9</item>
|
||||
<item>10</item>
|
||||
</integer-array>
|
||||
|
||||
<string-array name="cameraImageSourceNames">
|
||||
<item>@string/blank</item>
|
||||
<item>@string/still_image</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue