This commit is contained in:
Charles Ewert 2020-03-25 00:20:52 -04:00
parent e0fa6481ad
commit c062bd0597

View File

@ -18,6 +18,11 @@ sub init()
m.LoadLibrariesTask = createObject("roSGNode", "LoadItemsTask")
m.LoadLibrariesTask.observeField("content", "onLibrariesLoaded")
m.LoadLibrariesTask.control = "RUN"
' set up tesk nodes for other rows
m.LoadContinueTask = createObject("roSGNode", "LoadItemsTask")
m.LoadContinueTask.itemsToLoad = "continue"
m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask")
m.LoadNextUpTask.itemsToLoad = "nextUp"
end sub
sub updateSize()
@ -45,7 +50,7 @@ sub onLibrariesLoaded()
m.LoadLibrariesTask.unobserveField("content")
if(m.libraryData <> invalid and m.libraryData.count() > 0) then
if (m.libraryData <> invalid and m.libraryData.count() > 0) then
'Add the Libraries Row
m.data = CreateObject("roSGNode", "ContentNode")
@ -60,111 +65,11 @@ sub onLibrariesLoaded()
' Load the Continue Watching Data
m.top.content = m.data
m.LoadContinueTask = createObject("roSGNode", "LoadItemsTask")
m.LoadContinueTask.itemsToLoad = "continue"
m.LoadContinueTask.observeField("content", "onContinueItemsLoaded")
m.LoadContinueTask.observeField("content", "updateContinueItems")
m.LoadContinueTask.control = "RUN"
end sub
sub onContinueItemsLoaded()
m.LoadContinueTask.unobserveField("content")
itemData = m.LoadContinueTask.content
if(itemData <> invalid and itemData.count() > 0) then
'Add the Row
row = m.top.content.CreateChild("HomeRow")
row.title = "Continue Watching"
m.sizeArray.Push([464, 331])
m.top.rowItemSize = m.sizeArray
for each item in itemData
row.appendChild(item)
end for
end if
' Load Next Up
m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask")
m.LoadNextUpTask.itemsToLoad = "nextUp"
m.LoadNextUpTask.observeField("content", "onNextUpItemsLoaded")
m.LoadNextUpTask.control = "RUN"
end sub
sub onNextUpItemsLoaded()
m.LoadNextUpTask.unobserveField("content")
itemData = m.LoadNextUpTask.content
if(itemData <> invalid and itemData.count() > 0) then
'Add the Next Up Row
row = m.top.content.CreateChild("HomeRow")
row.title = "Next Up >"
m.sizeArray.Push([464, 331])
m.top.rowItemSize = m.sizeArray
for each item in itemData
row.appendChild(item)
end for
end if
' Now load latest in all libraries
for each lib in m.libraryData
if lib.collectionType <> "livetv" then
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", "onLatestLoaded")
loadLatest.control = "RUN"
end if
end for
end sub
function onLatestLoaded(msg)
itemData = msg.GetData()
data = msg.getField()
node = msg.getRoSGNode()
node.unobserveField("content")
if(itemData <> invalid and itemData.count() > 0) then
'Add the Latest Row
row = m.top.content.CreateChild("HomeRow")
row.title = "Latest in " + node.metadata.title + " >"
row.usePoster = true
' Handle specific types with different item widths
if node.metadata.contentType = "movies" then
row.imageWidth = 180
m.sizeArray.Push([188, 331])
else if node.metadata.contentType = "music" then
row.imageWidth = 261
m.sizeArray.Push([261, 331])
else
row.imageWidth = 464
m.sizeArray.Push([464, 331])
end if
m.top.rowItemSize = m.sizeArray
for each item in itemData
row.appendChild(item)
end for
end if
end function
function updateHomeRows()
m.LoadContinueTask.observeField("content", "updateContinueItems")
m.LoadContinueTask.control = "RUN"
@ -177,15 +82,7 @@ function updateContinueItems()
if itemData = invalid then return false
homeRows = m.top.content
continueRowIndex = invalid
for i = 1 to homeRows.getChildCount() - 1
' skip row 0 since it's always "My Media"
tmpRow = homeRows.getChild(i)
if tmpRow.title = "Continue Watching" then
continueRowIndex = i
exit for
end if
end for
continueRowIndex = getRowIndex("Continue Watching")
if itemData.count() < 1 then
if continueRowIndex <> invalid then
@ -223,15 +120,7 @@ function updateNextUpItems()
if itemData = invalid then return false
homeRows = m.top.content
nextUpRowIndex = invalid
for i = 1 to homeRows.getChildCount() - 1
' skip row 0 since it's always "My Media"
tmpRow = homeRows.getChild(i)
if tmpRow.title = "Next Up >" then
nextUpRowIndex = i
exit for
end if
end for
nextUpRowIndex = getRowIndex("Next Up >")
if itemData.count() < 1 then
if nextUpRowIndex <> invalid then
@ -251,7 +140,7 @@ function updateNextUpItems()
if nextUpRowIndex = invalid then
' insert new row under "Continue Watching if it exists"
tmpRow = homeRows.getChild(1)
if tmpRow.title = "Continue Watching" then
if tmpRow <> invalid and tmpRow.title = "Continue Watching" then
updateSizeArray(itemSize, 2)
homeRows.insertChild(row, 2)
else
@ -291,15 +180,7 @@ function updateLatestItems(msg)
if itemData = invalid then return false
homeRows = m.top.content
rowIndex = invalid
for i = 1 to homeRows.getChildCount() - 1
' skip row 0 since it's always "My Media"
tmpRow = homeRows.getChild(i)
if tmpRow.title = "Latest in " + node.metadata.title + " >" then
rowIndex = i
exit for
end if
end for
rowIndex = getRowIndex("Latest in " + node.metadata.title + " >")
if itemData.count() < 1 then
' remove row
@ -340,6 +221,19 @@ function updateLatestItems(msg)
end if
end function
function getRowIndex(rowTitle as string)
rowIndex = invalid
for i = 1 to m.top.content.getChildCount() - 1
' skip row 0 since it's always "My Media"
tmpRow = m.top.content.getChild(i)
if tmpRow.title = rowTitle then
rowIndex = i
exit for
end if
end for
return rowIndex
end function
sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "add")
sizeArray = m.top.rowItemSize
' append by default