From d5f335b0d6df40fbe92c1a8f1fd0613ecfa648ad Mon Sep 17 00:00:00 2001 From: sds100 Date: Sun, 13 Oct 2024 11:36:02 +0200 Subject: [PATCH] #1274 set parallel trigger to short press when adding assistant key --- .../mappings/keymaps/ConfigKeyMapUseCase.kt | 7 +++- .../keymapper/ConfigKeyMapUseCaseTest.kt | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt index bfeaae44ec..4a2c3be12f 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt @@ -61,8 +61,11 @@ class ConfigKeyMapUseCaseImpl( newKeys.size <= 1 -> TriggerMode.Undefined /* Automatically make it a parallel trigger when the user makes a trigger with more than one key - because this is what most users are expecting when they make a trigger with multiple keys */ - newKeys.size == 2 && !containsKey -> TriggerMode.Parallel(newKeys[0].clickType) + because this is what most users are expecting when they make a trigger with multiple keys. + + It must be a short press because long pressing the assistant key isn't supported. + */ + !containsKey -> TriggerMode.Parallel(ClickType.SHORT_PRESS) else -> trigger.mode } diff --git a/app/src/test/java/io/github/sds100/keymapper/ConfigKeyMapUseCaseTest.kt b/app/src/test/java/io/github/sds100/keymapper/ConfigKeyMapUseCaseTest.kt index cbe893edec..97fe4ecee9 100644 --- a/app/src/test/java/io/github/sds100/keymapper/ConfigKeyMapUseCaseTest.kt +++ b/app/src/test/java/io/github/sds100/keymapper/ConfigKeyMapUseCaseTest.kt @@ -23,7 +23,6 @@ import kotlinx.coroutines.test.runTest import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.`is` -import org.junit.Assert.fail import org.junit.Before import org.junit.Test import org.mockito.kotlin.mock @@ -48,10 +47,45 @@ class ConfigKeyMapUseCaseTest { ) } + @Test + fun `Set trigger mode to short press when adding assistant key to multiple long press trigger keys`() = + runTest(testDispatcher) { + useCase.mapping.value = State.Data(KeyMap()) + + useCase.addKeyCodeTriggerKey(KeyEvent.KEYCODE_VOLUME_DOWN, TriggerKeyDevice.Any) + useCase.addKeyCodeTriggerKey(KeyEvent.KEYCODE_VOLUME_UP, TriggerKeyDevice.Any) + useCase.setTriggerLongPress() + + useCase.addAssistantTriggerKey(AssistantTriggerType.ANY) + + val trigger = useCase.mapping.value.dataOrNull()!!.trigger + assertThat(trigger.mode, `is`(TriggerMode.Parallel(clickType = ClickType.SHORT_PRESS))) + } + + @Test + fun `Set trigger mode to short press when adding assistant key to double press trigger key`() = + runTest(testDispatcher) { + useCase.mapping.value = State.Data(KeyMap()) + + useCase.addKeyCodeTriggerKey(KeyEvent.KEYCODE_VOLUME_DOWN, TriggerKeyDevice.Any) + useCase.setTriggerDoublePress() + useCase.addAssistantTriggerKey(AssistantTriggerType.ANY) + + val trigger = useCase.mapping.value.dataOrNull()!!.trigger + assertThat(trigger.mode, `is`(TriggerMode.Parallel(clickType = ClickType.SHORT_PRESS))) + } + @Test fun `Set trigger mode to short press when adding assistant key to long press trigger key`() = runTest(testDispatcher) { - fail() + useCase.mapping.value = State.Data(KeyMap()) + + useCase.addKeyCodeTriggerKey(KeyEvent.KEYCODE_VOLUME_DOWN, TriggerKeyDevice.Any) + useCase.setTriggerLongPress() + useCase.addAssistantTriggerKey(AssistantTriggerType.ANY) + + val trigger = useCase.mapping.value.dataOrNull()!!.trigger + assertThat(trigger.mode, `is`(TriggerMode.Parallel(clickType = ClickType.SHORT_PRESS))) } @Test