Android: Convert InputDeviceSetting to Kotlin

This commit is contained in:
Charles Lombardo 2023-06-10 05:16:07 -04:00
parent 2590382871
commit 9d7bd6e6bd
6 changed files with 56 additions and 89 deletions

View File

@ -1,70 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.input.model.view;
import android.content.Context;
import org.dolphinemu.dolphinemu.features.input.model.ControllerInterface;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.EmulatedController;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting;
public class InputDeviceSetting extends StringSingleChoiceSetting
{
private final EmulatedController mController;
public InputDeviceSetting(Context context, int titleId, int descriptionId,
EmulatedController controller)
{
super(context, null, titleId, descriptionId, null, null, null);
mController = controller;
refreshChoicesAndValues();
}
@Override
public String getSelectedChoice()
{
return mController.getDefaultDevice();
}
@Override
public String getSelectedValue()
{
return mController.getDefaultDevice();
}
@Override
public void setSelectedValue(Settings settings, String newValue)
{
mController.setDefaultDevice(newValue);
}
@Override
public void refreshChoicesAndValues()
{
String[] devices = ControllerInterface.getAllDeviceStrings();
setChoices(devices);
setValues(devices);
}
@Override
public boolean isEditable()
{
return true;
}
@Override
public boolean canClear()
{
return true;
}
@Override
public void clear(Settings settings)
{
setSelectedValue(settings, "");
}
}

View File

@ -0,0 +1,42 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.input.model.view
import android.content.Context
import org.dolphinemu.dolphinemu.features.input.model.ControllerInterface
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.EmulatedController
import org.dolphinemu.dolphinemu.features.settings.model.Settings
import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting
class InputDeviceSetting(
context: Context,
titleId: Int,
descriptionId: Int,
private val controller: EmulatedController
) : StringSingleChoiceSetting(context, null, titleId, descriptionId, null, null, null) {
init {
refreshChoicesAndValues()
}
override val selectedChoice: String
get() = controller.getDefaultDevice()
override val selectedValue: String
get() = controller.getDefaultDevice()
override fun setSelectedValue(settings: Settings, selection: String) =
controller.setDefaultDevice(selection)
override fun refreshChoicesAndValues() {
val devices = ControllerInterface.getAllDeviceStrings()
choices = devices
values = devices
}
override val isEditable: Boolean = true
override fun canClear(): Boolean = true
override fun clear(settings: Settings) = setSelectedValue(settings, "")
}

View File

@ -4,14 +4,14 @@ package org.dolphinemu.dolphinemu.features.settings.model
object PostProcessing {
@JvmStatic
val shaderList: Array<String?>
val shaderList: Array<String>
external get
@JvmStatic
val anaglyphShaderList: Array<String?>
val anaglyphShaderList: Array<String>
external get
@JvmStatic
val passiveShaderList: Array<String?>
val passiveShaderList: Array<String>
external get
}

View File

@ -17,9 +17,9 @@ open class StringSingleChoiceSetting : SettingsItem {
override val setting: AbstractSetting?
get() = stringSetting
var choices: Array<String?>?
var choices: Array<String>?
protected set
var values: Array<String?>?
var values: Array<String>?
protected set
val menuTag: MenuTag?
var noChoicesAvailableString = 0
@ -37,8 +37,8 @@ open class StringSingleChoiceSetting : SettingsItem {
setting: AbstractStringSetting?,
titleId: Int,
descriptionId: Int,
choices: Array<String?>?,
values: Array<String?>?,
choices: Array<String>?,
values: Array<String>?,
menuTag: MenuTag? = null
) : super(context, titleId, descriptionId) {
stringSetting = setting
@ -52,8 +52,8 @@ open class StringSingleChoiceSetting : SettingsItem {
setting: AbstractStringSetting,
titleId: Int,
descriptionId: Int,
choices: Array<String?>,
values: Array<String?>,
choices: Array<String>,
values: Array<String>,
noChoicesAvailableString: Int
) : this(context, setting, titleId, descriptionId, choices, values) {
this.noChoicesAvailableString = noChoicesAvailableString
@ -102,8 +102,8 @@ open class StringSingleChoiceSetting : SettingsItem {
return -1
}
open fun setSelectedValue(settings: Settings?, selection: String?) {
stringSetting!!.setString(settings!!, selection!!)
open fun setSelectedValue(settings: Settings, selection: String) {
stringSetting!!.setString(settings, selection)
}
open fun refreshChoicesAndValues() {}

View File

@ -474,7 +474,7 @@ class SettingsAdapter(
val value = scSetting.getValueAt(which)
if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
scSetting.setSelectedValue(settings, value)
scSetting.setSelectedValue(settings!!, value!!)
closeDialog()
}

View File

@ -1339,13 +1339,8 @@ class SettingsFragmentPresenter(
val shaderList =
if (stereoModeValue == anaglyphMode) PostProcessing.anaglyphShaderList else PostProcessing.shaderList
val shaderListEntries = arrayOfNulls<String>(shaderList.size + 1)
shaderListEntries[0] = context.getString(R.string.off)
System.arraycopy(shaderList, 0, shaderListEntries, 1, shaderList.size)
val shaderListValues = arrayOfNulls<String>(shaderList.size + 1)
shaderListValues[0] = ""
System.arraycopy(shaderList, 0, shaderListValues, 1, shaderList.size)
val shaderListEntries = arrayOf(context.getString(R.string.off), *shaderList)
val shaderListValues = arrayOf("", *shaderList)
sl.add(
StringSingleChoiceSetting(