diff options
| author | JosJuice <josjuice@gmail.com> | 2025-05-16 18:12:21 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2025-06-07 10:20:21 +0200 |
| commit | 43b254aaad5add867b719857d6f8b4fe2d6b750d (patch) | |
| tree | dafdbc53eb3a115d0c9532b2704bb8fa53e57c80 /Source/Android/app/src/main/java/org | |
| parent | 1002f296918153c55dca674b3d70a54485f00306 (diff) | |
Android: Update advanced mapping dialog when devices change
Without this, there was a bug where if you turned the device's screen
off and on again while in the advanced mapping dialog, the input
indicators would stop updating. This is because turning the screen on
again causes devices to refresh, which causes all devices to be
recreated, leaving the AdvancedMappingControlViewHolders stuck
referencing controls belonging to devices that are no longer being
updated.
Diffstat (limited to 'Source/Android/app/src/main/java/org')
2 files changed, 26 insertions, 5 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.kt index d5945f2784..e09e0dec99 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/ControllerInterface.kt @@ -30,10 +30,14 @@ object ControllerInterface { private var inputStateUpdatePending = AtomicBoolean(false) private val inputStateVersion = MutableLiveData(0) + private val devicesVersion = MutableLiveData(0) val inputStateChanged: LiveData<Int> get() = inputStateVersion + val devicesChanged: LiveData<Int> + get() = devicesVersion + /** * Activities which want to pass on inputs to native code * should call this in their own dispatchKeyEvent method. @@ -119,6 +123,14 @@ object ControllerInterface { @Keep @JvmStatic + private fun onDevicesChanged() { + Handler(Looper.getMainLooper()).post { + devicesVersion.value = devicesVersion.value?.plus(1) + } + } + + @Keep + @JvmStatic private fun registerInputDeviceListener() { looperThread = LooperThread("Hotplug thread") looperThread.start() diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/AdvancedMappingDialog.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/AdvancedMappingDialog.kt index 2117ed3102..803f6e4cc6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/AdvancedMappingDialog.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/AdvancedMappingDialog.kt @@ -25,7 +25,7 @@ class AdvancedMappingDialog( private val controlReference: ControlReference, private val controller: EmulatedController ) : AlertDialog(context), OnItemClickListener { - private val devices: Array<String> = ControllerInterface.getAllDeviceStrings() + private lateinit var devices: Array<String> private val controlAdapter: AdvancedMappingControlAdapter private lateinit var selectedDevice: String @@ -36,10 +36,6 @@ class AdvancedMappingDialog( binding.dropdownDevice.onItemClickListener = this - val deviceAdapter = - ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, devices) - binding.dropdownDevice.setAdapter(deviceAdapter) - controlAdapter = AdvancedMappingControlAdapter(lifecycle, controlReference.isInput()) { control: String -> onControlClicked(control) } @@ -52,6 +48,12 @@ class AdvancedMappingDialog( binding.editExpression.setText(controlReference.getExpression()) + ControllerInterface.devicesChanged.observe(this) { + onDevicesChanged() + setSelectedDevice(selectedDevice) + } + + onDevicesChanged() selectDefaultDevice() } @@ -72,6 +74,13 @@ class AdvancedMappingDialog( return super.dispatchGenericMotionEvent(event) } + private fun onDevicesChanged() { + devices = ControllerInterface.getAllDeviceStrings() + binding.dropdownDevice.setAdapter( + ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, devices) + ) + } + private fun setSelectedDevice(deviceString: String) { selectedDevice = deviceString |
