@@ -3,6 +3,7 @@ import "pkg:/source/api/Image.bs"
33import "pkg:/source/enums/ColorPalette.bs"
44import "pkg:/source/enums/ImageType.bs"
55import "pkg:/source/enums/KeyCode.bs"
6+ import "pkg:/source/enums/String.bs"
67import "pkg:/source/enums/TaskControl.bs"
78import "pkg:/source/utils/config.bs"
89import "pkg:/source/utils/misc.bs"
@@ -55,8 +56,8 @@ sub init()
5556 song = m .top .findNode ("song" )
5657 song .font .size = 60
5758
58- artist = m .top .findNode ("artist" )
59- artist .font .size = 35
59+ m . artist = m .top .findNode ("artist" )
60+ m . artist .font .size = 35
6061
6162 numberofsongs = m .top .findNode ("numberofsongs" )
6263 numberofsongs .font .size = 25
@@ -293,7 +294,7 @@ sub audioStateChanged()
293294 if m .global .audioPlayer .loopMode = "one"
294295 m .scrubTimestamp = - 1
295296 playAction ()
296- exitScrubMode ()
297+ exitScrubMode (m . buttons )
297298 return
298299 end if
299300
@@ -355,7 +356,7 @@ function previousClicked() as boolean
355356 end if
356357 end if
357358
358- exitScrubMode ()
359+ exitScrubMode (m . buttons )
359360
360361 m .lastRecordedPositionTimestamp = 0
361362 m .positionTimestamp .text = "0:00"
@@ -415,7 +416,7 @@ function nextClicked() as boolean
415416 end if
416417 end if
417418
418- exitScrubMode ()
419+ exitScrubMode (m . buttons )
419420
420421 m .lastRecordedPositionTimestamp = 0
421422 m .positionTimestamp .text = "0:00"
@@ -482,7 +483,7 @@ sub LoadNextSong()
482483 m .global .audioPlayer .control = "stop"
483484 end if
484485
485- exitScrubMode ()
486+ exitScrubMode (m . buttons )
486487
487488 ' Reset playPosition bar without animation
488489 m .playPosition .width = 0
@@ -789,8 +790,12 @@ end sub
789790
790791' exitScrubMode: Moves player out of scrub mode state, resets back to standard play mode
791792'
792- sub exitScrubMode ()
793- m .buttons .setFocus (true )
793+ sub exitScrubMode (nodeReceivingFocus = m .buttons as dynamic )
794+ if not isValid (nodeReceivingFocus )
795+ nodeReceivingFocus = m .buttons
796+ end if
797+
798+ nodeReceivingFocus .setFocus (true )
794799 m .thumb .setFocus (false )
795800
796801 if m .seekPosition .visible
@@ -801,7 +806,12 @@ sub exitScrubMode()
801806
802807 m .inScrubMode = false
803808 m .thumb .visible = false
804- setSelectedButtonState (ButtonState .SELECTED )
809+
810+ if isValid (nodeReceivingFocus .id )
811+ if LCase (nodeReceivingFocus .id ) = "buttons"
812+ setSelectedButtonState (ButtonState .SELECTED )
813+ end if
814+ end if
805815end sub
806816
807817' checkDisplaySiblingItem: Determine visible state for both previous and next item popups
@@ -848,17 +858,63 @@ sub checkDisplaySiblingItem()
848858 m .previousItem .visible = showPreviousItem
849859end sub
850860
861+ sub setFocusOnThumb ()
862+ if not m .thumb .visible
863+ m .thumb .visible = true
864+ setSelectedButtonState (ButtonState .DEFAULT )
865+ end if
866+
867+ if not m .seekPosition .visible
868+ m .seekPosition .visible = true
869+ end if
870+
871+ m .thumb .setFocus (true )
872+ end sub
873+
851874' Process key press events
852875function onKeyEvent (key as string , press as boolean ) as boolean
853876
854- ' Key bindings for remote control buttons
855877 if press
856878 ' If user presses key to turn off screensaver, don't do anything else with it
857879 if screenSaverActive ()
858880 endScreenSaver ()
859881 return true
860882 end if
861883
884+ ' Key Event handler when m.artist is in focus
885+ if m .artist .hasFocus ()
886+ if key = KeyCode .DOWN
887+ m .artist .setFocus (false )
888+ m .artist .color = ColorPalette .WHITE
889+ setFocusOnThumb ()
890+ return true
891+ end if
892+
893+ if key = KeyCode .OK or key = KeyCode .PLAY
894+ currentItem = m .global .queueManager .callFunc ("getCurrentItem" )
895+
896+ if isChainValid (currentItem , "ArtistItems" )
897+ if isValidAndNotEmpty (currentItem .ArtistItems )
898+ m .global .audioPlayer .control = "stop"
899+ m .global .audioPlayer .loopMode = ""
900+ m .top .selectedArtist = currentItem .ArtistItems [0 ]
901+ end if
902+ end if
903+
904+ if not isValidAndNotEmpty (m .top .selectedArtist )
905+ if isChainValid (currentItem , "json.ArtistItems" )
906+ if isValidAndNotEmpty (currentItem .json .ArtistItems )
907+ m .global .audioPlayer .control = "stop"
908+ m .global .audioPlayer .loopMode = ""
909+ m .top .selectedArtist = currentItem .json .ArtistItems [0 ]
910+ end if
911+ end if
912+ end if
913+
914+ return true
915+ end if
916+ end if
917+
862918 ' Key Event handler when m.thumb is in focus
863919 if m .thumb .hasFocus ()
864920 if key = KeyCode .RIGHT
@@ -873,6 +929,14 @@ function onKeyEvent(key as string, press as boolean) as boolean
873929 return true
874930 end if
875931
932+ if key = KeyCode .UP
933+ m .artist .color = ColorPalette .HIGHLIGHT
934+ if m .thumb .visible
935+ exitScrubMode (m .artist )
936+ end if
937+ return true
938+ end if
939+
876940 if key = KeyCode .OK or key = KeyCode .PLAY
877941 if m .inScrubMode
878942 startLoadingSpinner ()
@@ -892,24 +956,51 @@ function onKeyEvent(key as string, press as boolean) as boolean
892956 return playAction ()
893957 end if
894958
895- if key = KeyCode .UP
896- if not m .thumb .visible
897- m .thumb .visible = true
898- setSelectedButtonState (ButtonState .DEFAULT )
959+ if m .buttons .hasFocus ()
960+ if key = KeyCode .UP
961+ setFocusOnThumb ()
962+ m .buttons .setFocus (false )
963+ checkDisplaySiblingItem ()
964+ return true
899965 end if
900- if not m .seekPosition .visible
901- m .seekPosition .visible = true
966+
967+ if key = KeyCode .OK
968+ if m .buttons .getChild (m .top .selectedButtonIndex ).id = "play"
969+ return playAction ()
970+ else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "previous"
971+ return previousClicked ()
972+ else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "next"
973+ return nextClicked ()
974+ else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "shuffle"
975+ return shuffleClicked ()
976+ else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "loop"
977+ return loopClicked ()
978+ end if
902979 end if
903980
904- m .thumb .setFocus (true )
905- m .buttons .setFocus (false )
906- checkDisplaySiblingItem ()
907- return true
981+ if key = KeyCode .RIGHT
982+ if m .global .queueManager .callFunc ("getCount" ) = 1 then return false
983+ m .previouslySelectedButtonIndex = m .top .selectedButtonIndex
984+ if m .top .selectedButtonIndex < m .buttonCount - 1 then m .top .selectedButtonIndex = m .top .selectedButtonIndex + 1
985+ checkDisplaySiblingItem ()
986+ return true
987+ end if
988+
989+ if key = KeyCode .LEFT
990+ if m .global .queueManager .callFunc ("getCount" ) = 1 then return false
991+
992+ if m .top .selectedButtonIndex > 0
993+ m .previouslySelectedButtonIndex = m .top .selectedButtonIndex
994+ m .top .selectedButtonIndex = m .top .selectedButtonIndex - 1
995+ checkDisplaySiblingItem ()
996+ end if
997+ return true
998+ end if
908999 end if
9091000
9101001 if key = KeyCode .DOWN
9111002 if m .thumb .visible
912- exitScrubMode ()
1003+ exitScrubMode (m . buttons )
9131004 end if
9141005 checkDisplaySiblingItem ()
9151006 return true
@@ -922,40 +1013,6 @@ function onKeyEvent(key as string, press as boolean) as boolean
9221013 return previousClicked ()
9231014 else if key = KeyCode .FASTFORWRD
9241015 return nextClicked ()
925- else if key = KeyCode .left
926- if m .buttons .hasFocus ()
927- if m .global .queueManager .callFunc ("getCount" ) = 1 then return false
928-
929- if m .top .selectedButtonIndex > 0
930- m .previouslySelectedButtonIndex = m .top .selectedButtonIndex
931- m .top .selectedButtonIndex = m .top .selectedButtonIndex - 1
932- checkDisplaySiblingItem ()
933- end if
934- return true
935- end if
936- else if key = KeyCode .RIGHT
937- if m .buttons .hasFocus ()
938- if m .global .queueManager .callFunc ("getCount" ) = 1 then return false
939-
940- m .previouslySelectedButtonIndex = m .top .selectedButtonIndex
941- if m .top .selectedButtonIndex < m .buttonCount - 1 then m .top .selectedButtonIndex = m .top .selectedButtonIndex + 1
942- checkDisplaySiblingItem ()
943- return true
944- end if
945- else if key = KeyCode .OK
946- if m .buttons .hasFocus ()
947- if m .buttons .getChild (m .top .selectedButtonIndex ).id = "play"
948- return playAction ()
949- else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "previous"
950- return previousClicked ()
951- else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "next"
952- return nextClicked ()
953- else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "shuffle"
954- return shuffleClicked ()
955- else if m .buttons .getChild (m .top .selectedButtonIndex ).id = "loop"
956- return loopClicked ()
957- end if
958- end if
9591016 end if
9601017 end if
9611018
0 commit comments