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.
This commit is contained in:
1hitsong 2023-10-22 18:37:37 -04:00
parent bd5a2cd4c2
commit e4f8523387
6 changed files with 151 additions and 91 deletions

View File

@ -27,7 +27,7 @@ sub onItemSelected()
i = m.top.itemSelected i = m.top.itemSelected
itemField = m.top.content.getchild(i) itemField = m.top.content.getchild(i)
configList_show_dialog(itemField) configListShowDialog(itemField)
end sub end sub
function onDialogButton() function onDialogButton()
@ -46,7 +46,7 @@ function onDialogButton()
end function end function
sub configList_show_dialog(configField) sub configListShowDialog(configField)
dialog = createObject("roSGNode", "StandardKeyboardDialog") dialog = createObject("roSGNode", "StandardKeyboardDialog")
m.configField = configField m.configField = configField
dialog.title = configField.label dialog.title = configField.label

View File

@ -27,8 +27,8 @@ sub init()
m.LoadLibrariesTask.observeField("content", "onLibrariesLoaded") m.LoadLibrariesTask.observeField("content", "onLibrariesLoaded")
' set up tesk nodes for other rows ' set up tesk nodes for other rows
m.LoadContinueTask = createObject("roSGNode", "LoadItemsTask") m.LoadContinueWatchingTask = createObject("roSGNode", "LoadItemsTask")
m.LoadContinueTask.itemsToLoad = "continue" m.LoadContinueWatchingTask.itemsToLoad = "continue"
m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask") m.LoadNextUpTask = createObject("roSGNode", "LoadItemsTask")
m.LoadNextUpTask.itemsToLoad = "nextUp" m.LoadNextUpTask.itemsToLoad = "nextUp"
@ -68,10 +68,23 @@ sub onLibrariesLoaded()
content = CreateObject("roSGNode", "ContentNode") content = CreateObject("roSGNode", "ContentNode")
sizeArray = [] sizeArray = []
loadedSections = 0
' Add sections in order based on user settings ' Add sections in order based on user settings
for i = 0 to 6 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 end for
' Favorites isn't an option on Web settings, so we must manually add it for now ' 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.rowItemSize = sizeArray
m.top.content = content 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 end sub
' Removes a home section from the home rows ' Removes a home section from the home rows
@ -93,9 +100,11 @@ sub removeHomeSection(sectionType as string)
removedSectionIndex = m.homeSectionIndexes[sectionName] removedSectionIndex = m.homeSectionIndexes[sectionName]
if not isValid(removedSectionIndex) then return
for each section in m.homeSectionIndexes for each section in m.homeSectionIndexes
if m.homeSectionIndexes[section] > removedSectionIndex if m.homeSectionIndexes[section] > removedSectionIndex
m.homeSectionIndexes[section] = m.homeSectionIndexes[section] - 1 m.homeSectionIndexes[section]--
end if end if
end for end for
@ -105,47 +114,47 @@ sub removeHomeSection(sectionType as string)
m.top.content.removeChildIndex(removedSectionIndex) m.top.content.removeChildIndex(removedSectionIndex)
end sub end sub
' Adds a new home section to the home rows ' Adds a new home section to the home rows.
sub addHomeSection(content as dynamic, sizeArray as dynamic, sectionType as string) ' Returns a boolean indicating whether the section was handled.
sectionName = LCase(sectionType) function addHomeSection(content as dynamic, sizeArray as dynamic, sectionName as string) as boolean
' Poster size library items ' Poster size library items
if sectionName = "livetv" if sectionName = "livetv"
createLiveTVRow(content, sizeArray) createLiveTVRow(content, sizeArray)
return return true
end if end if
' Poster size library items ' Poster size library items
if sectionName = "smalllibrarytiles" if sectionName = "smalllibrarytiles"
createLibraryRow(content, sizeArray) createLibraryRow(content, sizeArray)
return return true
end if end if
' Continue Watching items ' Continue Watching items
if sectionName = "resume" if sectionName = "resume"
createResumeRow(content, sizeArray) createContinueWatchingRow(content, sizeArray)
return return true
end if end if
' Next Up items ' Next Up items
if sectionName = "nextup" if sectionName = "nextup"
createNextUpRow(content, sizeArray) createNextUpRow(content, sizeArray)
return return true
end if end if
' Latest items in each library ' Latest items in each library
if sectionName = "latestmedia" if sectionName = "latestmedia"
createLatestInRows(content, sizeArray) createLatestInRows(content, sizeArray)
return return true
end if end if
' Favorite Items ' Favorite Items
if sectionName = "favorites" if sectionName = "favorites"
createFavoritesRow(content, sizeArray) createFavoritesRow(content, sizeArray)
return return true
end if end if
end sub return false
end function
' Create a row displaying the user's libraries ' Create a row displaying the user's libraries
sub createLibraryRow(content as dynamic, sizeArray as dynamic) sub createLibraryRow(content as dynamic, sizeArray as dynamic)
@ -209,16 +218,16 @@ sub createLiveTVRow(content as dynamic, sizeArray as dynamic)
end sub end sub
' Create a row displaying items the user can continue watching ' Create a row displaying items the user can continue watching
sub createResumeRow(content as dynamic, sizeArray as dynamic) sub createContinueWatchingRow(content as dynamic, sizeArray as dynamic)
continueRow = content.CreateChild("HomeRow") continueWatchingRow = content.CreateChild("HomeRow")
continueRow.title = tr("Continue Watching") continueWatchingRow.title = tr("Continue Watching")
m.homeSectionIndexes.AddReplace("resume", m.homeSectionIndexes.count) m.homeSectionIndexes.AddReplace("resume", m.homeSectionIndexes.count)
m.homeSectionIndexes.count++ m.homeSectionIndexes.count++
sizeArray.push([464, 331]) sizeArray.push([464, 331])
' Load the Continue Watching Data ' Load the Continue Watching Data
m.LoadContinueTask.observeField("content", "updateContinueItems") m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems")
m.LoadContinueTask.control = "RUN" m.LoadContinueWatchingTask.control = "RUN"
end sub end sub
' Create a row displaying next episodes up to watch ' Create a row displaying next episodes up to watch
@ -259,8 +268,8 @@ sub updateHomeRows()
' If resume section exists, reload row's data ' If resume section exists, reload row's data
if m.homeSectionIndexes.doesExist("resume") if m.homeSectionIndexes.doesExist("resume")
m.LoadContinueTask.observeField("content", "updateContinueItems") m.LoadContinueWatchingTask.observeField("content", "updateContinueWatchingItems")
m.LoadContinueTask.control = "RUN" m.LoadContinueWatchingTask.control = "RUN"
end if end if
' If next up section exists, reload row's data ' If next up section exists, reload row's data
@ -268,6 +277,32 @@ sub updateHomeRows()
m.LoadNextUpTask.observeField("content", "updateNextUpItems") m.LoadNextUpTask.observeField("content", "updateNextUpItems")
m.LoadNextUpTask.control = "RUN" m.LoadNextUpTask.control = "RUN"
end if 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 end sub
sub updateFavoritesItems() sub updateFavoritesItems()
@ -305,10 +340,10 @@ sub updateFavoritesItems()
end if end if
end sub end sub
sub updateContinueItems() sub updateContinueWatchingItems()
itemData = m.LoadContinueTask.content itemData = m.LoadContinueWatchingTask.content
m.LoadContinueTask.unobserveField("content") m.LoadContinueWatchingTask.unobserveField("content")
m.LoadContinueTask.content = [] m.LoadContinueWatchingTask.content = []
if itemData = invalid then return if itemData = invalid then return
@ -360,6 +395,29 @@ sub updateNextUpItems()
end if end if
end sub 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) sub updateLatestItems(msg)
itemData = msg.GetData() itemData = msg.GetData()

View File

@ -34,7 +34,7 @@ sub OnAuthenticated()
if authenticated <> invalid and authenticated = true if authenticated <> invalid and authenticated = true
currentUser = AboutMe() currentUser = AboutMe()
session.user.Login(currentUser) session.user.Login(currentUser)
LoadUserPreferences() session.user.LoadUserPreferences()
LoadUserAbilities() LoadUserAbilities()
m.top.close = true m.top.close = true
m.top.authenticated = true m.top.authenticated = true

View File

@ -90,7 +90,7 @@ function LoginFlow()
else else
print "Success! Auth token is still valid" print "Success! Auth token is still valid"
session.user.Login(currentUser) session.user.Login(currentUser)
LoadUserPreferences() session.user.LoadUserPreferences()
LoadUserAbilities() LoadUserAbilities()
return true return true
end if end if
@ -103,7 +103,7 @@ function LoginFlow()
if isValid(userData) if isValid(userData)
print "login success!" print "login success!"
session.user.Login(userData) session.user.Login(userData)
LoadUserPreferences() session.user.LoadUserPreferences()
LoadUserAbilities() LoadUserAbilities()
return true return true
else else
@ -146,7 +146,7 @@ function LoginFlow()
if isValid(userData) if isValid(userData)
print "login success!" print "login success!"
session.user.Login(userData) session.user.Login(userData)
LoadUserPreferences() session.user.LoadUserPreferences()
LoadUserAbilities() LoadUserAbilities()
return true return true
else else
@ -172,7 +172,7 @@ function LoginFlow()
goto start_login goto start_login
end if end if
LoadUserPreferences() session.user.LoadUserPreferences()
LoadUserAbilities() LoadUserAbilities()
m.global.sceneManager.callFunc("clearScenes") m.global.sceneManager.callFunc("clearScenes")

View File

@ -110,57 +110,6 @@ function GetPublicUsers()
return getJson(resp) return getJson(resp)
end function 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() sub LoadUserAbilities()
if m.global.session.user.Policy.EnableLiveTvManagement = true if m.global.session.user.Policy.EnableLiveTvManagement = true
set_user_setting("livetv.canrecord", "true") set_user_setting("livetv.canrecord", "true")

View File

@ -162,6 +162,59 @@ namespace session
end if end if
end sub 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 ' Empty the global user session array and reload defaults
sub Logout() sub Logout()
session.Update("user", { session.Update("user", {