diff --git a/components/home/HomeRows.bs b/components/home/HomeRows.bs index 894e5e47..b888da39 100644 --- a/components/home/HomeRows.bs +++ b/components/home/HomeRows.bs @@ -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 - ' Add sections in order based on user settings + ' calculate expected row count by processing homesections for i = 0 to 6 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 if sectionLoaded then loadedSections++ @@ -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 @@ -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") @@ -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 @@ -346,7 +364,6 @@ 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 @@ -354,7 +371,6 @@ 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" @@ -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) @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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