2023-10-03 16:11:25 +00:00
|
|
|
import "pkg:/source/utils/misc.bs"
|
2023-11-25 13:25:31 +00:00
|
|
|
import "pkg:/source/constants/ImageSizes.bs"
|
2023-11-23 13:52:44 +00:00
|
|
|
|
|
|
|
' The maximum number of seconds we will show the loading spinner and delay the user from using the home view while the content loads
|
|
|
|
' We use this to wait for the rows to load so we can reset focus to the row/item once it loads
|
|
|
|
const MAX_TIME_HOME_LOADING_SPINNER_SHOWN = 1
|
2023-05-03 21:21:04 +00:00
|
|
|
|
2020-03-03 23:01:13 +00:00
|
|
|
sub init()
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.itemComponentName = "HomeItem"
|
|
|
|
' how many rows are visible on the screen
|
|
|
|
m.top.numRows = 2
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.rowFocusAnimationStyle = "fixedFocusWrap"
|
|
|
|
m.top.vertFocusAnimationStyle = "fixedFocus"
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.showRowLabel = [true]
|
|
|
|
m.top.rowLabelOffset = [0, 20]
|
|
|
|
m.top.showRowCounter = [true]
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections = {}
|
2023-09-30 21:36:16 +00:00
|
|
|
|
2023-11-23 13:52:44 +00:00
|
|
|
m.loadingTimer = createObject("roSGNode", "Timer")
|
|
|
|
m.loadingTimer.duration = MAX_TIME_HOME_LOADING_SPINNER_SHOWN
|
|
|
|
m.loadingTimer.observeField("fire", "stopLoadingSpinner")
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
updateSize()
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.setfocus(true)
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.observeField("rowItemSelected", "itemSelected")
|
2020-04-04 22:24:47 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' Load the Libraries from API via task
|
|
|
|
m.LoadLibrariesTask = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
m.LoadLibrariesTask.observeField("content", "onLibrariesLoaded")
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
' set up tesk nodes for other rows
|
2023-10-22 22:37:37 +00:00
|
|
|
m.LoadContinueWatchingTask = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
m.LoadContinueWatchingTask.itemsToLoad = "continue"
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
m.LoadNextUpTask.itemsToLoad = "nextUp"
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2021-12-18 06:31:28 +00:00
|
|
|
m.LoadOnNowTask = createObject("roSGNode", "LoadItemsTask")
|
2021-12-20 14:57:22 +00:00
|
|
|
m.LoadOnNowTask.itemsToLoad = "onNow"
|
2022-11-05 00:37:54 +00:00
|
|
|
|
|
|
|
m.LoadFavoritesTask = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
m.LoadFavoritesTask.itemsToLoad = "favorites"
|
2020-03-03 23:01:13 +00:00
|
|
|
end sub
|
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub loadLibraries()
|
2021-07-09 20:08:32 +00:00
|
|
|
m.LoadLibrariesTask.control = "RUN"
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2020-12-08 15:56:13 +00:00
|
|
|
|
2020-03-03 23:01:13 +00:00
|
|
|
sub updateSize()
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.translation = [111, 180]
|
2022-07-12 23:15:59 +00:00
|
|
|
itemHeight = 330
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
'Set width of Rows to cut off at edge of Safe Zone
|
|
|
|
m.top.itemSize = [1703, itemHeight]
|
2020-06-10 14:40:09 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' spacing between rows
|
2022-07-12 23:15:59 +00:00
|
|
|
m.top.itemSpacing = [0, 105]
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
' spacing between items in a row
|
|
|
|
m.top.rowItemSpacing = [20, 0]
|
2020-03-03 23:01:13 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.visible = true
|
2020-03-03 23:01:13 +00:00
|
|
|
end sub
|
|
|
|
|
2023-11-22 19:58:21 +00:00
|
|
|
' processUserSections: Loop through user's chosen home section settings and generate the content for each row
|
|
|
|
'
|
|
|
|
' @return {dynamic} content node filled with child nodes for each row
|
|
|
|
function processUserSections() as dynamic
|
|
|
|
m.homeSections = {}
|
2023-09-30 21:36:16 +00:00
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
loadedSections = 0
|
2023-11-22 19:58:21 +00:00
|
|
|
content = CreateObject("roSGNode", "ContentNode")
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
' Add sections in order based on user settings
|
|
|
|
for i = 0 to 6
|
2023-10-22 22:37:37 +00:00
|
|
|
sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()])
|
2023-11-22 17:14:35 +00:00
|
|
|
sectionLoaded = addHomeSection(content, sectionName)
|
2023-10-22 22:37:37 +00:00
|
|
|
|
|
|
|
' Count how many sections with data are loaded
|
|
|
|
if sectionLoaded then loadedSections++
|
|
|
|
|
|
|
|
' If 2 sections with data are loaded or we're at the end of the web client section data, consider the home view loaded
|
2023-11-22 19:58:21 +00:00
|
|
|
if not m.global.app_loaded
|
|
|
|
if loadedSections = 2 or i = 6
|
2023-10-22 22:37:37 +00:00
|
|
|
m.top.signalBeacon("AppLaunchComplete") ' Roku Performance monitoring
|
|
|
|
m.global.app_loaded = true
|
|
|
|
end if
|
|
|
|
end if
|
2023-09-30 21:36:16 +00:00
|
|
|
end for
|
|
|
|
|
|
|
|
' Favorites isn't an option on Web settings, so we must manually add it for now
|
2023-11-22 17:14:35 +00:00
|
|
|
addHomeSection(content, "favorites")
|
|
|
|
|
2023-11-22 19:58:21 +00:00
|
|
|
return content
|
|
|
|
end function
|
|
|
|
|
|
|
|
|
|
|
|
' onLibrariesLoaded: Handler when LoadLibrariesTask returns data
|
|
|
|
'
|
|
|
|
sub onLibrariesLoaded()
|
|
|
|
' save data for other functions
|
|
|
|
m.libraryData = m.LoadLibrariesTask.content
|
|
|
|
m.LoadLibrariesTask.unobserveField("content")
|
|
|
|
m.LoadLibrariesTask.content = []
|
|
|
|
|
|
|
|
content = processUserSections()
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
setRowItemSizes()
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
m.top.content = content
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' Removes a home section from the home rows
|
|
|
|
sub removeHomeSection(sectionType as string)
|
|
|
|
sectionName = LCase(sectionType)
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
removedSection = m.homeSections[sectionName]
|
2023-09-30 21:36:16 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
if not isValid(removedSection) then return
|
|
|
|
if not isValid(removedSection.index) then return
|
2023-10-22 22:37:37 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
for each section in m.homeSections
|
|
|
|
if m.homeSections[section].index > removedSection.index
|
|
|
|
m.homeSections[section].index--
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.Delete(sectionName)
|
|
|
|
m.top.content.removeChildIndex(removedSection.index)
|
|
|
|
|
|
|
|
setRowItemSizes()
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' setRowItemSizes: Loops through all home sections and sets the correct item sizes per row
|
|
|
|
'
|
|
|
|
sub setRowItemSizes()
|
|
|
|
newSizeArray = CreateObject("roArray", m.homeSections.count(), false)
|
|
|
|
|
|
|
|
for each section in m.homeSections
|
|
|
|
newSizeArray[m.homeSections[section].index] = m.homeSections[section].imagesize
|
|
|
|
end for
|
2023-09-30 21:36:16 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.top.rowItemSize = newSizeArray
|
2023-09-30 21:36:16 +00:00
|
|
|
end sub
|
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
' Adds a new home section to the home rows.
|
|
|
|
' Returns a boolean indicating whether the section was handled.
|
2023-11-22 17:14:35 +00:00
|
|
|
function addHomeSection(content as dynamic, sectionName as string) as boolean
|
2023-09-30 21:36:16 +00:00
|
|
|
' Poster size library items
|
|
|
|
if sectionName = "livetv"
|
2023-11-22 17:14:35 +00:00
|
|
|
createLiveTVRow(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Poster size library items
|
|
|
|
if sectionName = "smalllibrarytiles"
|
2023-11-22 17:14:35 +00:00
|
|
|
createLibraryRow(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Continue Watching items
|
|
|
|
if sectionName = "resume"
|
2023-11-22 17:14:35 +00:00
|
|
|
createContinueWatchingRow(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Next Up items
|
|
|
|
if sectionName = "nextup"
|
2023-11-22 17:14:35 +00:00
|
|
|
createNextUpRow(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Latest items in each library
|
|
|
|
if sectionName = "latestmedia"
|
2023-11-22 17:14:35 +00:00
|
|
|
createLatestInRows(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Favorite Items
|
|
|
|
if sectionName = "favorites"
|
2023-11-22 17:14:35 +00:00
|
|
|
createFavoritesRow(content)
|
2023-10-22 22:37:37 +00:00
|
|
|
return true
|
2023-09-30 21:36:16 +00:00
|
|
|
end if
|
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
return false
|
|
|
|
end function
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
' Create a row displaying the user's libraries
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createLibraryRow(content as dynamic)
|
2023-09-30 21:36:16 +00:00
|
|
|
' Ensure we have data
|
|
|
|
if not isValidAndNotEmpty(m.libraryData) then return
|
2023-01-10 00:38:50 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
mediaRow = content.CreateChild("HomeRow")
|
|
|
|
mediaRow.title = tr("My Media")
|
2023-01-10 00:38:50 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace("library", {
|
2023-11-23 13:52:44 +00:00
|
|
|
imageSize: imageSizes.WIDE_POSTER,
|
2023-11-22 17:14:35 +00:00
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
filteredMedia = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.MyMediaExcludes)
|
|
|
|
for each item in filteredMedia
|
|
|
|
mediaRow.appendChild(item)
|
|
|
|
end for
|
|
|
|
end sub
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' Create a row displaying latest items in each of the user's libraries
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createLatestInRows(content as dynamic)
|
2023-09-30 21:36:16 +00:00
|
|
|
' Ensure we have data
|
|
|
|
if not isValidAndNotEmpty(m.libraryData) then return
|
2022-11-05 00:37:54 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' create a "Latest In" row for each library
|
|
|
|
filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes)
|
|
|
|
for each lib in filteredLatest
|
|
|
|
if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program"
|
|
|
|
latestInRow = content.CreateChild("HomeRow")
|
|
|
|
latestInRow.title = tr("Latest in") + " " + lib.name + " >"
|
2021-07-09 20:08:32 +00:00
|
|
|
|
2023-11-23 13:52:44 +00:00
|
|
|
imagesize = imageSizes.WIDE_POSTER
|
2023-11-22 17:14:35 +00:00
|
|
|
|
|
|
|
if LCase(lib.collectionType) = "movies"
|
2023-11-23 13:52:44 +00:00
|
|
|
imagesize = imageSizes.MOVIE_POSTER
|
2023-11-22 17:14:35 +00:00
|
|
|
else if LCase(lib.collectionType) = "music"
|
2023-11-23 13:52:44 +00:00
|
|
|
imagesize = imageSizes.MUSIC_ALBUM
|
2023-11-22 17:14:35 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
m.homeSections.AddReplace("latestin" + LCase(lib.name).Replace(" ", ""), {
|
|
|
|
imageSize: imagesize,
|
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
loadLatest = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
loadLatest.itemsToLoad = "latest"
|
|
|
|
loadLatest.itemId = lib.id
|
|
|
|
|
|
|
|
metadata = { "title": lib.name }
|
|
|
|
metadata.Append({ "contentType": lib.json.CollectionType })
|
|
|
|
loadLatest.metadata = metadata
|
|
|
|
|
|
|
|
loadLatest.observeField("content", "updateLatestItems")
|
|
|
|
loadLatest.control = "RUN"
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' Create a row displaying the live tv now on section
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createLiveTVRow(content as dynamic)
|
2023-09-30 21:36:16 +00:00
|
|
|
contentRow = content.CreateChild("HomeRow")
|
|
|
|
contentRow.title = tr("On Now")
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace("livetv", {
|
2023-11-23 13:52:44 +00:00
|
|
|
imageSize: imageSizes.WIDE_POSTER,
|
2023-11-22 17:14:35 +00:00
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
m.LoadOnNowTask.observeField("content", "updateOnNowItems")
|
|
|
|
m.LoadOnNowTask.control = "RUN"
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' Create a row displaying items the user can continue watching
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createContinueWatchingRow(content as dynamic)
|
2023-10-22 22:37:37 +00:00
|
|
|
continueWatchingRow = content.CreateChild("HomeRow")
|
|
|
|
continueWatchingRow.title = tr("Continue Watching")
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace("resume", {
|
2023-11-23 13:52:44 +00:00
|
|
|
imageSize: imageSizes.WIDE_POSTER,
|
2023-11-22 17:14:35 +00:00
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2023-04-13 19:41:11 +00:00
|
|
|
|
|
|
|
' Load the Continue Watching Data
|
2023-10-22 22:37:37 +00:00
|
|
|
m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems")
|
|
|
|
m.LoadContinueWatchingTask.control = "RUN"
|
2023-09-30 21:36:16 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
' Create a row displaying next episodes up to watch
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createNextUpRow(content as dynamic)
|
2023-09-30 21:36:16 +00:00
|
|
|
nextUpRow = content.CreateChild("HomeRow")
|
|
|
|
nextUpRow.title = tr("Next Up >")
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace("nextup", {
|
2023-11-23 13:52:44 +00:00
|
|
|
imageSize: imageSizes.WIDE_POSTER,
|
2023-11-22 17:14:35 +00:00
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2023-09-30 21:36:16 +00:00
|
|
|
|
|
|
|
' Load the Next Up Data
|
|
|
|
m.LoadNextUpTask.observeField("content", "updateNextUpItems")
|
|
|
|
m.LoadNextUpTask.control = "RUN"
|
|
|
|
end sub
|
|
|
|
|
|
|
|
' Create a row displaying items from the user's favorites list
|
2023-11-22 17:14:35 +00:00
|
|
|
sub createFavoritesRow(content as dynamic)
|
2023-09-30 21:36:16 +00:00
|
|
|
favoritesRow = content.CreateChild("HomeRow")
|
|
|
|
favoritesRow.title = tr("Favorites")
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace("favorites", {
|
2023-11-23 13:52:44 +00:00
|
|
|
imageSize: imageSizes.WIDE_POSTER,
|
2023-11-22 17:14:35 +00:00
|
|
|
index: m.homeSections.count()
|
|
|
|
})
|
2023-04-13 19:41:11 +00:00
|
|
|
|
|
|
|
' Load the Favorites Data
|
|
|
|
m.LoadFavoritesTask.observeField("content", "updateFavoritesItems")
|
|
|
|
m.LoadFavoritesTask.control = "RUN"
|
2022-05-24 16:23:42 +00:00
|
|
|
end sub
|
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' Update home row data
|
2021-06-26 10:18:09 +00:00
|
|
|
sub updateHomeRows()
|
2023-11-23 13:52:44 +00:00
|
|
|
startMediaLoadingSpinner()
|
2023-11-25 13:25:31 +00:00
|
|
|
m.loadingTimer.control = "start"
|
2023-11-22 19:58:21 +00:00
|
|
|
content = processUserSections()
|
|
|
|
setRowItemSizes()
|
|
|
|
m.top.content = content
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2020-03-24 00:45:40 +00:00
|
|
|
|
2022-11-05 00:37:54 +00:00
|
|
|
sub updateFavoritesItems()
|
|
|
|
itemData = m.LoadFavoritesTask.content
|
|
|
|
m.LoadFavoritesTask.unobserveField("content")
|
|
|
|
m.LoadFavoritesTask.content = []
|
|
|
|
|
|
|
|
if itemData = invalid then return
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
rowIndex = m.homeSections.favorites.index
|
2022-11-05 00:37:54 +00:00
|
|
|
|
|
|
|
if itemData.count() < 1
|
2023-09-30 21:36:16 +00:00
|
|
|
removeHomeSection("favorites")
|
|
|
|
return
|
2022-11-05 00:37:54 +00:00
|
|
|
else
|
|
|
|
' remake row using the new data
|
|
|
|
row = CreateObject("roSGNode", "HomeRow")
|
|
|
|
row.title = tr("Favorites")
|
|
|
|
|
|
|
|
for each item in itemData
|
|
|
|
usePoster = true
|
|
|
|
|
|
|
|
if lcase(item.type) = "episode" or lcase(item.type) = "audio" or lcase(item.type) = "musicartist"
|
|
|
|
usePoster = false
|
|
|
|
end if
|
|
|
|
|
|
|
|
item.usePoster = usePoster
|
|
|
|
item.imageWidth = row.imageWidth
|
|
|
|
row.appendChild(item)
|
|
|
|
end for
|
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' replace the old row
|
|
|
|
m.top.content.replaceChild(row, rowIndex)
|
2023-11-22 23:23:04 +00:00
|
|
|
' Set focus on previously focused item
|
|
|
|
setFocusToPreviousFocusedItem()
|
2023-09-30 21:36:16 +00:00
|
|
|
|
2022-11-05 00:37:54 +00:00
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
sub updateContinueWatchingItems()
|
|
|
|
itemData = m.LoadContinueWatchingTask.content
|
|
|
|
m.LoadContinueWatchingTask.unobserveField("content")
|
|
|
|
m.LoadContinueWatchingTask.content = []
|
2020-03-24 07:37:45 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData = invalid then return
|
2022-05-24 16:23:42 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.count() < 1
|
2023-09-30 21:36:16 +00:00
|
|
|
removeHomeSection("resume")
|
|
|
|
return
|
|
|
|
end if
|
2022-12-10 02:53:00 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' remake row using the new data
|
|
|
|
row = CreateObject("roSGNode", "HomeRow")
|
|
|
|
row.title = tr("Continue Watching")
|
2020-03-24 07:37:45 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
for each item in itemData
|
|
|
|
if isValid(item.json) and isValid(item.json.UserData) and isValid(item.json.UserData.PlayedPercentage)
|
|
|
|
item.PlayedPercentage = item.json.UserData.PlayedPercentage
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
2023-04-13 19:41:11 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
item.usePoster = row.usePoster
|
|
|
|
item.imageWidth = row.imageWidth
|
|
|
|
row.appendChild(item)
|
|
|
|
end for
|
|
|
|
|
|
|
|
' replace the old row
|
2023-11-22 17:14:35 +00:00
|
|
|
m.top.content.replaceChild(row, m.homeSections.resume.index)
|
2023-11-22 23:23:04 +00:00
|
|
|
' Set focus on previously focused item
|
|
|
|
setFocusToPreviousFocusedItem()
|
2022-05-24 16:23:42 +00:00
|
|
|
end sub
|
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
sub updateNextUpItems()
|
|
|
|
itemData = m.LoadNextUpTask.content
|
|
|
|
m.LoadNextUpTask.unobserveField("content")
|
|
|
|
m.LoadNextUpTask.content = []
|
2023-11-23 13:52:44 +00:00
|
|
|
m.LoadNextUpTask.control = "STOP"
|
2022-05-24 16:23:42 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData = invalid then return
|
2022-05-24 16:23:42 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.count() < 1
|
2023-09-30 21:36:16 +00:00
|
|
|
removeHomeSection("nextup")
|
|
|
|
return
|
2022-07-12 23:15:59 +00:00
|
|
|
else
|
|
|
|
' remake row using the new data
|
|
|
|
row = CreateObject("roSGNode", "HomeRow")
|
|
|
|
row.title = tr("Next Up") + " >"
|
|
|
|
for each item in itemData
|
|
|
|
item.usePoster = row.usePoster
|
|
|
|
item.imageWidth = row.imageWidth
|
|
|
|
row.appendChild(item)
|
2022-05-24 16:23:42 +00:00
|
|
|
end for
|
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' replace the old row
|
2023-11-22 17:14:35 +00:00
|
|
|
m.top.content.replaceChild(row, m.homeSections.nextup.index)
|
2023-11-22 23:23:04 +00:00
|
|
|
' Set focus on previously focused item
|
|
|
|
setFocusToPreviousFocusedItem()
|
2020-03-24 07:37:45 +00:00
|
|
|
end if
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2021-07-09 20:08:32 +00:00
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
' Iterate over user's libraries and update data for each Latest In section
|
|
|
|
sub updateLatestInRows()
|
|
|
|
' Ensure we have data
|
|
|
|
if not isValidAndNotEmpty(m.libraryData) then return
|
2023-01-26 22:45:20 +00:00
|
|
|
|
2023-10-22 22:37:37 +00:00
|
|
|
' Load new data for each library
|
2023-06-01 12:43:27 +00:00
|
|
|
filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes)
|
2023-04-13 19:41:11 +00:00
|
|
|
for each lib in filteredLatest
|
2023-10-22 22:37:37 +00:00
|
|
|
if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program"
|
2023-04-13 19:41:11 +00:00
|
|
|
loadLatest = createObject("roSGNode", "LoadItemsTask")
|
|
|
|
loadLatest.itemsToLoad = "latest"
|
|
|
|
loadLatest.itemId = lib.id
|
|
|
|
|
2023-11-11 04:34:19 +00:00
|
|
|
metadata = {
|
|
|
|
"title": lib.name,
|
|
|
|
"contentType": lib.json.CollectionType
|
|
|
|
}
|
2023-04-13 19:41:11 +00:00
|
|
|
|
2023-11-11 04:34:19 +00:00
|
|
|
loadLatest.metadata = metadata
|
2023-04-13 19:41:11 +00:00
|
|
|
loadLatest.observeField("content", "updateLatestItems")
|
|
|
|
loadLatest.control = "RUN"
|
|
|
|
end if
|
|
|
|
end for
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub updateLatestItems(msg)
|
2021-07-09 20:08:32 +00:00
|
|
|
itemData = msg.GetData()
|
2020-03-24 07:37:45 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
node = msg.getRoSGNode()
|
|
|
|
node.unobserveField("content")
|
2022-07-12 23:15:59 +00:00
|
|
|
node.content = []
|
|
|
|
|
|
|
|
if itemData = invalid then return
|
2020-03-24 07:37:45 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
sectionName = "latestin" + LCase(node.metadata.title).Replace(" ", "")
|
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.count() < 1
|
2023-09-30 21:36:16 +00:00
|
|
|
removeHomeSection(sectionName)
|
|
|
|
return
|
2022-07-12 23:15:59 +00:00
|
|
|
else
|
|
|
|
' remake row using new data
|
|
|
|
row = CreateObject("roSGNode", "HomeRow")
|
|
|
|
row.title = tr("Latest in") + " " + node.metadata.title + " >"
|
|
|
|
row.usePoster = true
|
2023-11-25 13:25:31 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
' Handle specific types with different item widths
|
|
|
|
if node.metadata.contentType = "movies"
|
2023-11-23 13:52:44 +00:00
|
|
|
row.imageWidth = imageSizes.MOVIE_POSTER[0]
|
|
|
|
itemSize = imageSizes.MOVIE_POSTER
|
2022-07-12 23:15:59 +00:00
|
|
|
else if node.metadata.contentType = "music"
|
2023-11-23 13:52:44 +00:00
|
|
|
row.imageWidth = imageSizes.MUSIC_ALBUM[0]
|
|
|
|
itemSize = imageSizes.MUSIC_ALBUM
|
2022-07-12 23:15:59 +00:00
|
|
|
else
|
2023-11-23 13:52:44 +00:00
|
|
|
row.imageWidth = imageSizes.WIDE_POSTER[0]
|
|
|
|
itemSize = imageSizes.WIDE_POSTER
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
2022-07-12 23:15:59 +00:00
|
|
|
|
|
|
|
for each item in itemData
|
|
|
|
item.usePoster = row.usePoster
|
|
|
|
item.imageWidth = row.imageWidth
|
|
|
|
row.appendChild(item)
|
2021-07-09 20:08:32 +00:00
|
|
|
end for
|
2022-07-12 23:15:59 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
if isValid(m.homeSections[sectionName])
|
|
|
|
rowIndex = m.homeSections[sectionName].index
|
2023-11-11 04:34:19 +00:00
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
' Replace the old row
|
|
|
|
if isValid(rowIndex)
|
|
|
|
m.top.content.replaceChild(row, rowIndex)
|
2023-11-22 23:23:04 +00:00
|
|
|
|
|
|
|
' Set focus on previously focused item
|
|
|
|
setFocusToPreviousFocusedItem()
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
return
|
|
|
|
end if
|
2023-11-11 04:34:19 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
' Determine highest index of a Lastest In section so we can append the new section after it
|
|
|
|
highestLatestHomeSectionIndex = 0
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
for each section in m.homeSections
|
2023-11-11 04:34:19 +00:00
|
|
|
if LCase(Left(section, 6)) = "latest"
|
2023-11-22 17:14:35 +00:00
|
|
|
if m.homeSections[section].index > highestLatestHomeSectionIndex
|
|
|
|
highestLatestHomeSectionIndex = m.homeSections[section].index
|
2023-11-11 04:34:19 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
' We have data for a section that doesn't currently exist
|
|
|
|
rowIndex = highestLatestHomeSectionIndex + 1
|
|
|
|
|
|
|
|
' Advance all the indexes greater than or equal than our new row
|
2023-11-22 17:14:35 +00:00
|
|
|
for each section in m.homeSections
|
|
|
|
if m.homeSections[section].index >= rowIndex
|
|
|
|
m.homeSections[section].index++
|
2023-11-11 04:34:19 +00:00
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
2023-11-22 17:14:35 +00:00
|
|
|
m.homeSections.AddReplace(sectionName, {
|
|
|
|
imageSize: itemSize,
|
|
|
|
index: rowIndex
|
|
|
|
})
|
2023-11-11 04:34:19 +00:00
|
|
|
|
|
|
|
m.top.content.insertChild(row, rowIndex)
|
2023-11-22 17:14:35 +00:00
|
|
|
|
|
|
|
' We've inserted a new row, we must set the row sizes again to ensure they're correct
|
|
|
|
setRowItemSizes()
|
2023-11-11 04:34:19 +00:00
|
|
|
|
|
|
|
return
|
2020-03-24 07:37:45 +00:00
|
|
|
end if
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2023-11-22 23:23:04 +00:00
|
|
|
' setFocusToPreviousFocusedItem: Sets the cursor focus to the row and item previously selected
|
|
|
|
'
|
|
|
|
sub setFocusToPreviousFocusedItem()
|
2023-11-25 13:25:31 +00:00
|
|
|
if not isValidAndNotEmpty(m.selectedRowItem) then return
|
|
|
|
|
|
|
|
' Set focus to row if it exists
|
|
|
|
itemRow = m.top.content.getChild(m.selectedRowItem[0])
|
|
|
|
if isValid(itemRow)
|
|
|
|
m.top.jumpToItem = m.selectedRowItem[0]
|
|
|
|
|
|
|
|
' Set focus to column if it exists
|
|
|
|
itemColumn = itemRow.getChild(m.selectedRowItem[1])
|
|
|
|
if isValid(itemColumn)
|
|
|
|
m.top.jumpToRowItem = [m.selectedRowItem[0], m.selectedRowItem[1]]
|
|
|
|
m.loadingTimer.control = "stop"
|
|
|
|
stopLoadingSpinner()
|
2023-11-22 23:23:04 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2021-12-17 06:18:19 +00:00
|
|
|
sub updateOnNowItems()
|
|
|
|
itemData = m.LoadOnNowTask.content
|
|
|
|
m.LoadOnNowTask.unobserveField("content")
|
2022-07-12 23:15:59 +00:00
|
|
|
m.LoadOnNowTask.content = []
|
2021-12-17 06:18:19 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData = invalid then return
|
2021-12-17 06:18:19 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
if itemData.count() < 1
|
2023-09-30 21:36:16 +00:00
|
|
|
removeHomeSection("livetv")
|
|
|
|
return
|
2022-07-12 23:15:59 +00:00
|
|
|
else
|
|
|
|
' remake row using the new data
|
|
|
|
row = CreateObject("roSGNode", "HomeRow")
|
|
|
|
row.title = tr("On Now")
|
2023-11-23 13:52:44 +00:00
|
|
|
row.imageWidth = imageSizes.WIDE_POSTER[0]
|
2022-07-12 23:15:59 +00:00
|
|
|
for each item in itemData
|
2023-11-12 14:21:05 +00:00
|
|
|
row.usePoster = false
|
2023-11-23 13:52:44 +00:00
|
|
|
|
2023-11-12 14:21:05 +00:00
|
|
|
if (not isValid(item.thumbnailURL) or item.thumbnailURL = "") and isValid(item.json) and isValid(item.json.imageURL)
|
|
|
|
item.thumbnailURL = item.json.imageURL
|
|
|
|
row.usePoster = true
|
2023-11-23 13:52:44 +00:00
|
|
|
row.imageWidth = imageSizes.MOVIE_POSTER[0]
|
|
|
|
|
|
|
|
m.homeSections.livetv.imageSize = imageSizes.MOVIE_POSTER
|
2023-11-12 14:21:05 +00:00
|
|
|
end if
|
2023-11-23 13:52:44 +00:00
|
|
|
|
2022-07-12 23:15:59 +00:00
|
|
|
item.usePoster = row.usePoster
|
|
|
|
item.imageWidth = row.imageWidth
|
|
|
|
row.appendChild(item)
|
2022-05-24 16:23:42 +00:00
|
|
|
end for
|
2022-07-12 23:15:59 +00:00
|
|
|
|
2023-09-30 21:36:16 +00:00
|
|
|
' replace the old row
|
2023-11-22 17:14:35 +00:00
|
|
|
m.top.content.replaceChild(row, m.homeSections.livetv.index)
|
2023-11-22 23:23:04 +00:00
|
|
|
' Set focus on previously focused item
|
|
|
|
setFocusToPreviousFocusedItem()
|
2021-12-17 06:18:19 +00:00
|
|
|
|
2023-11-23 13:52:44 +00:00
|
|
|
' We may now have different poster sizes. Reset the row item sizes
|
|
|
|
setRowItemSizes()
|
|
|
|
|
2020-03-24 07:37:45 +00:00
|
|
|
end if
|
2020-03-24 07:31:36 +00:00
|
|
|
end sub
|
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub itemSelected()
|
2023-11-23 13:52:44 +00:00
|
|
|
m.selectedRowItem = m.top.rowItemSelected
|
2023-11-22 23:23:04 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.selectedItem = m.top.content.getChild(m.top.rowItemSelected[0]).getChild(m.top.rowItemSelected[1])
|
2023-05-07 01:26:02 +00:00
|
|
|
|
|
|
|
'Prevent the selected item event from double firing
|
|
|
|
m.top.selectedItem = invalid
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2020-03-12 18:33:45 +00:00
|
|
|
|
2020-04-04 22:24:47 +00:00
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
2021-07-09 20:08:32 +00:00
|
|
|
if press
|
|
|
|
if key = "play"
|
2023-09-16 21:18:03 +00:00
|
|
|
print "play was pressed from homerow"
|
2021-07-09 20:08:32 +00:00
|
|
|
itemToPlay = m.top.content.getChild(m.top.rowItemFocused[0]).getChild(m.top.rowItemFocused[1])
|
2023-09-16 21:18:03 +00:00
|
|
|
if isValid(itemToPlay)
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.quickPlayNode = itemToPlay
|
|
|
|
end if
|
2023-09-16 21:18:03 +00:00
|
|
|
return true
|
|
|
|
else if key = "replay"
|
2022-06-25 21:29:24 +00:00
|
|
|
m.top.jumpToRowItem = [m.top.rowItemFocused[0], 0]
|
2023-09-16 21:18:03 +00:00
|
|
|
return true
|
2022-06-25 21:29:24 +00:00
|
|
|
end if
|
2020-12-08 08:39:58 +00:00
|
|
|
end if
|
2023-09-16 21:18:03 +00:00
|
|
|
return false
|
2020-04-04 22:24:47 +00:00
|
|
|
end function
|
2020-12-06 04:59:32 +00:00
|
|
|
|
|
|
|
function filterNodeArray(nodeArray as object, nodeKey as string, excludeArray as object) as object
|
2021-07-09 20:08:32 +00:00
|
|
|
if excludeArray.IsEmpty() then return nodeArray
|
|
|
|
|
|
|
|
newNodeArray = []
|
|
|
|
for each node in nodeArray
|
|
|
|
excludeThisNode = false
|
|
|
|
for each exclude in excludeArray
|
|
|
|
if node[nodeKey] = exclude
|
|
|
|
excludeThisNode = true
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
if excludeThisNode = false
|
|
|
|
newNodeArray.Push(node)
|
|
|
|
end if
|
2020-12-06 04:59:32 +00:00
|
|
|
end for
|
2021-07-09 20:08:32 +00:00
|
|
|
return newNodeArray
|
2022-05-30 12:57:40 +00:00
|
|
|
end function
|