apply settings only on finish

This commit is contained in:
Felix Nüsse 2024-07-12 21:13:19 +02:00 committed by OpenSauce
parent dbfefa615d
commit c7f6d2d679
2 changed files with 32 additions and 1 deletions

View File

@ -35,6 +35,8 @@ class InputBindingSetting(
.apply() .apply()
} }
private var key: String = ""
/** /**
* Returns true if this key is for the 3DS Circle Pad * Returns true if this key is for the 3DS Circle Pad
*/ */
@ -230,6 +232,29 @@ class InputBindingSetting(
value = uiString value = uiString
} }
/**
* Stores the provided key input setting as an Android preference.
* Only gets applied when apply(); is called.
*
* @param keyEvent KeyEvent of this key press.
*/
fun onKeyInputDeferred(keyEvent: KeyEvent) {
if (!isButtonMappingSupported()) {
Toast.makeText(context, R.string.input_message_analog_only, Toast.LENGTH_LONG).show()
return
}
key = getInputButtonKey(keyEvent.keyCode)
val uiString = "${keyEvent.device.name}: Button ${keyEvent.keyCode}"
value = uiString
}
/**
* Stores the provided key input setting as an Android preference.
*/
fun applyMapping() {
writeButtonMapping(key)
}
/** /**
* Saves the provided motion input setting as an Android preference. * Saves the provided motion input setting as an Android preference.
* *

View File

@ -71,6 +71,7 @@ class ControllerQuickConfigDialog(
private fun prepareUIforIndex(i: Int) { private fun prepareUIforIndex(i: Int) {
if (allButtons.size-1 < i) { if (allButtons.size-1 < i) {
settingsList.forEach { it.applyMapping() }
dialog?.dismiss() dialog?.dismiss()
return return
} }
@ -145,6 +146,8 @@ class ControllerQuickConfigDialog(
private var setting: InputBindingSetting? = null private var setting: InputBindingSetting? = null
private var debounceTimestamp = System.currentTimeMillis() private var debounceTimestamp = System.currentTimeMillis()
private var settingsList = arrayListOf<InputBindingSetting>()
private fun onKeyEvent(event: KeyEvent): Boolean { private fun onKeyEvent(event: KeyEvent): Boolean {
return when (event.action) { return when (event.action) {
KeyEvent.ACTION_UP -> { KeyEvent.ACTION_UP -> {
@ -154,7 +157,10 @@ class ControllerQuickConfigDialog(
debounceTimestamp = System.currentTimeMillis() debounceTimestamp = System.currentTimeMillis()
index++ index++
setting?.onKeyInput(event) setting?.let {
it.onKeyInputDeferred(event)
settingsList.add(it)
}
prepareUIforIndex(index) prepareUIforIndex(index)
// Even if we ignore the key, we still consume it. Thus return true regardless. // Even if we ignore the key, we still consume it. Thus return true regardless.
true true