jf-roku/components/ListPoster.brs

117 lines
3.6 KiB
Plaintext
Raw Normal View History

import "pkg:/source/utils/config.brs"
import "pkg:/source/utils/misc.brs"
2019-05-03 12:48:59 +00:00
sub init()
m.title = m.top.findNode("title")
m.staticTitle = m.top.findNode("staticTitle")
m.series = m.top.findNode("Series")
2019-05-03 12:48:59 +00:00
m.poster = m.top.findNode("poster")
2022-12-10 21:41:40 +00:00
m.unplayedCount = m.top.findNode("unplayedCount")
m.unplayedEpisodeCount = m.top.findNode("unplayedEpisodeCount")
2021-07-09 20:08:32 +00:00
2019-05-03 12:48:59 +00:00
m.backdrop = m.top.findNode("backdrop")
2021-07-09 20:08:32 +00:00
' Randmomise the background colors
posterBackgrounds = m.global.constants.poster_bg_pallet
m.backdrop.color = posterBackgrounds[rnd(posterBackgrounds.count()) - 1]
2019-05-03 12:48:59 +00:00
updateSize()
end sub
sub updateSize()
image = invalid
if isValid(m.top.itemContent) and isValid(m.top.itemContent.image)
2021-07-09 20:08:32 +00:00
image = m.top.itemContent.image
end if
if image = invalid
2021-07-09 20:08:32 +00:00
m.backdrop.visible = true
else
2021-07-09 20:08:32 +00:00
m.backdrop.visible = false
end if
2019-05-03 12:48:59 +00:00
' TODO - abstract this in case the parent doesnt have itemSize
maxSize = m.top.getParent().itemSize
' Always reserve the bottom for the Poster Title
m.title.maxWidth = maxSize[0]
m.title.height = 40
m.title.translation = [0, int(maxSize[1]) - m.title.height + 5]
m.staticTitle.width = maxSize[0]
m.staticTitle.height = m.title.height
m.staticTitle.translation = m.title.translation
m.series.maxWidth = maxSize[0]
2019-05-03 12:48:59 +00:00
m.poster.width = int(maxSize[0]) - 4
m.poster.height = int(maxSize[1]) - m.title.height 'Set poster height to available space
2019-05-03 12:48:59 +00:00
m.backdrop.width = m.poster.width
m.backdrop.height = m.poster.height
end sub
sub itemContentChanged() as void
2021-07-09 20:08:32 +00:00
m.poster = m.top.findNode("poster")
itemData = m.top.itemContent
m.title.text = itemData.title
if get_user_setting("ui.tvshows.disableUnwatchedEpisodeCount", "false") = "false"
if isValid(itemData.json.UserData) and isValid(itemData.json.UserData.UnplayedItemCount)
if itemData.json.UserData.UnplayedItemCount > 0
m.unplayedCount.visible = true
m.unplayedEpisodeCount.text = itemData.json.UserData.UnplayedItemCount
end if
2022-12-10 22:41:22 +00:00
end if
2022-12-10 21:41:40 +00:00
end if
if itemData.json.lookup("Type") = "Episode" and isValid(itemData.json.IndexNumber)
2021-07-09 20:08:32 +00:00
m.title.text = StrI(itemData.json.IndexNumber) + ". " + m.title.text
m.series.text = itemData.json.Series
m.series.visible = true
else if itemData.json.lookup("Type") = "MusicAlbum"
m.title.font = "font:SmallestSystemFont"
m.staticTitle.font = "font:SmallestSystemFont"
else
m.series.visible = false
2021-07-09 20:08:32 +00:00
end if
m.staticTitle.text = m.title.text
imageUrl = itemData.posterURL
if get_user_setting("ui.tvshows.blurunwatched") = "true"
if itemData.json.lookup("Type") = "Episode" and isValid(itemData.json.userdata)
if not itemData.json.userdata.played
imageUrl = imageUrl + "&blur=15"
end if
end if
end if
m.poster.uri = imageUrl
2019-05-03 12:48:59 +00:00
2021-07-09 20:08:32 +00:00
updateSize()
end sub
'
' Enable title scrolling based on item Focus
sub focusChanged()
2021-07-09 20:08:32 +00:00
if m.top.itemHasFocus = true
m.title.repeatCount = -1
m.series.repeatCount = -1
2021-07-09 20:08:32 +00:00
m.staticTitle.visible = false
m.title.visible = true
' text to speech for accessibility
if m.global.device.isAudioGuideEnabled = true
txt2Speech = CreateObject("roTextToSpeech")
txt2Speech.Flush()
txt2Speech.Say(m.title.text)
end if
2021-07-09 20:08:32 +00:00
else
m.title.repeatCount = 0
m.series.repeatCount = 0
2021-07-09 20:08:32 +00:00
m.staticTitle.visible = true
m.title.visible = false
end if
end sub