apply settings only on finish
This commit is contained in:
parent
6011c323ae
commit
5df1b4306b
2 changed files with 32 additions and 1 deletions
|
|
@ -35,6 +35,8 @@ class InputBindingSetting(
|
|||
.apply()
|
||||
}
|
||||
|
||||
private var key: String = ""
|
||||
|
||||
/**
|
||||
* Returns true if this key is for the 3DS Circle Pad
|
||||
*/
|
||||
|
|
@ -231,6 +233,29 @@ class InputBindingSetting(
|
|||
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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ class ControllerQuickConfigDialog(
|
|||
|
||||
private fun prepareUIforIndex(i: Int) {
|
||||
if (allButtons.size-1 < i) {
|
||||
settingsList.forEach { it.applyMapping() }
|
||||
dialog?.dismiss()
|
||||
return
|
||||
}
|
||||
|
|
@ -145,6 +146,8 @@ class ControllerQuickConfigDialog(
|
|||
private var setting: InputBindingSetting? = null
|
||||
private var debounceTimestamp = System.currentTimeMillis()
|
||||
|
||||
private var settingsList = arrayListOf<InputBindingSetting>()
|
||||
|
||||
private fun onKeyEvent(event: KeyEvent): Boolean {
|
||||
return when (event.action) {
|
||||
KeyEvent.ACTION_UP -> {
|
||||
|
|
@ -154,7 +157,10 @@ class ControllerQuickConfigDialog(
|
|||
|
||||
debounceTimestamp = System.currentTimeMillis()
|
||||
index++
|
||||
setting?.onKeyInput(event)
|
||||
setting?.let {
|
||||
it.onKeyInputDeferred(event)
|
||||
settingsList.add(it)
|
||||
}
|
||||
prepareUIforIndex(index)
|
||||
// Even if we ignore the key, we still consume it. Thus return true regardless.
|
||||
true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue