jf-roku/components/music/ArtistView.brs

249 lines
6.9 KiB
Plaintext
Raw Normal View History

2022-05-14 02:35:50 +00:00
sub init()
m.top.optionsAvailable = false
2022-05-21 20:45:01 +00:00
setupMainNode()
2022-07-19 02:28:06 +00:00
setupButtons()
m.albumHeader = m.top.findNode("albumHeader")
m.albumHeader.text = tr("Albums")
m.albums = m.top.findNode("albums")
m.albums.observeField("infocus", "onAlbumFocusChange")
m.pageLoadAnimation = m.top.findNode("pageLoad")
m.pageLoadAnimation.control = "start"
m.showAlbumsAnimation = m.top.findNode("showAlbums")
m.hideAlbumsAnimation = m.top.findNode("hideAlbums")
m.sectionNavigation = m.top.findNode("sectionNavigation")
m.sectionNavigation.observeField("escape", "onSectionNavigationEscape")
m.sectionNavigation.observeField("selected", "onSectionNavigationSelected")
' Load background image
m.LoadBackdropImageTask = CreateObject("roSGNode", "LoadItemsTask")
m.LoadBackdropImageTask.itemsToLoad = "backdropImage"
m.backDrop = m.top.findNode("backdrop")
m.artistImage = m.top.findNode("artistImage")
m.dscr = m.top.findNode("overview")
m.dscr.observeField("isTextEllipsized", "onEllipsisChanged")
createDialogPallete()
2022-05-21 20:45:01 +00:00
end sub
2022-07-19 02:28:06 +00:00
' Setup playback buttons, default to Play button selected
sub setupButtons()
m.buttonGrp = m.top.findNode("buttons")
m.buttonCount = m.buttonGrp.getChildCount()
m.playButton = m.top.findNode("play")
m.previouslySelectedButtonIndex = -1
m.top.observeField("selectedButtonIndex", "onButtonSelectedChange")
m.top.selectedButtonIndex = 0
end sub
' Event handler when user selected a different playback button
sub onButtonSelectedChange()
' Change previously selected button back to default image
if m.previouslySelectedButtonIndex > -1
selectedButton = m.buttonGrp.getChild(m.previouslySelectedButtonIndex)
selectedButton.setFocus(false)
end if
' Change selected button image to selected image
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.setFocus(true)
end sub
2022-05-21 20:45:01 +00:00
sub setupMainNode()
2022-07-19 02:28:06 +00:00
m.main = m.top.findNode("toplevel")
m.main.translation = [120, 175]
2022-05-14 02:35:50 +00:00
end sub
2022-05-21 20:45:01 +00:00
' Event fired when page data is loaded
sub pageContentChanged()
item = m.top.pageContent
2022-05-14 02:35:50 +00:00
' Use metadata to load backdrop image
m.LoadBackdropImageTask.itemId = item.json.id
m.LoadBackdropImageTask.observeField("content", "onBackdropImageLoaded")
m.LoadBackdropImageTask.control = "RUN"
2022-05-14 21:14:15 +00:00
' Populate scene data
2022-05-21 20:45:01 +00:00
setScreenTitle(item.json)
setPosterImage(item.posterURL)
setOnScreenTextValues(item.json)
2022-05-14 02:35:50 +00:00
end sub
2022-05-21 20:45:01 +00:00
sub setScreenTitle(json)
if isValid(json)
m.top.overhangTitle = json.name
end if
end sub
2022-05-14 02:35:50 +00:00
2022-05-21 20:45:01 +00:00
sub setPosterImage(posterURL)
2022-07-19 02:28:06 +00:00
if not isValid(posterURL) or posterURL = ""
posterURL = "pkg:/images/missingArtist.png"
2022-05-14 02:35:50 +00:00
end if
2022-07-19 02:28:06 +00:00
m.artistImage.uri = posterURL
2022-05-21 20:45:01 +00:00
end sub
2022-05-14 02:35:50 +00:00
sub onBackdropImageLoaded()
data = m.LoadBackdropImageTask.content[0]
m.LoadBackdropImageTask.unobserveField("content")
if isValid(data) and data <> ""
setBackdropImage(data)
end if
end sub
' Add backdrop image to screen
sub setBackdropImage(data)
if isValid(data)
if m.backDrop.uri <> data
m.backDrop.uri = data
end if
end if
end sub
2022-05-21 20:45:01 +00:00
' Populate on screen text variables
sub setOnScreenTextValues(json)
if isValid(json)
setFieldTextValue("overview", json.overview)
end if
2022-05-14 02:35:50 +00:00
end sub
sub onEllipsisChanged()
if m.dscr.isTextEllipsized
dscrShowFocus()
end if
end sub
2022-07-19 02:28:06 +00:00
sub onAlbumFocusChange()
if m.albums.infocus
m.albums.setFocus(true)
m.showAlbumsAnimation.control = "start"
return
end if
' Change selected button image to selected image
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.setFocus(true)
m.albums.setFocus(false)
m.hideAlbumsAnimation.control = "start"
end sub
sub onSectionNavigationEscape()
if m.sectionNavigation.escape = "right"
if m.albums.infocus
m.albums.setFocus(true)
return
end if
selectedButton = m.buttonGrp.getChild(0)
selectedButton.setFocus(true)
end if
end sub
sub onSectionNavigationSelected()
m.albums.infocus = (m.sectionNavigation.selected = 1)
end sub
sub dscrShowFocus()
if m.dscr.isTextEllipsized
m.dscr.setFocus(true)
m.dscr.opacity = 1.0
end if
end sub
sub createFullDscrDlg()
dlg = CreateObject("roSGNode", "OverviewDialog")
dlg.Title = tr("Press 'Back' to Close")
dlg.width = 1290
dlg.palette = m.dlgPalette
dlg.overview = [m.dscr.text]
m.fullDscrDlg = dlg
m.top.getScene().dialog = dlg
border = createObject("roSGNode", "Poster")
border.uri = "pkg:/images/hd_focul_9.png"
border.blendColor = "#c9c9c9ff"
border.width = dlg.width + 6
border.height = dlg.height + 6
border.translation = [dlg.translation[0] - 3, dlg.translation[1] - 3]
border.visible = true
end sub
sub createDialogPallete()
m.dlgPalette = createObject("roSGNode", "RSGPalette")
m.dlgPalette.colors = {
DialogBackgroundColor: "0x262828FF",
DialogItemColor: "0x00EF00FF",
DialogTextColor: "0xb0b0b0FF",
DialogFocusColor: "0xcececeFF",
DialogFocusItemColor: "0x202020FF",
DialogSecondaryTextColor: "0xf8f8f8ff",
DialogSecondaryItemColor: "0xcc7ecc4D",
DialogInputFieldColor: "0x80FF8080",
DialogKeyboardColor: "0x80FF804D",
DialogFootprintColor: "0x80FF804D"
}
end sub
2022-05-14 02:35:50 +00:00
function onKeyEvent(key as string, press as boolean) as boolean
if key = "left"
if m.buttonGrp.isInFocusChain()
2022-07-19 02:28:06 +00:00
if m.top.selectedButtonIndex > 0
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
m.top.selectedButtonIndex = m.top.selectedButtonIndex - 1
return true
2022-07-19 02:28:06 +00:00
end if
if press
m.buttonGrp.setFocus(false)
m.sectionNavigation.setFocus(true)
return true
end if
return false
end if
if m.albums.isInFocusChain()
if m.albums.itemFocused mod 5 = 0
m.sectionNavigation.setFocus(true)
return true
end if
end if
end if
if m.buttonGrp.isInFocusChain()
if key = "down"
m.albums.infocus = true
2022-07-19 02:28:06 +00:00
return true
else if key = "right"
if m.sectionNavigation.escape = "right"
m.sectionNavigation.escape = ""
return true
end if
2022-07-19 02:28:06 +00:00
if m.top.pageContent.count() = 1 then return false
2022-07-19 02:28:06 +00:00
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
if m.top.selectedButtonIndex < m.buttonCount - 1 then m.top.selectedButtonIndex = m.top.selectedButtonIndex + 1
return true
end if
end if
if not press then return false
if key = "options"
if m.dscr.isTextEllipsized
createFullDscrDlg()
return true
end if
end if
2022-05-14 02:35:50 +00:00
return false
end function