Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track menu scan state separately #200

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
}
}
Loading