2023-10-03 16:11:25 +00:00
|
|
|
import "pkg:/source/api/Image.bs"
|
|
|
|
import "pkg:/source/api/baserequest.bs"
|
|
|
|
import "pkg:/source/utils/config.bs"
|
|
|
|
import "pkg:/source/utils/misc.bs"
|
2023-10-03 16:27:07 +00:00
|
|
|
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
2020-12-04 08:17:16 +00:00
|
|
|
|
2023-05-03 21:21:04 +00:00
|
|
|
sub init()
|
|
|
|
m.log = log.Logger("HomeItem")
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText = m.top.findNode("itemText")
|
|
|
|
m.itemPoster = m.top.findNode("itemPoster")
|
2022-12-10 02:53:00 +00:00
|
|
|
m.itemProgress = m.top.findNode("progress")
|
|
|
|
m.itemProgressBackground = m.top.findNode("progressBackground")
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemIcon = m.top.findNode("itemIcon")
|
|
|
|
m.itemTextExtra = m.top.findNode("itemTextExtra")
|
|
|
|
m.itemPoster.observeField("loadStatus", "onPosterLoadStatusChanged")
|
2022-12-10 22:41:22 +00:00
|
|
|
m.unplayedCount = m.top.findNode("unplayedCount")
|
|
|
|
m.unplayedEpisodeCount = m.top.findNode("unplayedEpisodeCount")
|
2023-04-23 16:36:44 +00:00
|
|
|
m.playedIndicator = m.top.findNode("playedIndicator")
|
2020-12-04 08:17:16 +00:00
|
|
|
|
2022-12-10 02:53:00 +00:00
|
|
|
m.showProgressBarAnimation = m.top.findNode("showProgressBar")
|
|
|
|
m.showProgressBarField = m.top.findNode("showProgressBarField")
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' Randomize the background colors
|
2024-01-13 01:55:48 +00:00
|
|
|
backdropColor = "#00a4db" ' set default in case global var is invalid
|
|
|
|
localGlobal = m.global
|
|
|
|
|
|
|
|
if isValid(localGlobal) and isValid(localGlobal.constants) and isValid(localGlobal.constants.poster_bg_pallet)
|
|
|
|
posterBackgrounds = localGlobal.constants.poster_bg_pallet
|
|
|
|
backdropColor = posterBackgrounds[rnd(posterBackgrounds.count()) - 1]
|
|
|
|
end if
|
|
|
|
|
|
|
|
' update the backdrop node
|
2021-07-09 20:08:32 +00:00
|
|
|
m.backdrop = m.top.findNode("backdrop")
|
2024-01-13 01:55:48 +00:00
|
|
|
m.backdrop.color = backdropColor
|
2020-12-04 08:17:16 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
|
2020-03-12 18:33:45 +00:00
|
|
|
sub itemContentChanged()
|
2023-11-25 13:25:31 +00:00
|
|
|
m.unplayedCount.visible = false
|
2021-07-09 20:08:32 +00:00
|
|
|
itemData = m.top.itemContent
|
|
|
|
if itemData = invalid then return
|
2023-09-23 15:16:15 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
itemData.Title = itemData.name ' Temporarily required while we move from "HomeItem" to "JFContentItem"
|
2022-07-12 23:15:59 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemPoster.width = itemData.imageWidth
|
|
|
|
m.itemText.maxWidth = itemData.imageWidth
|
|
|
|
m.itemTextExtra.width = itemData.imageWidth
|
|
|
|
m.itemTextExtra.visible = true
|
2023-11-14 15:54:19 +00:00
|
|
|
m.itemTextExtra.text = ""
|
2020-03-05 09:11:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.backdrop.width = itemData.imageWidth
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.iconUrl)
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemIcon.uri = itemData.iconUrl
|
2020-03-12 18:33:45 +00:00
|
|
|
end if
|
|
|
|
|
2023-04-25 00:58:43 +00:00
|
|
|
if itemData.isWatched
|
2023-04-23 16:36:44 +00:00
|
|
|
m.playedIndicator.visible = true
|
|
|
|
m.unplayedCount.visible = false
|
|
|
|
else
|
|
|
|
m.playedIndicator.visible = false
|
|
|
|
|
|
|
|
if LCase(itemData.type) = "series"
|
2023-06-01 12:43:27 +00:00
|
|
|
if m.global.session.user.settings["ui.tvshows.disableUnwatchedEpisodeCount"] = false
|
2023-04-23 16:36:44 +00:00
|
|
|
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
|
2023-02-04 23:16:36 +00:00
|
|
|
end if
|
2022-12-15 01:08:25 +00:00
|
|
|
end if
|
2022-12-10 22:41:22 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' Format the Data based on the type of Home Data
|
|
|
|
if itemData.type = "CollectionFolder" or itemData.type = "UserView" or itemData.type = "Channel"
|
2023-11-23 01:55:41 +00:00
|
|
|
m.itemText.font.size = 35
|
|
|
|
m.itemText.height = 64
|
|
|
|
m.itemText.horizAlign = "center"
|
|
|
|
m.itemText.vertAlign = "bottom"
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText.text = itemData.name
|
2022-07-12 23:15:59 +00:00
|
|
|
m.itemPoster.uri = itemData.widePosterURL
|
2021-07-09 20:08:32 +00:00
|
|
|
return
|
2020-03-12 18:33:45 +00:00
|
|
|
end if
|
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.type = "UserView"
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemPoster.width = "96"
|
|
|
|
m.itemPoster.height = "96"
|
|
|
|
m.itemPoster.translation = "[192, 88]"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemPoster.uri = itemData.widePosterURL
|
|
|
|
return
|
2020-03-05 09:11:45 +00:00
|
|
|
end if
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2023-04-25 00:58:43 +00:00
|
|
|
playedIndicatorLeftPosition = m.itemPoster.width - 60
|
|
|
|
m.playedIndicator.translation = [playedIndicatorLeftPosition, 0]
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText.height = 34
|
|
|
|
m.itemText.font.size = 25
|
|
|
|
m.itemText.horizAlign = "left"
|
2022-07-12 23:15:59 +00:00
|
|
|
m.itemText.vertAlign = "bottom"
|
|
|
|
m.itemTextExtra.visible = true
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemTextExtra.font.size = 22
|
|
|
|
|
2021-12-18 06:43:28 +00:00
|
|
|
' "Program" is from clicking on an "On Now" item on the Home Screen
|
2021-12-17 06:18:19 +00:00
|
|
|
if itemData.type = "Program"
|
|
|
|
m.itemText.Text = itemData.json.name
|
2023-01-19 01:52:11 +00:00
|
|
|
m.itemTextExtra.Text = itemData.json.ChannelName
|
2023-11-12 14:21:05 +00:00
|
|
|
if itemData.usePoster
|
|
|
|
m.itemPoster.uri = itemData.thumbnailURL
|
2023-01-19 01:52:11 +00:00
|
|
|
else
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.json.ChannelId)
|
2021-12-17 06:18:19 +00:00
|
|
|
end if
|
2023-11-12 14:45:13 +00:00
|
|
|
m.itemPoster.loadDisplayMode = "scaleToFill"
|
2021-12-17 06:18:19 +00:00
|
|
|
|
2021-12-20 14:57:22 +00:00
|
|
|
' Set Episode title if available
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.EpisodeTitle)
|
2021-12-17 06:18:19 +00:00
|
|
|
m.itemTextExtra.text = itemData.json.EpisodeTitle
|
|
|
|
end if
|
|
|
|
|
|
|
|
return
|
|
|
|
end if
|
2021-07-09 20:08:32 +00:00
|
|
|
|
|
|
|
if itemData.type = "Episode"
|
|
|
|
m.itemText.text = itemData.json.SeriesName
|
|
|
|
|
2022-12-10 02:53:00 +00:00
|
|
|
if itemData.PlayedPercentage > 0
|
|
|
|
drawProgressBar(itemData)
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if itemData.usePoster = true
|
2022-05-24 16:23:42 +00:00
|
|
|
m.itemPoster.uri = itemData.widePosterURL
|
2022-07-12 23:15:59 +00:00
|
|
|
else
|
|
|
|
m.itemPoster.uri = itemData.thumbnailURL
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Set Series and Episode Number for Extra Text
|
|
|
|
extraPrefix = ""
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.ParentIndexNumber)
|
2021-07-09 20:08:32 +00:00
|
|
|
extraPrefix = "S" + StrI(itemData.json.ParentIndexNumber).trim()
|
|
|
|
end if
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.IndexNumber)
|
2021-07-09 20:08:32 +00:00
|
|
|
extraPrefix = extraPrefix + "E" + StrI(itemData.json.IndexNumber).trim()
|
|
|
|
end if
|
|
|
|
if extraPrefix.len() > 0
|
|
|
|
extraPrefix = extraPrefix + " - "
|
|
|
|
end if
|
|
|
|
|
|
|
|
m.itemTextExtra.text = extraPrefix + itemData.name
|
|
|
|
return
|
|
|
|
end if
|
2020-05-13 19:36:38 +00:00
|
|
|
|
2023-09-23 15:16:15 +00:00
|
|
|
if itemData.type = "Movie" or itemData.type = "MusicVideo"
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText.text = itemData.name
|
|
|
|
|
2022-12-10 02:53:00 +00:00
|
|
|
if itemData.PlayedPercentage > 0
|
|
|
|
drawProgressBar(itemData)
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' Use best image, but fallback to secondary if it's empty
|
|
|
|
if (itemData.imageWidth = 180 and itemData.posterURL <> "") or itemData.thumbnailURL = ""
|
|
|
|
m.itemPoster.uri = itemData.posterURL
|
|
|
|
else
|
|
|
|
m.itemPoster.uri = itemData.thumbnailURL
|
|
|
|
end if
|
|
|
|
|
|
|
|
' Set Release Year and Age Rating for Extra Text
|
|
|
|
textExtra = ""
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.ProductionYear)
|
2021-07-09 20:08:32 +00:00
|
|
|
textExtra = StrI(itemData.json.ProductionYear).trim()
|
|
|
|
end if
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.OfficialRating)
|
2021-07-09 20:08:32 +00:00
|
|
|
if textExtra <> ""
|
|
|
|
textExtra = textExtra + " - " + itemData.json.OfficialRating
|
|
|
|
else
|
|
|
|
textExtra = itemData.json.OfficialRating
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
m.itemTextExtra.text = textExtra
|
|
|
|
|
|
|
|
return
|
2020-05-13 19:36:38 +00:00
|
|
|
end if
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if itemData.type = "Video"
|
|
|
|
m.itemText.text = itemData.name
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2022-12-10 02:53:00 +00:00
|
|
|
if itemData.PlayedPercentage > 0
|
|
|
|
drawProgressBar(itemData)
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if itemData.imageWidth = 180
|
|
|
|
m.itemPoster.uri = itemData.posterURL
|
|
|
|
else
|
|
|
|
m.itemPoster.uri = itemData.thumbnailURL
|
|
|
|
end if
|
2023-11-14 15:54:19 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
return
|
2020-03-12 18:33:45 +00:00
|
|
|
end if
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2023-04-05 22:18:33 +00:00
|
|
|
if itemData.type = "BoxSet"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemPoster.uri = itemData.posterURL
|
|
|
|
|
|
|
|
' Set small text to number of items in the collection
|
|
|
|
if isValid(itemData.json) and isValid(itemData.json.ChildCount)
|
|
|
|
m.itemTextExtra.text = StrI(itemData.json.ChildCount).trim() + " item"
|
|
|
|
if itemData.json.ChildCount > 1
|
|
|
|
m.itemTextExtra.text += "s"
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if itemData.type = "Series"
|
2022-07-12 23:15:59 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText.text = itemData.name
|
2022-07-12 23:15:59 +00:00
|
|
|
|
|
|
|
if itemData.usePoster = true
|
|
|
|
if itemData.imageWidth = 180
|
|
|
|
m.itemPoster.uri = itemData.posterURL
|
|
|
|
else
|
|
|
|
m.itemPoster.uri = itemData.widePosterURL
|
|
|
|
end if
|
|
|
|
else
|
|
|
|
m.itemPoster.uri = itemData.thumbnailURL
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
2022-07-12 23:15:59 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
textExtra = ""
|
2023-03-09 19:35:29 +00:00
|
|
|
if isValid(itemData.json.ProductionYear)
|
2021-07-09 20:08:32 +00:00
|
|
|
textExtra = StrI(itemData.json.ProductionYear).trim()
|
|
|
|
end if
|
|
|
|
|
|
|
|
' Set Years Run for Extra Text
|
|
|
|
if itemData.json.Status = "Continuing"
|
|
|
|
textExtra = textExtra + " - Present"
|
2023-03-09 19:35:29 +00:00
|
|
|
else if itemData.json.Status = "Ended" and isValid(itemData.json.EndDate)
|
2021-07-09 20:08:32 +00:00
|
|
|
textExtra = textExtra + " - " + LEFT(itemData.json.EndDate, 4)
|
|
|
|
end if
|
|
|
|
m.itemTextExtra.text = textExtra
|
|
|
|
|
|
|
|
return
|
2019-10-13 08:59:51 +00:00
|
|
|
end if
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.type = "MusicAlbum"
|
2021-07-09 20:08:32 +00:00
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemTextExtra.text = itemData.json.AlbumArtist
|
2022-07-12 23:15:59 +00:00
|
|
|
m.itemPoster.uri = itemData.posterURL
|
2021-07-09 20:08:32 +00:00
|
|
|
return
|
2020-03-12 18:33:45 +00:00
|
|
|
end if
|
|
|
|
|
2022-11-05 00:37:54 +00:00
|
|
|
if itemData.type = "MusicArtist"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemTextExtra.text = itemData.json.AlbumArtist
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
if itemData.type = "Audio"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemTextExtra.text = itemData.json.AlbumArtist
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
if itemData.type = "TvChannel"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemTextExtra.text = itemData.json.AlbumArtist
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
if itemData.type = "Season"
|
|
|
|
m.itemText.text = itemData.json.SeriesName
|
|
|
|
m.itemTextExtra.text = itemData.name
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2023-11-13 14:16:00 +00:00
|
|
|
if itemData.type = "Photo"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
|
|
|
|
' subtext
|
|
|
|
if isValidAndNotEmpty(itemData.json)
|
2023-11-13 22:57:58 +00:00
|
|
|
if isValid(itemData.json.ProductionYear)
|
|
|
|
m.itemTextExtra.text = itemData.json.ProductionYear.ToStr().trim()
|
2023-11-13 14:16:00 +00:00
|
|
|
end if
|
|
|
|
if isValidAndNotEmpty(itemData.json.Album)
|
|
|
|
if m.itemTextExtra.text = ""
|
|
|
|
m.itemTextExtra.text = tr("Album") + ": " + itemData.json.Album.trim()
|
|
|
|
else
|
|
|
|
m.itemTextExtra.text = m.itemTextExtra.text + " - " + tr("Album") + ": " + itemData.json.Album.trim()
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
if itemData.type = "PhotoAlbum"
|
|
|
|
m.itemText.text = itemData.name
|
|
|
|
m.itemPoster.uri = ImageURL(itemData.id)
|
|
|
|
|
2023-11-14 15:54:19 +00:00
|
|
|
' subtext
|
|
|
|
if isValid(itemData.json.ChildCount)
|
|
|
|
m.itemTextExtra.text = itemData.json.ChildCount.ToStr().trim() + " items"
|
|
|
|
end if
|
|
|
|
|
2023-11-13 14:16:00 +00:00
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2023-05-03 21:21:04 +00:00
|
|
|
m.log.warn("Unhandled Home Item Type", itemData.type)
|
2020-03-12 18:33:45 +00:00
|
|
|
end sub
|
2020-05-13 15:50:20 +00:00
|
|
|
|
2022-12-10 02:53:00 +00:00
|
|
|
'
|
|
|
|
' Draws and animates item progress bar
|
|
|
|
sub drawProgressBar(itemData)
|
|
|
|
m.itemProgressBackground.width = itemData.imageWidth
|
|
|
|
m.itemProgressBackground.visible = true
|
|
|
|
m.showProgressBarField.keyValue = [0, m.itemPoster.width * (itemData.PlayedPercentage / 100)]
|
|
|
|
m.showProgressBarAnimation.control = "Start"
|
|
|
|
end sub
|
|
|
|
|
2020-05-13 15:50:20 +00:00
|
|
|
'
|
|
|
|
' Enable title scrolling based on item Focus
|
|
|
|
sub focusChanged()
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if m.top.itemHasFocus = true
|
|
|
|
m.itemText.repeatCount = -1
|
|
|
|
else
|
|
|
|
m.itemText.repeatCount = 0
|
|
|
|
end if
|
2020-05-13 15:50:20 +00:00
|
|
|
|
|
|
|
end sub
|
2020-12-02 21:33:59 +00:00
|
|
|
|
|
|
|
'Hide backdrop and icon when poster loaded
|
|
|
|
sub onPosterLoadStatusChanged()
|
2022-07-12 23:15:59 +00:00
|
|
|
if m.itemPoster.loadStatus = "ready" and m.itemPoster.uri <> ""
|
|
|
|
m.backdrop.visible = false
|
|
|
|
m.itemIcon.visible = false
|
|
|
|
else
|
|
|
|
m.backdrop.visible = true
|
|
|
|
m.itemIcon.visible = true
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
2022-05-30 12:57:40 +00:00
|
|
|
end sub
|