Skip to content

Commit

Permalink
#1274 set parallel trigger to short press when adding assistant key
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Oct 13, 2024
1 parent f6e1e95 commit d5f335b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d5f335b

Please sign in to comment.