Make home screen use user settings

This commit is contained in:
cewert 2020-12-05 23:59:32 -05:00
parent 04e6aa3345
commit b95faed3fc
4 changed files with 69 additions and 30 deletions

View File

@ -6,6 +6,7 @@
</children> </children>
<interface> <interface>
<field id="selectedItem" alias="homeRows.selectedItem" /> <field id="selectedItem" alias="homeRows.selectedItem" />
<field id="userConfig" alias="homeRows.userConfig" />
<field id="timeLastRefresh" type="integer" /> <field id="timeLastRefresh" type="integer" />
<function name="refresh" /> <function name="refresh" />
</interface> </interface>

View File

@ -49,29 +49,45 @@ sub updateSize()
end sub end sub
sub onLibrariesLoaded() sub onLibrariesLoaded()
' save data for other functions
m.libraryData = m.LoadLibrariesTask.content m.libraryData = m.LoadLibrariesTask.content
m.sizeArray = [[464, 311]]
m.top.rowItemSize = m.sizeArray
m.LoadLibrariesTask.unobserveField("content") m.LoadLibrariesTask.unobserveField("content")
' create My Media, Continue Watching, and Next Up rows
content = CreateObject("roSGNode", "ContentNode")
mediaRow = content.CreateChild("HomeRow")
mediaRow.title = tr("My Media")
continueRow = content.CreateChild("HomeRow")
continueRow.title = tr("Continue Watching")
nextUpRow = content.CreateChild("HomeRow")
nextUpRow.title = tr("Next Up >")
sizeArray = [
[464, 311], ' My Media
[464, 311], ' Continue Watching
[464, 311] ' Next Up
]
' validate library data
if (m.libraryData <> invalid and m.libraryData.count() > 0) then if (m.libraryData <> invalid and m.libraryData.count() > 0) then
userConfig = m.top.userConfig
'Add the Libraries Row ' populate My Media row
m.data = CreateObject("roSGNode", "ContentNode") filteredMedia = filterNodeArray(m.libraryData, "id", userConfig.MyMediaExcludes)
row = m.data.CreateChild("HomeRow") for each item in filteredMedia
row.title = tr("My Media") mediaRow.appendChild(item)
end for
for each item in m.libraryData ' create a "Latest In" row for each library
row.appendChild(item) filteredLatest = filterNodeArray(m.libraryData, "id", userConfig.LatestItemsExcludes)
for each lib in filteredLatest
if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" then
latestInRow = content.CreateChild("HomeRow")
latestInRow.title = tr("Latest in") + " " + lib.name + " >"
sizeArray.Push([464, 331])
end if
end for end for
end if end if
m.top.rowItemSize = sizeArray
m.top.content = content
' Load the Continue Watching Data ' Load the Continue Watching Data
m.top.content = m.data
m.LoadContinueTask.observeField("content", "updateContinueItems") m.LoadContinueTask.observeField("content", "updateContinueItems")
m.LoadContinueTask.control = "RUN" m.LoadContinueTask.control = "RUN"
end sub end sub
@ -148,12 +164,13 @@ function updateNextUpItems()
end for end for
if nextUpRowIndex = invalid then if nextUpRowIndex = invalid then
' insert new row under "Continue Watching if it exists" ' insert new row under "Continue Watching"
tmpRow = homeRows.getChild(1) continueRowIndex = getRowIndex("Continue Watching")
if tmpRow <> invalid and tmpRow.title = tr("Continue Watching") then if continueRowIndex <> invalid then
updateSizeArray(itemSize, 2) updateSizeArray(itemSize, continueRowIndex + 1)
homeRows.insertChild(row, 2) homeRows.insertChild(row, continueRowIndex + 1)
else else
' insert it under My Media
updateSizeArray(itemSize, 1) updateSizeArray(itemSize, 1)
homeRows.insertChild(row, 1) homeRows.insertChild(row, 1)
end if end if
@ -163,9 +180,11 @@ function updateNextUpItems()
end if end if
end if end if
' Update "Latest in" for all libraries ' create task nodes for "Latest In" rows
for each lib in m.libraryData userConfig = m.top.userConfig
if lib.collectionType <> "livetv" then filteredLatest = filterNodeArray(m.libraryData, "id", userConfig.LatestItemsExcludes)
for each lib in filteredLatest
if lib.collectionType <> "livetv" and lib.collectionType <> "boxsets" then
loadLatest = createObject("roSGNode", "LoadItemsTask") loadLatest = createObject("roSGNode", "LoadItemsTask")
loadLatest.itemsToLoad = "latest" loadLatest.itemsToLoad = "latest"
loadLatest.itemId = lib.id loadLatest.itemId = lib.id
@ -224,11 +243,11 @@ function updateLatestItems(msg)
if rowIndex = invalid then if rowIndex = invalid then
' append new row ' append new row
' todo: insert row based on user settings
updateSizeArray(itemSize) updateSizeArray(itemSize)
homeRows.appendChild(row) homeRows.appendChild(row)
else else
' replace the old row ' replace the old row
updateSizeArray(itemSize, rowIndex, "replace")
homeRows.replaceChild(row, rowIndex) homeRows.replaceChild(row, rowIndex)
end if end if
end if end if
@ -253,7 +272,7 @@ function getRowIndex(rowTitle as string)
return rowIndex return rowIndex
end function end function
sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "add") sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "insert")
sizeArray = m.top.rowItemSize sizeArray = m.top.rowItemSize
' append by default ' append by default
if rowIndex = invalid then if rowIndex = invalid then
@ -263,16 +282,15 @@ sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "add")
newSizeArray = [] newSizeArray = []
for i = 0 to sizeArray.count() for i = 0 to sizeArray.count()
if rowIndex = i then if rowIndex = i then
if action = "add" then if action = "replace" then
' insert new row size newSizeArray.Push(rowItemSize)
else if action = "insert" then
newSizeArray.Push(rowItemSize) newSizeArray.Push(rowItemSize)
if sizeArray[i] <> invalid then if sizeArray[i] <> invalid then
' copy row size
newSizeArray.Push(sizeArray[i]) newSizeArray.Push(sizeArray[i])
end if end if
end if end if
else if sizeArray[i] <> invalid then else if sizeArray[i] <> invalid then
' copy row size
newSizeArray.Push(sizeArray[i]) newSizeArray.Push(sizeArray[i])
end if end if
end for end for
@ -290,3 +308,21 @@ end function
function onKeyEvent(key as string, press as boolean) as boolean function onKeyEvent(key as string, press as boolean) as boolean
return false return false
end function end function
function filterNodeArray(nodeArray as object, nodeKey as string, excludeArray as object) as object
if excludeArray.IsEmpty() then return nodeArray
newNodeArray = []
for each node in nodeArray
excludeThisNode = false
for each exclude in excludeArray
if node[nodeKey] = exclude then
excludeThisNode = true
end if
end for
if excludeThisNode = false then
newNodeArray.Push(node)
end if
end for
return newNodeArray
end function

View File

@ -2,6 +2,7 @@
<component name="HomeRows" extends="RowList"> <component name="HomeRows" extends="RowList">
<interface> <interface>
<field id="selectedItem" type="node" alwaysNotify="true" /> <field id="selectedItem" type="node" alwaysNotify="true" />
<field id="userConfig" type="assocarray" />
<function name="updateHomeRows" /> <function name="updateHomeRows" />
</interface> </interface>
<script type="text/brightscript" uri="HomeRows.brs"/> <script type="text/brightscript" uri="HomeRows.brs"/>

View File

@ -35,6 +35,7 @@ sub Main()
m.overhang.currentUser = m.user.Name m.overhang.currentUser = m.user.Name
m.overhang.showOptions = true m.overhang.showOptions = true
group = CreateHomeGroup() group = CreateHomeGroup()
group.userConfig = m.user.configuration
m.scene.appendChild(group) m.scene.appendChild(group)
m.scene.observeField("backPressed", m.port) m.scene.observeField("backPressed", m.port)