From bd5a2cd4c295df0acfd431cff76027bbeccca800 Mon Sep 17 00:00:00 2001 From: 1hitsong <3330318+1hitsong@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:36:16 -0400 Subject: [PATCH 1/2] Respect Home Section settings from web --- components/config/ConfigList.brs | 4 +- components/home/HomeRows.brs | 424 ++++++++++++++++--------------- source/api/userauth.brs | 40 ++- 3 files changed, 264 insertions(+), 204 deletions(-) diff --git a/components/config/ConfigList.brs b/components/config/ConfigList.brs index f2c4f49c..427615e3 100644 --- a/components/config/ConfigList.brs +++ b/components/config/ConfigList.brs @@ -27,7 +27,7 @@ sub onItemSelected() i = m.top.itemSelected itemField = m.top.content.getchild(i) - show_dialog(itemField) + configList_show_dialog(itemField) end sub function onDialogButton() @@ -46,7 +46,7 @@ function onDialogButton() end function -sub show_dialog(configField) +sub configList_show_dialog(configField) dialog = createObject("roSGNode", "StandardKeyboardDialog") m.configField = configField dialog.title = configField.label diff --git a/components/home/HomeRows.brs b/components/home/HomeRows.brs index 4fce8fff..1a661644 100644 --- a/components/home/HomeRows.brs +++ b/components/home/HomeRows.brs @@ -12,6 +12,10 @@ sub init() m.top.rowLabelOffset = [0, 20] m.top.showRowCounter = [true] + m.homeSectionIndexes = { + count: 0 + } + updateSize() m.top.setfocus(true) @@ -61,73 +65,190 @@ sub onLibrariesLoaded() m.libraryData = m.LoadLibrariesTask.content m.LoadLibrariesTask.unobserveField("content") m.LoadLibrariesTask.content = [] - ' create My Media, Continue Watching, and Next Up rows + content = CreateObject("roSGNode", "ContentNode") + sizeArray = [] - mediaRow = content.CreateChild("HomeRow") - mediaRow.title = tr("My Media") + ' Add sections in order based on user settings + for i = 0 to 6 + addHomeSection(content, sizeArray, m.global.session.user.settings["homesection" + i.toStr()]) + end for - continueRow = content.CreateChild("HomeRow") - continueRow.title = tr("Continue Watching") - - nextUpRow = content.CreateChild("HomeRow") - nextUpRow.title = tr("Next Up >") - - favoritesRow = content.CreateChild("HomeRow") - favoritesRow.title = tr("Favorites") - - sizeArray = [ - [464, 311], ' My Media - [464, 331], ' Continue Watching - [464, 331], ' Next Up - [464, 331] ' Favorites - ] - - haveLiveTV = false - - ' validate library data - if isValid(m.libraryData) and m.libraryData.count() > 0 - ' populate My Media row - filteredMedia = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.MyMediaExcludes) - for each item in filteredMedia - mediaRow.appendChild(item) - end for - - ' create a "Latest In" row for each library - filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes) - for each lib in filteredLatest - if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program" - latestInRow = content.CreateChild("HomeRow") - latestInRow.title = tr("Latest in") + " " + lib.name + " >" - sizeArray.Push([464, 331]) - else if lib.collectionType = "livetv" - ' If we have Live TV, add "On Now" - onNowRow = content.CreateChild("HomeRow") - onNowRow.title = tr("On Now") - sizeArray.Push([464, 331]) - haveLiveTV = true - end if - end for - end if + ' Favorites isn't an option on Web settings, so we must manually add it for now + addHomeSection(content, sizeArray, "favorites") m.top.rowItemSize = sizeArray m.top.content = content + ' consider home screen loaded when above rows are loaded + if not m.global.app_loaded + m.top.signalBeacon("AppLaunchComplete") ' Roku Performance monitoring + m.global.app_loaded = true + end if +end sub + +' Removes a home section from the home rows +sub removeHomeSection(sectionType as string) + sectionName = LCase(sectionType) + + removedSectionIndex = m.homeSectionIndexes[sectionName] + + for each section in m.homeSectionIndexes + if m.homeSectionIndexes[section] > removedSectionIndex + m.homeSectionIndexes[section] = m.homeSectionIndexes[section] - 1 + end if + end for + + m.homeSectionIndexes.Delete(sectionName) + m.homeSectionIndexes.AddReplace("count", m.homeSectionIndexes.count - 1) + + m.top.content.removeChildIndex(removedSectionIndex) +end sub + +' Adds a new home section to the home rows +sub addHomeSection(content as dynamic, sizeArray as dynamic, sectionType as string) + sectionName = LCase(sectionType) + + ' Poster size library items + if sectionName = "livetv" + createLiveTVRow(content, sizeArray) + return + end if + + ' Poster size library items + if sectionName = "smalllibrarytiles" + createLibraryRow(content, sizeArray) + return + end if + + ' Continue Watching items + if sectionName = "resume" + createResumeRow(content, sizeArray) + return + end if + + ' Next Up items + if sectionName = "nextup" + createNextUpRow(content, sizeArray) + return + end if + + ' Latest items in each library + if sectionName = "latestmedia" + createLatestInRows(content, sizeArray) + return + end if + + ' Favorite Items + if sectionName = "favorites" + createFavoritesRow(content, sizeArray) + return + end if + +end sub + +' Create a row displaying the user's libraries +sub createLibraryRow(content as dynamic, sizeArray as dynamic) + ' Ensure we have data + if not isValidAndNotEmpty(m.libraryData) then return + + mediaRow = content.CreateChild("HomeRow") + mediaRow.title = tr("My Media") + + m.homeSectionIndexes.AddReplace("library", m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ + + sizeArray.push([464, 331]) + + filteredMedia = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.MyMediaExcludes) + for each item in filteredMedia + mediaRow.appendChild(item) + end for +end sub + +' Create a row displaying latest items in each of the user's libraries +sub createLatestInRows(content as dynamic, sizeArray as dynamic) + ' Ensure we have data + 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 + if lib.collectionType <> "boxsets" and lib.collectionType <> "livetv" and lib.json.CollectionType <> "Program" + latestInRow = content.CreateChild("HomeRow") + latestInRow.title = tr("Latest in") + " " + lib.name + " >" + + m.homeSectionIndexes.AddReplace("latestin" + LCase(lib.name).Replace(" ", ""), m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ + sizeArray.Push([464, 331]) + + 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", "updateLatestItems") + loadLatest.control = "RUN" + end if + end for +end sub + +' Create a row displaying the live tv now on section +sub createLiveTVRow(content as dynamic, sizeArray as dynamic) + contentRow = content.CreateChild("HomeRow") + contentRow.title = tr("On Now") + m.homeSectionIndexes.AddReplace("livetv", m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ + sizeArray.push([464, 331]) + + m.LoadOnNowTask.observeField("content", "updateOnNowItems") + m.LoadOnNowTask.control = "RUN" +end sub + +' Create a row displaying items the user can continue watching +sub createResumeRow(content as dynamic, sizeArray as dynamic) + continueRow = content.CreateChild("HomeRow") + continueRow.title = tr("Continue Watching") + m.homeSectionIndexes.AddReplace("resume", m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ + sizeArray.push([464, 331]) + ' Load the Continue Watching Data m.LoadContinueTask.observeField("content", "updateContinueItems") m.LoadContinueTask.control = "RUN" +end sub + +' Create a row displaying next episodes up to watch +sub createNextUpRow(content as dynamic, sizeArray as dynamic) + nextUpRow = content.CreateChild("HomeRow") + nextUpRow.title = tr("Next Up >") + m.homeSectionIndexes.AddReplace("nextup", m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ + sizeArray.push([464, 331]) + + ' Load the Next Up Data + m.LoadNextUpTask.observeField("content", "updateNextUpItems") + m.LoadNextUpTask.control = "RUN" +end sub + +' Create a row displaying items from the user's favorites list +sub createFavoritesRow(content as dynamic, sizeArray as dynamic) + favoritesRow = content.CreateChild("HomeRow") + favoritesRow.title = tr("Favorites") + sizeArray.Push([464, 331]) + + m.homeSectionIndexes.AddReplace("favorites", m.homeSectionIndexes.count) + m.homeSectionIndexes.count++ ' Load the Favorites Data m.LoadFavoritesTask.observeField("content", "updateFavoritesItems") m.LoadFavoritesTask.control = "RUN" - - ' If we have Live TV access, load "On Now" data - if haveLiveTV - m.LoadOnNowTask.observeField("content", "updateOnNowItems") - m.LoadOnNowTask.control = "RUN" - end if end sub +' Update home row data sub updateHomeRows() if m.global.playstateTask.state = "run" m.global.playstateTask.observeField("state", "updateHomeRows") @@ -136,8 +257,17 @@ sub updateHomeRows() m.global.playstateTask.unobserveField("state") - m.LoadContinueTask.observeField("content", "updateContinueItems") - m.LoadContinueTask.control = "RUN" + ' If resume section exists, reload row's data + if m.homeSectionIndexes.doesExist("resume") + m.LoadContinueTask.observeField("content", "updateContinueItems") + m.LoadContinueTask.control = "RUN" + end if + + ' If next up section exists, reload row's data + if m.homeSectionIndexes.doesExist("nextup") + m.LoadNextUpTask.observeField("content", "updateNextUpItems") + m.LoadNextUpTask.control = "RUN" + end if end sub sub updateFavoritesItems() @@ -147,20 +277,15 @@ sub updateFavoritesItems() if itemData = invalid then return - homeRows = m.top.content - rowIndex = getRowIndex("Favorites") + rowIndex = m.homeSectionIndexes.favorites if itemData.count() < 1 - if isValid(rowIndex) - ' remove the row - deleteFromSizeArray(rowIndex) - homeRows.removeChildIndex(rowIndex) - end if + removeHomeSection("favorites") + return else ' remake row using the new data row = CreateObject("roSGNode", "HomeRow") row.title = tr("Favorites") - itemSize = [464, 331] for each item in itemData usePoster = true @@ -174,14 +299,9 @@ sub updateFavoritesItems() row.appendChild(item) end for - if rowIndex = invalid - ' insert new row under "My Media" - updateSizeArray(itemSize, 1) - homeRows.insertChild(row, 1) - else - ' replace the old row - homeRows.replaceChild(row, rowIndex) - end if + ' replace the old row + m.top.content.replaceChild(row, rowIndex) + end if end sub @@ -192,42 +312,27 @@ sub updateContinueItems() if itemData = invalid then return - homeRows = m.top.content - continueRowIndex = getRowIndex("Continue Watching") - if itemData.count() < 1 - if isValid(continueRowIndex) - ' remove the row - deleteFromSizeArray(continueRowIndex) - homeRows.removeChildIndex(continueRowIndex) - end if - else - ' remake row using the new data - row = CreateObject("roSGNode", "HomeRow") - row.title = tr("Continue Watching") - itemSize = [464, 331] - for each item in itemData - if isValid(item.json) and isValid(item.json.UserData) and isValid(item.json.UserData.PlayedPercentage) - item.PlayedPercentage = item.json.UserData.PlayedPercentage - end if - - item.usePoster = row.usePoster - item.imageWidth = row.imageWidth - row.appendChild(item) - end for - - if continueRowIndex = invalid - ' insert new row under "My Media" - updateSizeArray(itemSize, 1) - homeRows.insertChild(row, 1) - else - ' replace the old row - homeRows.replaceChild(row, continueRowIndex) - end if + removeHomeSection("resume") + return end if - m.LoadNextUpTask.observeField("content", "updateNextUpItems") - m.LoadNextUpTask.control = "RUN" + ' remake row using the new data + row = CreateObject("roSGNode", "HomeRow") + row.title = tr("Continue Watching") + + for each item in itemData + if isValid(item.json) and isValid(item.json.UserData) and isValid(item.json.UserData.PlayedPercentage) + item.PlayedPercentage = item.json.UserData.PlayedPercentage + end if + + item.usePoster = row.usePoster + item.imageWidth = row.imageWidth + row.appendChild(item) + end for + + ' replace the old row + m.top.content.replaceChild(row, m.homeSectionIndexes.resume) end sub sub updateNextUpItems() @@ -237,66 +342,22 @@ sub updateNextUpItems() if itemData = invalid then return - homeRows = m.top.content - nextUpRowIndex = getRowIndex("Next Up >") - if itemData.count() < 1 - if isValid(nextUpRowIndex) - ' remove the row - deleteFromSizeArray(nextUpRowIndex) - homeRows.removeChildIndex(nextUpRowIndex) - end if + removeHomeSection("nextup") + return else ' remake row using the new data row = CreateObject("roSGNode", "HomeRow") row.title = tr("Next Up") + " >" - itemSize = [464, 331] for each item in itemData item.usePoster = row.usePoster item.imageWidth = row.imageWidth row.appendChild(item) end for - if nextUpRowIndex = invalid - ' insert new row under "Continue Watching" - continueRowIndex = getRowIndex("Continue Watching") - if isValid(continueRowIndex) - updateSizeArray(itemSize, continueRowIndex + 1) - homeRows.insertChild(row, continueRowIndex + 1) - else - ' insert it under My Media - updateSizeArray(itemSize, 1) - homeRows.insertChild(row, 1) - end if - else - ' replace the old row - homeRows.replaceChild(row, nextUpRowIndex) - end if + ' replace the old row + m.top.content.replaceChild(row, m.homeSectionIndexes.nextup) end if - - ' consider home screen loaded when above rows are loaded - if m.global.app_loaded = false - m.top.signalBeacon("AppLaunchComplete") ' Roku Performance monitoring - m.global.app_loaded = true - end if - - ' create task nodes for "Latest In" rows - filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes) - for each lib in filteredLatest - if lib.collectionType <> "livetv" and lib.collectionType <> "boxsets" and lib.json.CollectionType <> "Program" - 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", "updateLatestItems") - loadLatest.control = "RUN" - end if - end for - end sub sub updateLatestItems(msg) @@ -308,15 +369,13 @@ sub updateLatestItems(msg) if itemData = invalid then return - homeRows = m.top.content - rowIndex = getRowIndex(tr("Latest in") + " " + node.metadata.title + " >") + sectionName = "latestin" + LCase(node.metadata.title).Replace(" ", "") + + rowIndex = m.homeSectionIndexes[sectionName] if itemData.count() < 1 - ' remove row - if isValid(rowIndex) - deleteFromSizeArray(rowIndex) - homeRows.removeChildIndex(rowIndex) - end if + removeHomeSection(sectionName) + return else ' remake row using new data row = CreateObject("roSGNode", "HomeRow") @@ -340,15 +399,9 @@ sub updateLatestItems(msg) row.appendChild(item) end for - if rowIndex = invalid - ' append new row - updateSizeArray(itemSize) - homeRows.appendChild(row) - else - ' replace the old row - updateSizeArray(itemSize, rowIndex, "replace") - homeRows.replaceChild(row, rowIndex) - end if + ' replace the old row + updateSizeArray(itemSize, rowIndex, "replace") + m.top.content.replaceChild(row, rowIndex) end if end sub @@ -359,50 +412,25 @@ sub updateOnNowItems() if itemData = invalid then return - homeRows = m.top.content - onNowRowIndex = getRowIndex("On Now") - if itemData.count() < 1 - if isValid(onNowRowIndex) - ' remove the row - deleteFromSizeArray(onNowRowIndex) - homeRows.removeChildIndex(onNowRowIndex) - end if + removeHomeSection("livetv") + return else ' remake row using the new data row = CreateObject("roSGNode", "HomeRow") row.title = tr("On Now") - itemSize = [464, 331] for each item in itemData item.usePoster = row.usePoster item.imageWidth = row.imageWidth row.appendChild(item) end for - if onNowRowIndex = invalid - ' insert new row under "My Media" - updateSizeArray(itemSize, 1) - homeRows.insertChild(row, 1) - else - ' replace the old row - homeRows.replaceChild(row, onNowRowIndex) - end if + ' replace the old row + m.top.content.replaceChild(row, m.homeSectionIndexes.livetv) + end if end sub -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 - rowIndex = i - exit for - end if - end for - return rowIndex -end function - sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "insert") sizeArray = m.top.rowItemSize ' append by default @@ -428,10 +456,6 @@ sub updateSizeArray(rowItemSize, rowIndex = invalid, action = "insert") m.top.rowItemSize = newSizeArray end sub -sub deleteFromSizeArray(rowIndex) - updateSizeArray([0, 0], rowIndex, "delete") -end sub - sub itemSelected() m.top.selectedItem = m.top.content.getChild(m.top.rowItemSelected[0]).getChild(m.top.rowItemSelected[1]) diff --git a/source/api/userauth.brs b/source/api/userauth.brs index ce00984b..4a6285ce 100644 --- a/source/api/userauth.brs +++ b/source/api/userauth.brs @@ -1,5 +1,6 @@ ' needed for SignOut() and ServerInfo() import "pkg:/source/utils/session.bs" +import "pkg:/source/utils/misc.brs" function get_token(user as string, password as string) url = "Users/AuthenticateByName?format=json" @@ -118,13 +119,48 @@ sub LoadUserPreferences() resp = APIRequest(url) jsonResponse = getJson(resp) - if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid and jsonResponse.CustomPrefs["landing-livetv"] <> invalid - set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"]) + if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid + LoadUserHomeSections(jsonResponse.CustomPrefs) + + if jsonResponse.CustomPrefs["landing-livetv"] <> invalid + set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"]) + else + unset_user_setting("display.livetv.landing") + end if else unset_user_setting("display.livetv.landing") end if end sub +sub LoadUserHomeSections(customPrefs as object) + rowTypes = [] + + for i = 0 to 6 + homeSectionKey = "homesection" + i.toStr() + rowType = LCase(customPrefs[homeSectionKey]) + + ' Just in case we get invalid data + if not isValid(rowType) then rowType = "none" + + ' Small size library item buttons - Currently unsupported, use small library titles + if rowType = "librarybuttons" + rowType = "smalllibrarytiles" + end if + + ' None is the only section type allowed to have duplicates + ' For all other types, only accept the 1st entry + if inArray(rowTypes, rowType) + set_user_setting(homeSectionKey, "none") + else + set_user_setting(homeSectionKey, rowType) + + if rowType <> "none" + rowTypes.push(rowType) + end if + end if + end for +end sub + sub LoadUserAbilities() if m.global.session.user.Policy.EnableLiveTvManagement = true set_user_setting("livetv.canrecord", "true") From e4f8523387c978b6335d27f39107c38374de7408 Mon Sep 17 00:00:00 2001 From: 1hitsong <3330318+1hitsong@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:37:37 -0400 Subject: [PATCH 2/2] Review items Now updates favorites, Live TV on now, and latest in library sections when returning to view. Code cleanup. Fire loaded beacon after 2 rows load. --- components/config/ConfigList.brs | 4 +- components/home/HomeRows.brs | 124 +++++++++++++----- .../quickConnect/QuickConnectDialog.brs | 2 +- source/ShowScenes.brs | 8 +- source/api/userauth.brs | 51 ------- source/utils/session.bs | 53 ++++++++ 6 files changed, 151 insertions(+), 91 deletions(-) diff --git a/components/config/ConfigList.brs b/components/config/ConfigList.brs index 427615e3..4e015df0 100644 --- a/components/config/ConfigList.brs +++ b/components/config/ConfigList.brs @@ -27,7 +27,7 @@ sub onItemSelected() i = m.top.itemSelected itemField = m.top.content.getchild(i) - configList_show_dialog(itemField) + configListShowDialog(itemField) end sub function onDialogButton() @@ -46,7 +46,7 @@ function onDialogButton() end function -sub configList_show_dialog(configField) +sub configListShowDialog(configField) dialog = createObject("roSGNode", "StandardKeyboardDialog") m.configField = configField dialog.title = configField.label diff --git a/components/home/HomeRows.brs b/components/home/HomeRows.brs index 1a661644..68a4a9ec 100644 --- a/components/home/HomeRows.brs +++ b/components/home/HomeRows.brs @@ -27,8 +27,8 @@ sub init() m.LoadLibrariesTask.observeField("content", "onLibrariesLoaded") ' set up tesk nodes for other rows - m.LoadContinueTask = createObject("roSGNode", "LoadItemsTask") - m.LoadContinueTask.itemsToLoad = "continue" + m.LoadContinueWatchingTask = createObject("roSGNode", "LoadItemsTask") + m.LoadContinueWatchingTask.itemsToLoad = "continue" m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask") m.LoadNextUpTask.itemsToLoad = "nextUp" @@ -68,10 +68,23 @@ sub onLibrariesLoaded() content = CreateObject("roSGNode", "ContentNode") sizeArray = [] + loadedSections = 0 ' Add sections in order based on user settings for i = 0 to 6 - addHomeSection(content, sizeArray, m.global.session.user.settings["homesection" + i.toStr()]) + sectionName = LCase(m.global.session.user.settings["homesection" + i.toStr()]) + sectionLoaded = addHomeSection(content, sizeArray, sectionName) + + ' Count how many sections with data are loaded + if sectionLoaded then loadedSections++ + + ' If 2 sections with data are loaded or we're at the end of the web client section data, consider the home view loaded + if loadedSections = 2 or i = 6 + if not m.global.app_loaded + m.top.signalBeacon("AppLaunchComplete") ' Roku Performance monitoring + m.global.app_loaded = true + end if + end if end for ' Favorites isn't an option on Web settings, so we must manually add it for now @@ -79,12 +92,6 @@ sub onLibrariesLoaded() m.top.rowItemSize = sizeArray m.top.content = content - - ' consider home screen loaded when above rows are loaded - if not m.global.app_loaded - m.top.signalBeacon("AppLaunchComplete") ' Roku Performance monitoring - m.global.app_loaded = true - end if end sub ' Removes a home section from the home rows @@ -93,9 +100,11 @@ sub removeHomeSection(sectionType as string) removedSectionIndex = m.homeSectionIndexes[sectionName] + if not isValid(removedSectionIndex) then return + for each section in m.homeSectionIndexes if m.homeSectionIndexes[section] > removedSectionIndex - m.homeSectionIndexes[section] = m.homeSectionIndexes[section] - 1 + m.homeSectionIndexes[section]-- end if end for @@ -105,47 +114,47 @@ sub removeHomeSection(sectionType as string) m.top.content.removeChildIndex(removedSectionIndex) end sub -' Adds a new home section to the home rows -sub addHomeSection(content as dynamic, sizeArray as dynamic, sectionType as string) - sectionName = LCase(sectionType) - +' Adds a new home section to the home rows. +' Returns a boolean indicating whether the section was handled. +function addHomeSection(content as dynamic, sizeArray as dynamic, sectionName as string) as boolean ' Poster size library items if sectionName = "livetv" createLiveTVRow(content, sizeArray) - return + return true end if ' Poster size library items if sectionName = "smalllibrarytiles" createLibraryRow(content, sizeArray) - return + return true end if ' Continue Watching items if sectionName = "resume" - createResumeRow(content, sizeArray) - return + createContinueWatchingRow(content, sizeArray) + return true end if ' Next Up items if sectionName = "nextup" createNextUpRow(content, sizeArray) - return + return true end if ' Latest items in each library if sectionName = "latestmedia" createLatestInRows(content, sizeArray) - return + return true end if ' Favorite Items if sectionName = "favorites" createFavoritesRow(content, sizeArray) - return + return true end if -end sub + return false +end function ' Create a row displaying the user's libraries sub createLibraryRow(content as dynamic, sizeArray as dynamic) @@ -209,16 +218,16 @@ sub createLiveTVRow(content as dynamic, sizeArray as dynamic) end sub ' Create a row displaying items the user can continue watching -sub createResumeRow(content as dynamic, sizeArray as dynamic) - continueRow = content.CreateChild("HomeRow") - continueRow.title = tr("Continue Watching") +sub createContinueWatchingRow(content as dynamic, sizeArray as dynamic) + continueWatchingRow = content.CreateChild("HomeRow") + continueWatchingRow.title = tr("Continue Watching") m.homeSectionIndexes.AddReplace("resume", m.homeSectionIndexes.count) m.homeSectionIndexes.count++ sizeArray.push([464, 331]) ' Load the Continue Watching Data - m.LoadContinueTask.observeField("content", "updateContinueItems") - m.LoadContinueTask.control = "RUN" + m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems") + m.LoadContinueWatchingTask.control = "RUN" end sub ' Create a row displaying next episodes up to watch @@ -259,8 +268,8 @@ sub updateHomeRows() ' If resume section exists, reload row's data if m.homeSectionIndexes.doesExist("resume") - m.LoadContinueTask.observeField("content", "updateContinueItems") - m.LoadContinueTask.control = "RUN" + m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems") + m.LoadContinueWatchingTask.control = "RUN" end if ' If next up section exists, reload row's data @@ -268,6 +277,32 @@ sub updateHomeRows() m.LoadNextUpTask.observeField("content", "updateNextUpItems") m.LoadNextUpTask.control = "RUN" end if + + ' If favorites section exists, reload row's data + if m.homeSectionIndexes.doesExist("favorites") + m.LoadFavoritesTask.observeField("content", "updateFavoritesItems") + m.LoadFavoritesTask.control = "RUN" + end if + + ' If live tv's on now section exists, reload row's data + if m.homeSectionIndexes.doesExist("livetv") + m.LoadOnNowTask.observeField("content", "updateOnNowItems") + m.LoadOnNowTask.control = "RUN" + end if + + ' If latest in library section exists, reload row's data + hasLatestHomeSection = false + + for each section in m.homeSectionIndexes + if LCase(Left(section, 6)) = "latest" + hasLatestHomeSection = true + exit for + end if + end for + + if hasLatestHomeSection + updateLatestInRows() + end if end sub sub updateFavoritesItems() @@ -305,10 +340,10 @@ sub updateFavoritesItems() end if end sub -sub updateContinueItems() - itemData = m.LoadContinueTask.content - m.LoadContinueTask.unobserveField("content") - m.LoadContinueTask.content = [] +sub updateContinueWatchingItems() + itemData = m.LoadContinueWatchingTask.content + m.LoadContinueWatchingTask.unobserveField("content") + m.LoadContinueWatchingTask.content = [] if itemData = invalid then return @@ -360,6 +395,29 @@ sub updateNextUpItems() end if end sub +' Iterate over user's libraries and update data for each Latest In section +sub updateLatestInRows() + ' Ensure we have data + if not isValidAndNotEmpty(m.libraryData) then return + + ' Load new data for each library + filteredLatest = filterNodeArray(m.libraryData, "id", m.global.session.user.configuration.LatestItemsExcludes) + for each lib in 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 + + metadata = { "title": lib.name } + metadata.Append({ "contentType": lib.json.CollectionType }) + loadLatest.metadata = metadata + + loadLatest.observeField("content", "updateLatestItems") + loadLatest.control = "RUN" + end if + end for +end sub + sub updateLatestItems(msg) itemData = msg.GetData() diff --git a/components/quickConnect/QuickConnectDialog.brs b/components/quickConnect/QuickConnectDialog.brs index c646b146..defb80d9 100644 --- a/components/quickConnect/QuickConnectDialog.brs +++ b/components/quickConnect/QuickConnectDialog.brs @@ -34,7 +34,7 @@ sub OnAuthenticated() if authenticated <> invalid and authenticated = true currentUser = AboutMe() session.user.Login(currentUser) - LoadUserPreferences() + session.user.LoadUserPreferences() LoadUserAbilities() m.top.close = true m.top.authenticated = true diff --git a/source/ShowScenes.brs b/source/ShowScenes.brs index 48a1853d..055df394 100644 --- a/source/ShowScenes.brs +++ b/source/ShowScenes.brs @@ -90,7 +90,7 @@ function LoginFlow() else print "Success! Auth token is still valid" session.user.Login(currentUser) - LoadUserPreferences() + session.user.LoadUserPreferences() LoadUserAbilities() return true end if @@ -103,7 +103,7 @@ function LoginFlow() if isValid(userData) print "login success!" session.user.Login(userData) - LoadUserPreferences() + session.user.LoadUserPreferences() LoadUserAbilities() return true else @@ -146,7 +146,7 @@ function LoginFlow() if isValid(userData) print "login success!" session.user.Login(userData) - LoadUserPreferences() + session.user.LoadUserPreferences() LoadUserAbilities() return true else @@ -172,7 +172,7 @@ function LoginFlow() goto start_login end if - LoadUserPreferences() + session.user.LoadUserPreferences() LoadUserAbilities() m.global.sceneManager.callFunc("clearScenes") diff --git a/source/api/userauth.brs b/source/api/userauth.brs index 4a6285ce..33f32252 100644 --- a/source/api/userauth.brs +++ b/source/api/userauth.brs @@ -110,57 +110,6 @@ function GetPublicUsers() return getJson(resp) end function -' Load and parse Display Settings from server -sub LoadUserPreferences() - id = m.global.session.user.id - ' Currently using client "emby", which is what website uses so we get same Display prefs as web. - ' May want to change to specific Roku display settings - url = Substitute("DisplayPreferences/usersettings?userId={0}&client=emby", id) - resp = APIRequest(url) - jsonResponse = getJson(resp) - - if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid - LoadUserHomeSections(jsonResponse.CustomPrefs) - - if jsonResponse.CustomPrefs["landing-livetv"] <> invalid - set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"]) - else - unset_user_setting("display.livetv.landing") - end if - else - unset_user_setting("display.livetv.landing") - end if -end sub - -sub LoadUserHomeSections(customPrefs as object) - rowTypes = [] - - for i = 0 to 6 - homeSectionKey = "homesection" + i.toStr() - rowType = LCase(customPrefs[homeSectionKey]) - - ' Just in case we get invalid data - if not isValid(rowType) then rowType = "none" - - ' Small size library item buttons - Currently unsupported, use small library titles - if rowType = "librarybuttons" - rowType = "smalllibrarytiles" - end if - - ' None is the only section type allowed to have duplicates - ' For all other types, only accept the 1st entry - if inArray(rowTypes, rowType) - set_user_setting(homeSectionKey, "none") - else - set_user_setting(homeSectionKey, rowType) - - if rowType <> "none" - rowTypes.push(rowType) - end if - end if - end for -end sub - sub LoadUserAbilities() if m.global.session.user.Policy.EnableLiveTvManagement = true set_user_setting("livetv.canrecord", "true") diff --git a/source/utils/session.bs b/source/utils/session.bs index 01c5712d..9ec9e4df 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -162,6 +162,59 @@ namespace session end if end sub + ' Load and parse Display Settings from server + sub LoadUserPreferences() + id = m.global.session.user.id + ' Currently using client "emby", which is what website uses so we get same Display prefs as web. + ' May want to change to specific Roku display settings + url = Substitute("DisplayPreferences/usersettings?userId={0}&client=emby", id) + resp = APIRequest(url) + jsonResponse = getJson(resp) + + if isValid(jsonResponse) and isValid(jsonResponse.CustomPrefs) + session.user.SaveUserHomeSections(jsonResponse.CustomPrefs) + + if isValid(jsonResponse.CustomPrefs["landing-livetv"]) + set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"]) + else + unset_user_setting("display.livetv.landing") + end if + else + unset_user_setting("display.livetv.landing") + end if + end sub + + ' Saves user's web client home sections as Roku user settings. + ' Handles unsupported sections and ignores duplicates. + sub SaveUserHomeSections(customPrefs as object) + rowTypes = [] + + for i = 0 to 6 + homeSectionKey = "homesection" + i.toStr() + rowType = LCase(customPrefs[homeSectionKey]) + + ' Just in case we get invalid data + if not isValid(rowType) then rowType = "none" + + ' Small size library item buttons - Currently unsupported, use small library titles + if rowType = "librarybuttons" + rowType = "smalllibrarytiles" + end if + + ' None is the only section type allowed to have duplicates + ' For all other types, only accept the 1st entry + if inArray(rowTypes, rowType) + set_user_setting(homeSectionKey, "none") + else + set_user_setting(homeSectionKey, rowType) + + if rowType <> "none" + rowTypes.push(rowType) + end if + end if + end for + end sub + ' Empty the global user session array and reload defaults sub Logout() session.Update("user", {