Skip to content

Commit

Permalink
Merge pull request #200 from enaboapps/iss199
Browse files Browse the repository at this point in the history
Track menu scan state separately
  • Loading branch information
enaboapps authored Mar 7, 2024
2 parents 33813b2 + d5c5bbc commit 21d8791
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.enaboapps.switchify.service.scanning
object ScanReceiver {
var state: ReceiverState = ReceiverState.CURSOR

/**
* This variable is used to determine if the scanning is in the menu
*/
var isInMenu = false

/**
* This enum represents the state of the scanning receiver
*/
Expand All @@ -16,11 +21,6 @@ object ScanReceiver {
* This state represents the item scan
* Sequentially scanning the items on the screen
*/
ITEM_SCAN,

/**
* This state represents the menu
*/
MENU
ITEM_SCAN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,29 @@ class ScanningManager(
// This function explicitly sets the state of the scanning manager to cursor
fun setCursorState() {
ScanReceiver.state = ScanReceiver.ReceiverState.CURSOR
ScanReceiver.isInMenu = false
}

// This function explicitly sets the state of the scanning manager to item scan
fun setItemScanState() {
ScanReceiver.state = ScanReceiver.ReceiverState.ITEM_SCAN
ScanReceiver.isInMenu = false
}

// This function explicitly sets the state of the scanning manager to menu
fun setMenuState() {
ScanReceiver.state = ScanReceiver.ReceiverState.MENU
ScanReceiver.isInMenu = true
}


// This function makes a selection
fun select() {
if (ScanReceiver.isInMenu) {
// Select the menu item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.performSelection()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Perform the cursor action
Expand All @@ -56,11 +64,6 @@ class ScanningManager(
// Perform the item scan action
nodeScanner.scanTree.performSelection()
}

ScanReceiver.ReceiverState.MENU -> {
// Select the menu item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.performSelection()
}
}
}

Expand All @@ -84,6 +87,12 @@ class ScanningManager(
}

SwitchAction.Actions.ACTION_STOP_SCANNING -> {
if (ScanReceiver.isInMenu) {
// Stop the menu scanning
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.stopScanning()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// reset the cursor
Expand All @@ -94,15 +103,16 @@ class ScanningManager(
// Stop item scanning
nodeScanner.scanTree.stopScanning()
}

ScanReceiver.ReceiverState.MENU -> {
// Stop scanning
MenuManager.getInstance().closeMenuHierarchy()
}
}
}

SwitchAction.Actions.ACTION_CHANGE_SCANNING_DIRECTION -> {
if (ScanReceiver.isInMenu) {
// Change the menu scanning direction
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.swapScanDirection()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Change the cursor direction
Expand All @@ -113,15 +123,16 @@ class ScanningManager(
// Change the item scan direction
nodeScanner.scanTree.swapScanDirection()
}

ScanReceiver.ReceiverState.MENU -> {
// Change the menu direction
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.swapScanDirection()
}
}
}

SwitchAction.Actions.ACTION_MOVE_TO_NEXT_ITEM -> {
if (ScanReceiver.isInMenu) {
// Move the menu to the next item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.stepForward()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Move the cursor to the next item
Expand All @@ -132,15 +143,16 @@ class ScanningManager(
// Move to the next item
nodeScanner.scanTree.stepForward()
}

ScanReceiver.ReceiverState.MENU -> {
// Move the menu to the next item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.stepForward()
}
}
}

SwitchAction.Actions.ACTION_MOVE_TO_PREVIOUS_ITEM -> {
if (ScanReceiver.isInMenu) {
// Move the menu to the previous item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.stepBackward()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Move the cursor to the previous item
Expand All @@ -151,11 +163,6 @@ class ScanningManager(
// Move to the previous item
nodeScanner.scanTree.stepBackward()
}

ScanReceiver.ReceiverState.MENU -> {
// Move the menu to the previous item
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.stepBackward()
}
}
}

Expand All @@ -167,6 +174,12 @@ class ScanningManager(
}

fun pauseScanning() {
if (ScanReceiver.isInMenu) {
// Pause the menu
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.pauseScanning()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Pause the cursor
Expand All @@ -177,15 +190,16 @@ class ScanningManager(
// Pause the item scan
nodeScanner.scanTree.pauseScanning()
}

ScanReceiver.ReceiverState.MENU -> {
// Pause the menu
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.pauseScanning()
}
}
}

fun resumeScanning() {
if (ScanReceiver.isInMenu) {
// Resume the menu
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.resumeScanning()
return
}

when (ScanReceiver.state) {
ScanReceiver.ReceiverState.CURSOR -> {
// Resume the cursor
Expand All @@ -196,11 +210,6 @@ class ScanningManager(
// Resume the item scan
nodeScanner.scanTree.resumeScanning()
}

ScanReceiver.ReceiverState.MENU -> {
// Resume the menu
MenuManager.getInstance().menuHierarchy?.getTopMenu()?.scanTree?.resumeScanning()
}
}
}
}

0 comments on commit 21d8791

Please sign in to comment.