Skip to content

Commit

Permalink
Create expected & processed counts. Hook short circuit to their values
Browse files Browse the repository at this point in the history
Code by cewert
  • Loading branch information
1hitsong committed Dec 4, 2023
1 parent 2832799 commit 7e7ac10
Showing 1 changed file with 41 additions and 52 deletions.
93 changes: 41 additions & 52 deletions components/home/HomeRows.bs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,33 @@ end sub
' processUserSections: Loop through user's chosen home section settings and generate the content for each row
'
sub processUserSections()
m.expectedRowCount = 0
loadedSections = 0
m.expectedRowCount = 1 ' the favorites row is hardcoded to always show atm
m.processedRowCount = 0

' calculate expected row count by processing homesections
for i = 0 to 6
sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()])
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 sections in order based on user settings
' 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 = addHomeSection(sectionName)
sectionLoaded = false
if sectionName <> "none"
sectionLoaded = addHomeSection(sectionName)
end if

' Count how many sections with data are loaded
if sectionLoaded then loadedSections++
Expand Down Expand Up @@ -173,11 +193,10 @@ sub setRowItemSize()
for i = 0 to homeSections.count() - 1
newSizeArray[i] = isValid(homeSections[i].cursorSize) ? homeSections[i].cursorSize : homeRowItemSizes.WIDE_POSTER
end for

m.top.rowItemSize = newSizeArray

' If we have the expected number of content rows, stop the loading timer and run the complete function
if m.expectedRowCount = homeSections.count()
' If we have processed the expected number of content rows, stop the loading timer and run the complete function
if m.expectedRowCount = m.processedRowCount
m.loadingTimer.control = "stop"
loadingTimerComplete()
end if
Expand Down Expand Up @@ -233,17 +252,19 @@ function addHomeSection(sectionType as string) as boolean
return true
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
end function

' createLibraryRow: Creates a row displaying the user's libraries
'
sub createLibraryRow()
m.processedRowCount++
' Ensure we have data
if not isValidAndNotEmpty(m.libraryData) then return

m.expectedRowCount++

sectionName = tr("My Media")

row = CreateObject("roSGNode", "HomeRow")
Expand Down Expand Up @@ -275,15 +296,12 @@ sub createLatestInRows()
if not isValidAndNotEmpty(m.libraryData) then return

' create a "Latest In" row for each library
filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes)
for each lib in filteredLatest
for each lib in m.filteredLatest
if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program"
loadLatest = createObject("roSGNode", "LoadItemsTask")
loadLatest.itemsToLoad = "latest"
loadLatest.itemId = lib.id

m.expectedRowCount++

metadata = { "title": lib.name }
metadata.Append({ "contentType": lib.json.CollectionType })
loadLatest.metadata = metadata
Expand Down Expand Up @@ -346,15 +364,13 @@ end function
' createLiveTVRow: Creates a row displaying the live tv now on section
'
sub createLiveTVRow()
m.expectedRowCount++
m.LoadOnNowTask.observeField("content", "updateOnNowItems")
m.LoadOnNowTask.control = "RUN"
end sub

' createContinueWatchingRow: Creates a row displaying items the user can continue watching
'
sub createContinueWatchingRow()
m.expectedRowCount++
' Load the Continue Watching Data
m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems")
m.LoadContinueWatchingTask.control = "RUN"
Expand All @@ -363,7 +379,6 @@ end sub
' createNextUpRow: Creates a row displaying next episodes up to watch
'
sub createNextUpRow()
m.expectedRowCount++
sectionName = tr("Next Up") + ">"

if not sectionExists(sectionName)
Expand All @@ -381,7 +396,6 @@ end sub
' createFavoritesRow: Creates a row displaying items from the user's favorites list
'
sub createFavoritesRow()
m.expectedRowCount++
' Load the Favorites Data
m.LoadFavoritesTask.observeField("content", "updateFavoritesItems")
m.LoadFavoritesTask.control = "RUN"
Expand All @@ -398,19 +412,14 @@ end sub
' updateFavoritesItems: Processes LoadFavoritesTask content. Removes, Creates, or Updates favorites row as needed
'
sub updateFavoritesItems()
m.processedRowCount++
itemData = m.LoadFavoritesTask.content
m.LoadFavoritesTask.unobserveField("content")
m.LoadFavoritesTask.content = []

if itemData = invalid
m.expectedRowCount--
return
end if

sectionName = tr("Favorites")

if itemData.count() < 1
m.expectedRowCount--
if not isValidAndNotEmpty(itemData)
removeHomeSection(sectionName)
return
end if
Expand Down Expand Up @@ -446,19 +455,14 @@ end sub
' updateContinueWatchingItems: Processes LoadContinueWatchingTask content. Removes, Creates, or Updates continue watching row as needed
'
sub updateContinueWatchingItems()
m.processedRowCount++
itemData = m.LoadContinueWatchingTask.content
m.LoadContinueWatchingTask.unobserveField("content")
m.LoadContinueWatchingTask.content = []

if not isValid(itemData)
m.expectedRowCount--
return
end if

sectionName = tr("Continue Watching")

if itemData.count() < 1
m.expectedRowCount--
if not isValidAndNotEmpty(itemData)
removeHomeSection(sectionName)
return
end if
Expand Down Expand Up @@ -496,20 +500,15 @@ end sub
' updateNextUpItems: Processes LoadNextUpTask content. Removes, Creates, or Updates next up row as needed
'
sub updateNextUpItems()
m.processedRowCount++
itemData = m.LoadNextUpTask.content
m.LoadNextUpTask.unobserveField("content")
m.LoadNextUpTask.content = []
m.LoadNextUpTask.control = "STOP"

if itemData = invalid
m.expectedRowCount--
return
end if

sectionName = tr("Next Up") + " >"

if itemData.count() < 1
m.expectedRowCount--
if not isValidAndNotEmpty(itemData)
removeHomeSection(sectionName)
return
end if
Expand Down Expand Up @@ -542,21 +541,16 @@ end sub
'
' @param {dynamic} msg - LoadItemsTask
sub updateLatestItems(msg)
m.processedRowCount++
itemData = msg.GetData()

node = msg.getRoSGNode()
node.unobserveField("content")
node.content = []

if itemData = invalid
m.expectedRowCount--
return
end if

sectionName = tr("Latest in") + " " + node.metadata.title + " >"

if itemData.count() < 1
m.expectedRowCount--
if not isValidAndNotEmpty(itemData)
removeHomeSection(sectionName)
return
end if
Expand Down Expand Up @@ -598,19 +592,14 @@ end sub
' updateOnNowItems: Processes LoadOnNowTask content. Removes, Creates, or Updates latest in on now row as needed
'
sub updateOnNowItems()
m.processedRowCount++
itemData = m.LoadOnNowTask.content
m.LoadOnNowTask.unobserveField("content")
m.LoadOnNowTask.content = []

if not isValid(itemData)
m.expectedRowCount--
return
end if

sectionName = tr("On Now")

if itemData.count() < 1
m.expectedRowCount--
if not isValidAndNotEmpty(itemData)
removeHomeSection(sectionName)
return
end if
Expand Down

0 comments on commit 7e7ac10

Please sign in to comment.