@@ -84,6 +84,30 @@ object CommandParser {
8484 Regex (" (?i)\\ b(?:letzte apps|letzte anwendungen|app übersicht|app-übersicht|übersicht)\\ b" )
8585 )
8686
87+ // Scroll down patterns - for scrolling down
88+ private val SCROLL_DOWN_PATTERNS = listOf (
89+ // Function-like patterns
90+ Regex (" (?i)\\ bscrollDown\\ (\\ )" ),
91+ Regex (" (?i)\\ bscrollDownPage\\ (\\ )" ),
92+ Regex (" (?i)\\ bpageDown\\ (\\ )" ),
93+
94+ // Natural language patterns
95+ Regex (" (?i)\\ b(?:scroll|swipe|move|nach unten|runter) (?:down|nach unten|runter)\\ b" ),
96+ Regex (" (?i)\\ b(?:nach unten scrollen|runter scrollen|nach unten wischen|runter wischen)\\ b" )
97+ )
98+
99+ // Scroll up patterns - for scrolling up
100+ private val SCROLL_UP_PATTERNS = listOf (
101+ // Function-like patterns
102+ Regex (" (?i)\\ bscrollUp\\ (\\ )" ),
103+ Regex (" (?i)\\ bscrollUpPage\\ (\\ )" ),
104+ Regex (" (?i)\\ bpageUp\\ (\\ )" ),
105+
106+ // Natural language patterns
107+ Regex (" (?i)\\ b(?:scroll|swipe|move|nach oben|hoch) (?:up|nach oben|hoch)\\ b" ),
108+ Regex (" (?i)\\ b(?:nach oben scrollen|hoch scrollen|nach oben wischen|hoch wischen)\\ b" )
109+ )
110+
87111 // Buffer for storing partial text between calls
88112 private var textBuffer = " "
89113
@@ -140,6 +164,8 @@ object CommandParser {
140164 is Command .PressHomeButton -> Log .d(TAG , " Command details: PressHomeButton" )
141165 is Command .PressBackButton -> Log .d(TAG , " Command details: PressBackButton" )
142166 is Command .ShowRecentApps -> Log .d(TAG , " Command details: ShowRecentApps" )
167+ is Command .ScrollDown -> Log .d(TAG , " Command details: ScrollDown" )
168+ is Command .ScrollUp -> Log .d(TAG , " Command details: ScrollUp" )
143169 }
144170 }
145171 } catch (e: Exception ) {
@@ -170,6 +196,12 @@ object CommandParser {
170196
171197 // Look for recent apps commands
172198 findRecentAppsCommands(text, commands)
199+
200+ // Look for scroll down commands
201+ findScrollDownCommands(text, commands)
202+
203+ // Look for scroll up commands
204+ findScrollUpCommands(text, commands)
173205 }
174206
175207 /* *
@@ -309,6 +341,42 @@ object CommandParser {
309341 }
310342 }
311343
344+ /* *
345+ * Find scroll down commands in the text
346+ */
347+ private fun findScrollDownCommands (text : String , commands : MutableList <Command >) {
348+ // Try each pattern
349+ for (pattern in SCROLL_DOWN_PATTERNS ) {
350+ if (pattern.containsMatchIn(text)) {
351+ // Check if this command is already in the list (avoid duplicates)
352+ if (! commands.any { it is Command .ScrollDown }) {
353+ Log .d(TAG , " Found scroll down command with pattern ${pattern.pattern} " )
354+ commands.add(Command .ScrollDown )
355+ // Only add one scroll down command even if multiple matches are found
356+ break
357+ }
358+ }
359+ }
360+ }
361+
362+ /* *
363+ * Find scroll up commands in the text
364+ */
365+ private fun findScrollUpCommands (text : String , commands : MutableList <Command >) {
366+ // Try each pattern
367+ for (pattern in SCROLL_UP_PATTERNS ) {
368+ if (pattern.containsMatchIn(text)) {
369+ // Check if this command is already in the list (avoid duplicates)
370+ if (! commands.any { it is Command .ScrollUp }) {
371+ Log .d(TAG , " Found scroll up command with pattern ${pattern.pattern} " )
372+ commands.add(Command .ScrollUp )
373+ // Only add one scroll up command even if multiple matches are found
374+ break
375+ }
376+ }
377+ }
378+ }
379+
312380 /* *
313381 * Clear the text buffer
314382 */
@@ -373,4 +441,14 @@ sealed class Command {
373441 * Command to show recent apps
374442 */
375443 object ShowRecentApps : Command()
444+
445+ /* *
446+ * Command to scroll down
447+ */
448+ object ScrollDown : Command()
449+
450+ /* *
451+ * Command to scroll up
452+ */
453+ object ScrollUp : Command()
376454}
0 commit comments