don't use optional chaining operators + address review comments

This commit is contained in:
Charles Ewert 2023-03-05 08:28:30 -05:00
parent 742c60b910
commit 33c3894638

View File

@ -257,11 +257,9 @@ sub Main (args as dynamic) as void
ptr = msg.getData() ptr = msg.getData()
' ptr is for [row, col] of selected item... but we only have 1 row ' ptr is for [row, col] of selected item... but we only have 1 row
series = msg.getRoSGNode() series = msg.getRoSGNode()
if isValid(ptr) and isValid(series?.seasonData?.items) if isValid(ptr) and ptr.count() >= 2 and isValid(ptr[1]) and isValid(series) and isValid(series.seasonData) and isValid(series.seasonData.items)
node = series.seasonData.items[ptr[1]] node = series.seasonData.items[ptr[1]]
group = CreateSeasonDetailsGroup(series.itemContent, node) group = CreateSeasonDetailsGroup(series.itemContent, node)
else
print "Something went wrong", ptr, series
end if end if
else if isNodeEvent(msg, "musicAlbumSelected") else if isNodeEvent(msg, "musicAlbumSelected")
' If you select a Music Album from ANYWHERE, follow this flow ' If you select a Music Album from ANYWHERE, follow this flow
@ -410,13 +408,13 @@ sub Main (args as dynamic) as void
' Check if a specific Audio Stream was selected ' Check if a specific Audio Stream was selected
audio_stream_idx = 1 audio_stream_idx = 1
if isValid(group?.selectedAudioStreamIndex) if isValid(group) and isValid(group.selectedAudioStreamIndex)
audio_stream_idx = group.selectedAudioStreamIndex audio_stream_idx = group.selectedAudioStreamIndex
end if end if
' Check to see if a specific video "version" was selected ' Check to see if a specific video "version" was selected
mediaSourceId = invalid mediaSourceId = invalid
if isValid(group?.selectedVideoStreamId) if isValid(group) and isValid(group.selectedVideoStreamId)
mediaSourceId = group.selectedVideoStreamId mediaSourceId = group.selectedVideoStreamId
end if end if
video_id = group.id video_id = group.id
@ -425,14 +423,14 @@ sub Main (args as dynamic) as void
sceneManager.callFunc("pushScene", video) sceneManager.callFunc("pushScene", video)
end if end if
if isValid(group?.lastFocus?.id) = "main_group" if isValid(group) and isValid(group.lastFocus) and isValid(group.lastFocus.id) and group.lastFocus.id = "main_group"
buttons = group.findNode("buttons") buttons = group.findNode("buttons")
if isValid(buttons) if isValid(buttons)
group.lastFocus = group.findNode("buttons") group.lastFocus = group.findNode("buttons")
end if end if
end if end if
if isValid(group?.lastFocus) if isValid(group) and isValid(group.lastFocus)
group.lastFocus.setFocus(true) group.lastFocus.setFocus(true)
end if end if
@ -447,7 +445,7 @@ sub Main (args as dynamic) as void
trailerData = api_API().users.getlocaltrailers(get_setting("active_user"), group.id) trailerData = api_API().users.getlocaltrailers(get_setting("active_user"), group.id)
video = invalid video = invalid
if isValid(trailerData[0]?.id) if isValid(trailerData) and isValid(trailerData[0]) and isValid(trailerData[0].id)
video_id = trailerData[0].id video_id = trailerData[0].id
video = CreateVideoPlayerGroup(video_id, mediaSourceId, audio_stream_idx, false, false) video = CreateVideoPlayerGroup(video_id, mediaSourceId, audio_stream_idx, false, false)
end if end if
@ -457,12 +455,12 @@ sub Main (args as dynamic) as void
dialog.close = true dialog.close = true
end if end if
if isValid(group?.lastFocus) if isValid(group) and isValid(group.lastFocus)
group.lastFocus.setFocus(true) group.lastFocus.setFocus(true)
end if end if
else if btn <> invalid and btn.id = "watched-button" else if btn <> invalid and btn.id = "watched-button"
movie = group.itemContent movie = group.itemContent
if isValid(movie?.watched) and isValid(movie?.id) if isValid(movie) and isValid(movie.watched) and isValid(movie.id)
if movie.watched if movie.watched
UnmarkItemWatched(movie.id) UnmarkItemWatched(movie.id)
else else
@ -489,11 +487,11 @@ sub Main (args as dynamic) as void
else if isNodeEvent(msg, "optionSelected") else if isNodeEvent(msg, "optionSelected")
button = msg.getRoSGNode() button = msg.getRoSGNode()
group = sceneManager.callFunc("getActiveScene") group = sceneManager.callFunc("getActiveScene")
if button.id = "goto_search" if button.id = "goto_search" and isValid(group)
' Exit out of the side panel ' Exit out of the side panel
panel = group.findNode("options") panel = group.findNode("options")
panel.visible = false panel.visible = false
if isValid(group?.lastFocus) if isValid(group.lastFocus)
group.lastFocus.setFocus(true) group.lastFocus.setFocus(true)
else else
group.setFocus(true) group.setFocus(true)
@ -516,7 +514,7 @@ sub Main (args as dynamic) as void
' Exit out of the side panel ' Exit out of the side panel
panel = group.findNode("options") panel = group.findNode("options")
panel.visible = false panel.visible = false
if isValid(group?.lastFocus) if isValid(group) and isValid(group.lastFocus)
group.lastFocus.setFocus(true) group.lastFocus.setFocus(true)
else else
group.setFocus(true) group.setFocus(true)
@ -539,7 +537,7 @@ sub Main (args as dynamic) as void
end if end if
else if isNodeEvent(msg, "state") else if isNodeEvent(msg, "state")
node = msg.getRoSGNode() node = msg.getRoSGNode()
if isValid(node?.state) if isValid(node) and isValid(node.state)
if m.selectedItemType = "TvChannel" and node.state = "finished" if m.selectedItemType = "TvChannel" and node.state = "finished"
video = CreateVideoPlayerGroup(node.id) video = CreateVideoPlayerGroup(node.id)
m.global.sceneManager.callFunc("pushScene", video) m.global.sceneManager.callFunc("pushScene", video)
@ -551,10 +549,10 @@ sub Main (args as dynamic) as void
if isValid(node.retryWithTranscoding) and node.retryWithTranscoding if isValid(node.retryWithTranscoding) and node.retryWithTranscoding
retryVideo = CreateVideoPlayerGroup(node.Id, invalid, node.audioIndex, true, false) retryVideo = CreateVideoPlayerGroup(node.Id, invalid, node.audioIndex, true, false)
m.global.sceneManager.callFunc("popScene") m.global.sceneManager.callFunc("popScene")
if retryVideo <> invalid if isValid(retryVideo)
m.global.sceneManager.callFunc("pushScene", retryVideo) m.global.sceneManager.callFunc("pushScene", retryVideo)
end if end if
else if isValid(node?.showID) else if not isValid(node.showID)
sceneManager.callFunc("popScene") sceneManager.callFunc("popScene")
else else
if video.errorMsg = "" if video.errorMsg = ""
@ -571,7 +569,7 @@ sub Main (args as dynamic) as void
if event.exitedScreensaver = true if event.exitedScreensaver = true
sceneManager.callFunc("resetTime") sceneManager.callFunc("resetTime")
group = sceneManager.callFunc("getActiveScene") group = sceneManager.callFunc("getActiveScene")
if isValid(group?.subtype()) if isValid(group) and isValid(group.subtype())
if group.subtype() = "Home" if group.subtype() = "Home"
currentTime = CreateObject("roDateTime").AsSeconds() currentTime = CreateObject("roDateTime").AsSeconds()
group.timeLastRefresh = currentTime group.timeLastRefresh = currentTime