jf-roku/components/music/AlbumGrid.brs

70 lines
1.8 KiB
Plaintext
Raw Normal View History

import "pkg:/source/utils/misc.brs"
2022-07-19 02:28:06 +00:00
sub init()
getData()
end sub
function getData()
' If we have no album data, return a blank node
if m.top.MusicArtistAlbumData = invalid
data = CreateObject("roSGNode", "ContentNode")
return data
end if
albumData = m.top.MusicArtistAlbumData
data = CreateObject("roSGNode", "ContentNode")
for each album in albumData.items
gridAlbum = CreateObject("roSGNode", "ContentNode")
2022-09-27 01:26:17 +00:00
if not isValid(album.posterURL) or album.posterURL = ""
album.posterURL = "pkg:/images/icons/album.png"
end if
2022-07-19 02:28:06 +00:00
gridAlbum.shortdescriptionline1 = album.title
gridAlbum.HDGRIDPOSTERURL = album.posterURL
gridAlbum.hdposterurl = album.posterURL
2022-09-27 01:26:17 +00:00
gridAlbum.SDGRIDPOSTERURL = album.posterURL
2022-07-19 02:28:06 +00:00
gridAlbum.sdposterurl = album.posterURL
data.appendChild(gridAlbum)
end for
m.top.content = data
return data
end function
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
if key = "up"
if m.top.itemFocused <= 4
2022-09-03 20:06:57 +00:00
m.top.escape = key
return true
end if
else if key = "left"
if m.top.itemFocused mod 5 = 0
m.top.escape = key
return true
end if
else if key = "right"
if m.top.itemFocused + 1 mod 5 = 0
m.top.escape = key
2022-07-19 02:28:06 +00:00
return true
end if
2022-09-27 01:26:17 +00:00
else if key = "down"
totalCount = m.top.MusicArtistAlbumData.items.count()
totalRows = div_ceiling(totalCount, 5)
currentRow = div_ceiling(m.top.itemFocused + 1, 5)
if currentRow = totalRows
m.top.escape = key
return true
end if
2022-07-19 02:28:06 +00:00
end if
return false
end function