Create expected & processed counts. Hook short circuit to their values

Code by cewert
This commit is contained in:
1hitsong 2023-12-04 12:18:59 -05:00
parent 2832799c82
commit 7e7ac107af

View File

@ -72,13 +72,33 @@ end sub
' processUserSections: Loop through user's chosen home section settings and generate the content for each row ' processUserSections: Loop through user's chosen home section settings and generate the content for each row
' '
sub processUserSections() sub processUserSections()
m.expectedRowCount = 0 m.expectedRowCount = 1 ' the favorites row is hardcoded to always show atm
loadedSections = 0 m.processedRowCount = 0
' Add sections in order based on user settings ' calculate expected row count by processing homesections
for i = 0 to 6 for i = 0 to 6
sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()]) sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()])
sectionLoaded = addHomeSection(sectionName) if sectionName = "latestmedia"
' expect 1 row per filtered media library
m.filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes)
for each latestLibrary in m.filteredLatest
if latestLibrary.collectionType <> "boxsets" and latestLibrary.collectionType <> "livetv" and latestLibrary.json.CollectionType <> "Program"
m.expectedRowCount++
end if
end for
else if sectionName <> "none"
m.expectedRowCount++
end if
end for
' Add home sections in order based on user settings
loadedSections = 0
for i = 0 to 6
sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()])
sectionLoaded = false
if sectionName <> "none"
sectionLoaded = addHomeSection(sectionName)
end if
' Count how many sections with data are loaded ' Count how many sections with data are loaded
if sectionLoaded then loadedSections++ if sectionLoaded then loadedSections++
@ -173,11 +193,10 @@ sub setRowItemSize()
for i = 0 to homeSections.count() - 1 for i = 0 to homeSections.count() - 1
newSizeArray[i] = isValid(homeSections[i].cursorSize) ? homeSections[i].cursorSize : homeRowItemSizes.WIDE_POSTER newSizeArray[i] = isValid(homeSections[i].cursorSize) ? homeSections[i].cursorSize : homeRowItemSizes.WIDE_POSTER
end for end for
m.top.rowItemSize = newSizeArray m.top.rowItemSize = newSizeArray
' If we have the expected number of content rows, stop the loading timer and run the complete function ' If we have processed the expected number of content rows, stop the loading timer and run the complete function
if m.expectedRowCount = homeSections.count() if m.expectedRowCount = m.processedRowCount
m.loadingTimer.control = "stop" m.loadingTimer.control = "stop"
loadingTimerComplete() loadingTimerComplete()
end if end if
@ -233,17 +252,19 @@ function addHomeSection(sectionType as string) as boolean
return true return true
end if end if
' This section type isn't supported.
' Count it as processed since we aren't going to do anything else with it
m.processedRowCount++
return false return false
end function end function
' createLibraryRow: Creates a row displaying the user's libraries ' createLibraryRow: Creates a row displaying the user's libraries
' '
sub createLibraryRow() sub createLibraryRow()
m.processedRowCount++
' Ensure we have data ' Ensure we have data
if not isValidAndNotEmpty(m.libraryData) then return if not isValidAndNotEmpty(m.libraryData) then return
m.expectedRowCount++
sectionName = tr("My Media") sectionName = tr("My Media")
row = CreateObject("roSGNode", "HomeRow") row = CreateObject("roSGNode", "HomeRow")
@ -275,15 +296,12 @@ sub createLatestInRows()
if not isValidAndNotEmpty(m.libraryData) then return if not isValidAndNotEmpty(m.libraryData) then return
' create a "Latest In" row for each library ' create a "Latest In" row for each library
filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes) for each lib in m.filteredLatest
for each lib in filteredLatest
if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program" if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program"
loadLatest = createObject("roSGNode", "LoadItemsTask") loadLatest = createObject("roSGNode", "LoadItemsTask")
loadLatest.itemsToLoad = "latest" loadLatest.itemsToLoad = "latest"
loadLatest.itemId = lib.id loadLatest.itemId = lib.id
m.expectedRowCount++
metadata = { "title": lib.name } metadata = { "title": lib.name }
metadata.Append({ "contentType": lib.json.CollectionType }) metadata.Append({ "contentType": lib.json.CollectionType })
loadLatest.metadata = metadata loadLatest.metadata = metadata
@ -346,7 +364,6 @@ end function
' createLiveTVRow: Creates a row displaying the live tv now on section ' createLiveTVRow: Creates a row displaying the live tv now on section
' '
sub createLiveTVRow() sub createLiveTVRow()
m.expectedRowCount++
m.LoadOnNowTask.observeField("content", "updateOnNowItems") m.LoadOnNowTask.observeField("content", "updateOnNowItems")
m.LoadOnNowTask.control = "RUN" m.LoadOnNowTask.control = "RUN"
end sub end sub
@ -354,7 +371,6 @@ end sub
' createContinueWatchingRow: Creates a row displaying items the user can continue watching ' createContinueWatchingRow: Creates a row displaying items the user can continue watching
' '
sub createContinueWatchingRow() sub createContinueWatchingRow()
m.expectedRowCount++
' Load the Continue Watching Data ' Load the Continue Watching Data
m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems") m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems")
m.LoadContinueWatchingTask.control = "RUN" m.LoadContinueWatchingTask.control = "RUN"
@ -363,7 +379,6 @@ end sub
' createNextUpRow: Creates a row displaying next episodes up to watch ' createNextUpRow: Creates a row displaying next episodes up to watch
' '
sub createNextUpRow() sub createNextUpRow()
m.expectedRowCount++
sectionName = tr("Next Up") + ">" sectionName = tr("Next Up") + ">"
if not sectionExists(sectionName) if not sectionExists(sectionName)
@ -381,7 +396,6 @@ end sub
' createFavoritesRow: Creates a row displaying items from the user's favorites list ' createFavoritesRow: Creates a row displaying items from the user's favorites list
' '
sub createFavoritesRow() sub createFavoritesRow()
m.expectedRowCount++
' Load the Favorites Data ' Load the Favorites Data
m.LoadFavoritesTask.observeField("content", "updateFavoritesItems") m.LoadFavoritesTask.observeField("content", "updateFavoritesItems")
m.LoadFavoritesTask.control = "RUN" m.LoadFavoritesTask.control = "RUN"
@ -398,19 +412,14 @@ end sub
' updateFavoritesItems: Processes LoadFavoritesTask content. Removes, Creates, or Updates favorites row as needed ' updateFavoritesItems: Processes LoadFavoritesTask content. Removes, Creates, or Updates favorites row as needed
' '
sub updateFavoritesItems() sub updateFavoritesItems()
m.processedRowCount++
itemData = m.LoadFavoritesTask.content itemData = m.LoadFavoritesTask.content
m.LoadFavoritesTask.unobserveField("content") m.LoadFavoritesTask.unobserveField("content")
m.LoadFavoritesTask.content = [] m.LoadFavoritesTask.content = []
if itemData = invalid
m.expectedRowCount--
return
end if
sectionName = tr("Favorites") sectionName = tr("Favorites")
if itemData.count() < 1 if not isValidAndNotEmpty(itemData)
m.expectedRowCount--
removeHomeSection(sectionName) removeHomeSection(sectionName)
return return
end if end if
@ -446,19 +455,14 @@ end sub
' updateContinueWatchingItems: Processes LoadContinueWatchingTask content. Removes, Creates, or Updates continue watching row as needed ' updateContinueWatchingItems: Processes LoadContinueWatchingTask content. Removes, Creates, or Updates continue watching row as needed
' '
sub updateContinueWatchingItems() sub updateContinueWatchingItems()
m.processedRowCount++
itemData = m.LoadContinueWatchingTask.content itemData = m.LoadContinueWatchingTask.content
m.LoadContinueWatchingTask.unobserveField("content") m.LoadContinueWatchingTask.unobserveField("content")
m.LoadContinueWatchingTask.content = [] m.LoadContinueWatchingTask.content = []
if not isValid(itemData)
m.expectedRowCount--
return
end if
sectionName = tr("Continue Watching") sectionName = tr("Continue Watching")
if itemData.count() < 1 if not isValidAndNotEmpty(itemData)
m.expectedRowCount--
removeHomeSection(sectionName) removeHomeSection(sectionName)
return return
end if end if
@ -496,20 +500,15 @@ end sub
' updateNextUpItems: Processes LoadNextUpTask content. Removes, Creates, or Updates next up row as needed ' updateNextUpItems: Processes LoadNextUpTask content. Removes, Creates, or Updates next up row as needed
' '
sub updateNextUpItems() sub updateNextUpItems()
m.processedRowCount++
itemData = m.LoadNextUpTask.content itemData = m.LoadNextUpTask.content
m.LoadNextUpTask.unobserveField("content") m.LoadNextUpTask.unobserveField("content")
m.LoadNextUpTask.content = [] m.LoadNextUpTask.content = []
m.LoadNextUpTask.control = "STOP" m.LoadNextUpTask.control = "STOP"
if itemData = invalid
m.expectedRowCount--
return
end if
sectionName = tr("Next Up") + " >" sectionName = tr("Next Up") + " >"
if itemData.count() < 1 if not isValidAndNotEmpty(itemData)
m.expectedRowCount--
removeHomeSection(sectionName) removeHomeSection(sectionName)
return return
end if end if
@ -542,21 +541,16 @@ end sub
' '
' @param {dynamic} msg - LoadItemsTask ' @param {dynamic} msg - LoadItemsTask
sub updateLatestItems(msg) sub updateLatestItems(msg)
m.processedRowCount++
itemData = msg.GetData() itemData = msg.GetData()
node = msg.getRoSGNode() node = msg.getRoSGNode()
node.unobserveField("content") node.unobserveField("content")
node.content = [] node.content = []
if itemData = invalid
m.expectedRowCount--
return
end if
sectionName = tr("Latest in") + " " + node.metadata.title + " >" sectionName = tr("Latest in") + " " + node.metadata.title + " >"
if itemData.count() < 1 if not isValidAndNotEmpty(itemData)
m.expectedRowCount--
removeHomeSection(sectionName) removeHomeSection(sectionName)
return return
end if end if
@ -598,19 +592,14 @@ end sub
' updateOnNowItems: Processes LoadOnNowTask content. Removes, Creates, or Updates latest in on now row as needed ' updateOnNowItems: Processes LoadOnNowTask content. Removes, Creates, or Updates latest in on now row as needed
' '
sub updateOnNowItems() sub updateOnNowItems()
m.processedRowCount++
itemData = m.LoadOnNowTask.content itemData = m.LoadOnNowTask.content
m.LoadOnNowTask.unobserveField("content") m.LoadOnNowTask.unobserveField("content")
m.LoadOnNowTask.content = [] m.LoadOnNowTask.content = []
if not isValid(itemData)
m.expectedRowCount--
return
end if
sectionName = tr("On Now") sectionName = tr("On Now")
if itemData.count() < 1 if not isValidAndNotEmpty(itemData)
m.expectedRowCount--
removeHomeSection(sectionName) removeHomeSection(sectionName)
return return
end if end if