mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-02 13:05:00 -06:00
Change List<> in Multi Files to be MutableSet<> to allow adds while prevent potential duplicates. Finished primary multi choice backend impl.
This commit is contained in:
parent
bfcafccb8e
commit
eaf9baee93
@ -5,5 +5,5 @@
|
||||
package org.citra.citra_emu.features.settings.model
|
||||
|
||||
interface AbstractMultiBooleanSetting : AbstractSetting {
|
||||
var booleans: List<Boolean>
|
||||
var booleans: MutableSet<Boolean>
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
package org.citra.citra_emu.features.settings.model
|
||||
|
||||
interface AbstractMultiFloatSetting : AbstractSetting {
|
||||
var floats: List<Float>
|
||||
var floats: MutableSet<Float>
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
package org.citra.citra_emu.features.settings.model
|
||||
|
||||
interface AbstractMultiIntSetting : AbstractSetting {
|
||||
var ints: List<Int>
|
||||
var ints: MutableSet<Int>
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
package org.citra.citra_emu.features.settings.model
|
||||
|
||||
interface AbstractMultiShortSetting : AbstractSetting {
|
||||
var shorts: List<Short>
|
||||
var shorts: MutableSet<Short>
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
package org.citra.citra_emu.features.settings.model
|
||||
|
||||
interface AbstractMultiStringSetting : AbstractSetting {
|
||||
var strings: List<String>
|
||||
var strings: MutableSet<String>
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@ package org.citra.citra_emu.features.settings.model.view
|
||||
import org.citra.citra_emu.features.settings.model.AbstractMultiIntSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractMultiShortSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractIntSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractShortSetting
|
||||
|
||||
class MultiChoiceSetting(
|
||||
setting: AbstractSetting?,
|
||||
@ -28,7 +30,7 @@ class MultiChoiceSetting(
|
||||
|
||||
try {
|
||||
val setting = setting as AbstractMultiIntSetting
|
||||
return setting.ints
|
||||
return setting.ints.toList()
|
||||
} catch (_: ClassCastException) {
|
||||
}
|
||||
|
||||
@ -48,15 +50,15 @@ class MultiChoiceSetting(
|
||||
* @param selection New value of the int.
|
||||
* @return the existing setting with the new value applied.
|
||||
*/
|
||||
fun setSelectedValues(selection: List<Int>): AbstractMultiIntSetting {
|
||||
fun setSelectedValues(selection: Int): AbstractMultiIntSetting {
|
||||
val intSetting = setting as AbstractMultiIntSetting
|
||||
intSetting.ints = selection
|
||||
intSetting.ints.add(selection)
|
||||
return intSetting
|
||||
}
|
||||
|
||||
fun setSelectedValues(selection: List<Short>): AbstractMultiShortSetting {
|
||||
fun setSelectedValues(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts = selection
|
||||
shortSetting.shorts.add(selection)
|
||||
return shortSetting
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ class StringMultiChoiceSetting(
|
||||
|
||||
try {
|
||||
val setting = setting as AbstractMultiStringSetting
|
||||
return setting.strings
|
||||
return setting.strings.toList()
|
||||
} catch (_: ClassCastException) {
|
||||
}
|
||||
|
||||
@ -78,15 +78,15 @@ class StringMultiChoiceSetting(
|
||||
* @param selection New value of the int.
|
||||
* @return the existing setting with the new value applied.
|
||||
*/
|
||||
fun setSelectedValues(selection: List<String>): AbstractMultiStringSetting {
|
||||
fun setSelectedValues(selection: String): AbstractMultiStringSetting {
|
||||
val stringSetting = setting as AbstractMultiStringSetting
|
||||
stringSetting.strings = selection
|
||||
stringSetting.strings.add(selection)
|
||||
return stringSetting
|
||||
}
|
||||
|
||||
fun setSelectedValues(selection: List<Short>): AbstractMultiShortSetting {
|
||||
fun setSelectedValues(selection: Short): AbstractMultiShortSetting {
|
||||
val shortSetting = setting as AbstractMultiShortSetting
|
||||
shortSetting.shorts = selection
|
||||
shortSetting.shorts.add(selection)
|
||||
return shortSetting
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,9 @@ import org.citra.citra_emu.databinding.ListItemSettingsHeaderBinding
|
||||
import org.citra.citra_emu.features.settings.model.AbstractBooleanSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractFloatSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractIntSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractMultiIntSetting
|
||||
import org.citra.citra_emu.features.settings.model.AbstractMultiShortSetting
|
||||
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.AbstractStringSetting
|
||||
import org.citra.citra_emu.features.settings.model.FloatSetting
|
||||
@ -663,6 +666,17 @@ class SettingsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getValueForMultiChoiceSelection(item: MultiChoiceSetting, which: Int, is_checked: Boolean): Int {
|
||||
val valuesId = item.valuesId
|
||||
if (valuesId > 0) {
|
||||
val valuesArray = context.resources.getIntArray(valuesId)
|
||||
if (is_checked) {
|
||||
return valuesArray[which]
|
||||
}
|
||||
}
|
||||
return which
|
||||
}
|
||||
|
||||
private fun onMultiChoiceClick(item: MultiChoiceSetting) {
|
||||
clickedItem = item
|
||||
val values = getSelectionForMultiChoiceValues(item)
|
||||
@ -695,27 +709,27 @@ class SettingsAdapter(
|
||||
//TODO: REFACTOR TO BE MULTICHOICE
|
||||
override fun onClick(dialog: DialogInterface?, which: Int, is_checked: Boolean) {
|
||||
when (clickedItem) {
|
||||
is SingleChoiceSetting -> {
|
||||
val scSetting = clickedItem as? SingleChoiceSetting
|
||||
is MultiChoiceSetting -> {
|
||||
val scSetting = clickedItem as? MultiChoiceSetting
|
||||
scSetting?.let {
|
||||
val setting = when (it.setting) {
|
||||
is AbstractIntSetting -> {
|
||||
val value = getValueForSingleChoiceSelection(it, which)
|
||||
if (it.selectedValue != value) {
|
||||
is AbstractMultiIntSetting -> {
|
||||
val value = getValueForMultiChoiceSelection(it, which, is_checked)
|
||||
if (value !in it.selectedValues) {
|
||||
fragmentView?.onSettingChanged()
|
||||
}
|
||||
it.setSelectedValue(value)
|
||||
it.setSelectedValues(value)
|
||||
}
|
||||
|
||||
is AbstractShortSetting -> {
|
||||
val value = getValueForSingleChoiceSelection(it, which).toShort()
|
||||
if (it.selectedValue.toShort() != value) {
|
||||
is AbstractMultiShortSetting -> {
|
||||
val value = getValueForMultiChoiceSelection(it, which, is_checked).toShort()
|
||||
if (value !in it.selectedValues.map { it.toShort() }) {
|
||||
fragmentView?.onSettingChanged()
|
||||
}
|
||||
it.setSelectedValue(value)
|
||||
it.setSelectedValues(value)
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException("Unrecognized type used for SingleChoiceSetting!")
|
||||
else -> throw IllegalStateException("Unrecognized type used for MultiChoiceSetting!")
|
||||
}
|
||||
fragmentView?.putSetting(setting)
|
||||
fragmentView.loadSettingsList()
|
||||
@ -723,22 +737,22 @@ class SettingsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
is StringSingleChoiceSetting -> {
|
||||
val scSetting = clickedItem as? StringSingleChoiceSetting
|
||||
is StringMultiChoiceSetting -> {
|
||||
val scSetting = clickedItem as? StringMultiChoiceSetting
|
||||
scSetting?.let {
|
||||
val setting = when (it.setting) {
|
||||
is AbstractStringSetting -> {
|
||||
is AbstractMultiStringSetting -> {
|
||||
val value = it.getValueAt(which)
|
||||
if (it.selectedValue != value) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValue(value ?: "")
|
||||
if (value !in it.selectedValues ) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValues(value ?: "")
|
||||
}
|
||||
|
||||
is AbstractShortSetting -> {
|
||||
if (it.selectValueIndex != which) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValue(it.getValueAt(which)?.toShort() ?: 1)
|
||||
is AbstractMultiShortSetting -> {
|
||||
if (is_checked != it.selectValueIndices[which]) fragmentView?.onSettingChanged()
|
||||
it.setSelectedValues(it.getValueAt(which)?.toShort() ?: 1)
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException("Unrecognized type used for StringSingleChoiceSetting!")
|
||||
else -> throw IllegalStateException("Unrecognized type used for StringMultiChoiceSetting!")
|
||||
}
|
||||
|
||||
fragmentView?.putSetting(setting)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user