Skip to content

Commit 2aedf33

Browse files
Separate switch task stops from lock replay (#2511)
- Stop Repeat, Auto Scroll, and gesture patterns before starting external switch holds - Suppress holds for captured Gesture Lock while preserving release replay - Add task tests proving captured Gesture Lock is not stopped as a task 🤖 Auto-generated Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 9433996 commit 2aedf33

3 files changed

Lines changed: 63 additions & 7 deletions

File tree

app/src/main/java/com/enaboapps/switchify/service/core/Tasks.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ class Tasks private constructor() {
3636
* @return True if any ongoing task was found and potentially stopped/advanced, false otherwise.
3737
*/
3838
fun stopOngoingTaskForSwitchPress(): Boolean {
39-
return stopOngoingTask()
39+
return stopStoppableTask()
40+
}
41+
42+
fun stopStoppableTaskForExternalSwitchPress(): Boolean {
43+
return stopStoppableTask()
4044
}
4145

4246
fun onOngoingTaskStarted() {
@@ -55,10 +59,10 @@ class Tasks private constructor() {
5559

5660
fun stopOngoingTaskForSwitchAction(action: SwitchAction): Boolean {
5761
if (shouldBypassOngoingTaskStop(action)) return false
58-
return stopOngoingTask()
62+
return stopStoppableTask()
5963
}
6064

61-
private fun stopOngoingTask(): Boolean {
65+
private fun stopStoppableTask(): Boolean {
6266
if (GestureRepeatManager.instance.stopRepeatForSwitchPress()) return true
6367

6468
// Stop auto-scrolling if active

app/src/main/java/com/enaboapps/switchify/service/switches/external/ExternalSwitchListener.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.util.Log
55
import com.enaboapps.switchify.backend.preferences.PreferenceManager
66
import com.enaboapps.switchify.service.core.ServiceCore
77
import com.enaboapps.switchify.service.core.Tasks
8+
import com.enaboapps.switchify.service.gestures.GestureLockManager
89
import com.enaboapps.switchify.service.scanning.ScanningManager
910
import com.enaboapps.switchify.service.selection.SelectionHandler
1011
import com.enaboapps.switchify.service.stats.StatsCollector
@@ -58,11 +59,16 @@ class ExternalSwitchListener(
5859
// Record stats for switch press
5960
StatsCollector.getInstance().recordSwitchPress("external", keyCode.toString())
6061

61-
val hasHoldActions = switchEvent.holdActions.isNotEmpty()
62-
if (!hasHoldActions &&
63-
Tasks.getInstance().stopOngoingTaskForSwitchAction(switchEvent.pressAction)
64-
) {
62+
if (Tasks.getInstance().stopStoppableTaskForExternalSwitchPress()) {
6563
latestAction = null
64+
ExternalSwitchLongPressHandler.cancelLongPress()
65+
return true
66+
}
67+
68+
if (GestureLockManager.instance.isGestureLockEngaged()) {
69+
latestAction = AbsorbedSwitchAction(switchEvent, System.currentTimeMillis())
70+
ExternalSwitchLongPressHandler.cancelLongPress()
71+
ExternalSwitchLongPressHandler.startLongPress(context, switchEvent.name, emptyList())
6672
return true
6773
}
6874

app/src/test/java/com/enaboapps/switchify/service/core/TasksTest.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.enaboapps.switchify.switches.SwitchAction
1212
import org.junit.After
1313
import org.junit.Assert.assertEquals
1414
import org.junit.Assert.assertFalse
15+
import org.junit.Assert.assertNotNull
1516
import org.junit.Assert.assertTrue
1617
import org.junit.Before
1718
import org.junit.Test
@@ -84,6 +85,51 @@ class TasksTest {
8485
assertTrue(repeatManager.isWaitingForGesture())
8586
}
8687

88+
@Test
89+
fun stopStoppableTaskForExternalSwitchPressStopsRepeat() {
90+
repeatManager.setAutoRepeatEnabledForTesting(true)
91+
repeatManager.onGesturePerformed(testGesture())
92+
93+
assertTrue(tasks.stopStoppableTaskForExternalSwitchPress())
94+
95+
assertFalse(repeatManager.isRepeatSessionActive())
96+
assertTrue(repeatManager.isWaitingForGesture())
97+
}
98+
99+
@Test
100+
fun stopStoppableTaskForExternalSwitchPressStopsAutoScroll() {
101+
assertTrue(autoScrollManager.startAutoScroll(scrollGesture()))
102+
messages.clear()
103+
104+
assertTrue(tasks.stopStoppableTaskForExternalSwitchPress())
105+
106+
assertFalse(autoScrollManager.isAutoScrolling())
107+
assertEquals(listOf(R.string.hud_auto_scroll_stopped), messages)
108+
}
109+
110+
@Test
111+
fun stopStoppableTaskForExternalSwitchPressIgnoresGestureLockEngaged() {
112+
lockManager.enableLockForNextGesture(showMessage = false)
113+
lockManager.setLockedGestureData(testGesture())
114+
115+
assertFalse(tasks.stopStoppableTaskForExternalSwitchPress())
116+
117+
assertTrue(lockManager.isGestureLockEngaged())
118+
assertNotNull(lockManager.getLockedGestureData())
119+
}
120+
121+
@Test
122+
fun stopStoppableTaskForExternalSwitchPressIgnoresWaitingModes() {
123+
repeatManager.setAutoRepeatEnabledForTesting(true)
124+
lockManager.enableLockForNextGesture(showMessage = false)
125+
126+
assertFalse(tasks.stopStoppableTaskForExternalSwitchPress())
127+
128+
assertTrue(repeatManager.isWaitingForGesture())
129+
assertTrue(lockManager.isLocked())
130+
assertFalse(lockManager.isGestureLockEngaged())
131+
}
132+
87133
@Test
88134
fun shouldAbsorbSwitchReleaseTrueWhileRepeatSessionActive() {
89135
repeatManager.setAutoRepeatEnabledForTesting(true)

0 commit comments

Comments
 (0)