2020-06-10 16:43:32 +00:00
sub init()
2021-07-09 20:08:32 +00:00
m.options = m.top.findNode("options")
m.tvGuide = invalid
2020-08-08 20:43:37 +00:00
2021-07-09 20:08:32 +00:00
m.itemGrid = m.top.findNode("itemGrid")
m.backdrop = m.top.findNode("backdrop")
m.newBackdrop = m.top.findNode("backdropTransition")
m.emptyText = m.top.findNode("emptyText")
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.swapAnimation = m.top.findNode("backroundSwapAnimation")
m.swapAnimation.observeField("state", "swapDone")
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
m.loadedRows = 0
m.loadedItems = 0
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.data = CreateObject("roSGNode", "ContentNode")
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.itemGrid.content = m.data
m.itemGrid.setFocus(true)
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.itemGrid.observeField("itemFocused", "onItemFocused")
m.itemGrid.observeField("itemSelected", "onItemSelected")
m.newBackdrop.observeField("loadStatus", "newBGLoaded")
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
'Background Image Queued for loading
m.queuedBGUri = ""
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
'Item sort - maybe load defaults from user prefs?
m.sortField = "SortName"
m.sortAscending = true
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
m.filter = "All"
2020-10-24 22:50:07 +00:00
2021-07-09 20:08:32 +00:00
m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2")
2020-08-16 14:44:03 +00:00
2020-06-10 16:43:32 +00:00
end sub
'
'Load initial set of Data
2020-08-16 14:44:03 +00:00
sub loadInitialItems()
2020-06-15 16:05:48 +00:00
2021-07-09 20:08:32 +00:00
if m.top.parentItem.backdropUrl <> invalid
SetBackground(m.top.parentItem.backdropUrl)
2020-11-29 11:18:23 +00:00
end if
2021-09-06 04:02:56 +00:00
' Read view/sort/filter settings
if m.top.parentItem.collectionType = "livetv"
' Translate between app and server nomenclature
viewSetting = get_user_setting("display.livetv.landing")
if viewSetting = "guide"
m.view = "tvGuide"
else
m.view = "livetv"
end if
m.sortField = get_user_setting("display.livetv.sortField")
sortAscendingStr = get_user_setting("display.livetv.sortAscending")
m.filter = get_user_setting("display.livetv.filter")
else
m.view = invalid
m.sortField = get_user_setting("display." + m.top.parentItem.Id + ".sortField")
sortAscendingStr = get_user_setting("display." + m.top.parentItem.Id + ".sortAscending")
m.filter = get_user_setting("display." + m.top.parentItem.Id + ".filter")
end if
if m.sortField = invalid then m.sortField = "SortName"
if m.filter = invalid then m.filter = "All"
if sortAscendingStr = invalid or sortAscendingStr = "true"
m.sortAscending = true
else
m.sortAscending = false
end if
2021-09-14 02:43:11 +00:00
updateTitle()
2021-07-09 20:08:32 +00:00
m.loadItemsTask.itemId = m.top.parentItem.Id
m.loadItemsTask.sortField = m.sortField
m.loadItemsTask.sortAscending = m.sortAscending
m.loadItemsTask.filter = m.filter
m.loadItemsTask.startIndex = 0
if m.top.parentItem.collectionType = "movies"
m.loadItemsTask.itemType = "Movie"
else if m.top.parentItem.collectionType = "tvshows"
m.loadItemsTask.itemType = "Series"
else if m.top.parentItem.collectionType = "livetv"
m.loadItemsTask.itemType = "LiveTV"
'For LiveTV, we want to "Fit" the item images, not zoom
m.top.imageDisplayMode = "scaleToFit"
2021-08-01 07:45:12 +00:00
if get_user_setting("display.livetv.landing") = "guide" and m.options.view <> "livetv"
showTvGuide()
2021-07-09 20:08:32 +00:00
end if
else if m.top.parentItem.collectionType = "CollectionFolder" or m.top.parentItem.collectionType = "boxsets" or m.top.parentItem.Type = "Folder" or m.top.parentItem.Type = "Channel"
' Non-recursive, to not show subfolder contents
m.loadItemsTask.recursive = false
else if m.top.parentItem.collectionType = "Channel"
m.top.imageDisplayMode = "scaleToFit"
else
print "[ItemGrid] Unknown Type: " m.top.parentItem
end if
2020-06-15 16:05:48 +00:00
2021-07-09 20:08:32 +00:00
m.loadItemsTask.observeField("content", "ItemDataLoaded")
m.loadItemsTask.control = "RUN"
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
SetUpOptions()
2020-08-16 14:44:03 +00:00
end sub
2020-08-16 16:17:41 +00:00
' Data to display when options button selected
2020-08-16 14:44:03 +00:00
sub SetUpOptions()
2021-07-09 20:08:32 +00:00
options = {}
2020-10-30 17:23:28 +00:00
options.filter = []
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
'Movies
if m.top.parentItem.collectionType = "movies"
options.views = [
{ "Title": tr("Movies"), "Name": "movies" },
]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" },
{ "Title": tr("IMDB_RATING"), "Name": "CommunityRating" },
{ "Title": tr("CRITIC_RATING"), "Name": "CriticRating" },
{ "Title": tr("DATE_ADDED"), "Name": "DateCreated" },
{ "Title": tr("DATE_PLAYED"), "Name": "DatePlayed" },
{ "Title": tr("OFFICIAL_RATING"), "Name": "OfficialRating" },
{ "Title": tr("PLAY_COUNT"), "Name": "PlayCount" },
{ "Title": tr("RELEASE_DATE"), "Name": "PremiereDate" },
{ "Title": tr("RUNTIME"), "Name": "Runtime" }
]
options.filter = [
{ "Title": tr("All"), "Name": "All" },
{ "Title": tr("Favorites"), "Name": "Favorites" }
]
'Boxsets
else if m.top.parentItem.collectionType = "boxsets"
options.views = [{ "Title": tr("Shows"), "Name": "shows" }]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" },
{ "Title": tr("DATE_ADDED"), "Name": "DateCreated" },
{ "Title": tr("DATE_PLAYED"), "Name": "DatePlayed" },
{ "Title": tr("RELEASE_DATE"), "Name": "PremiereDate" },
]
options.filter = [
{ "Title": tr("All"), "Name": "All" },
{ "Title": tr("Favorites"), "Name": "Favorites" }
]
'TV Shows
else if m.top.parentItem.collectionType = "tvshows"
options.views = [{ "Title": tr("Shows"), "Name": "shows" }]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" },
{ "Title": tr("IMDB_RATING"), "Name": "CommunityRating" },
{ "Title": tr("DATE_ADDED"), "Name": "DateCreated" },
{ "Title": tr("DATE_PLAYED"), "Name": "DatePlayed" },
{ "Title": tr("OFFICIAL_RATING"), "Name": "OfficialRating" },
{ "Title": tr("RELEASE_DATE"), "Name": "PremiereDate" },
]
2021-08-01 08:15:46 +00:00
options.filter = [
{ "Title": tr("All"), "Name": "All" },
{ "Title": tr("Favorites"), "Name": "Favorites" }
]
2021-07-09 20:08:32 +00:00
'Live TV
else if m.top.parentItem.collectionType = "livetv"
options.views = [
{ "Title": tr("Channels"), "Name": "livetv" },
2021-09-06 04:02:56 +00:00
{ "Title": tr("TV Guide"), "Name": "tvGuide" }
2021-07-09 20:08:32 +00:00
]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" }
]
2021-08-01 08:15:46 +00:00
options.filter = [
{ "Title": tr("All"), "Name": "All" },
{ "Title": tr("Favorites"), "Name": "Favorites" }
]
2021-07-09 20:08:32 +00:00
else
options.views = [
{ "Title": tr("Default"), "Name": "default" }
]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" }
]
options.filter = []
2020-08-16 14:44:03 +00:00
end if
2021-09-06 04:02:56 +00:00
for each o in options.views
if o.Name = m.view
o.Selected = true
o.Ascending = m.sortAscending
m.options.view = o.Name
end if
end for
2021-07-09 20:08:32 +00:00
for each o in options.sort
if o.Name = m.sortField
o.Selected = true
o.Ascending = m.sortAscending
2021-09-06 04:02:56 +00:00
m.options.sortField = o.Name
2021-07-09 20:08:32 +00:00
end if
end for
for each o in options.filter
if o.Name = m.filter
o.Selected = true
2021-09-06 04:02:56 +00:00
m.options.filter = o.Name
2021-07-09 20:08:32 +00:00
end if
end for
2020-10-24 22:59:41 +00:00
2021-07-09 20:08:32 +00:00
m.options.options = options
2020-08-16 14:44:03 +00:00
2020-06-10 16:43:32 +00:00
end sub
2020-08-16 14:44:03 +00:00
2020-06-10 16:43:32 +00:00
'
'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
if itemData = invalid
m.Loading = false
return
end if
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
for each item in itemData
m.data.appendChild(item)
end for
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
'Update the stored counts
m.loadedItems = m.itemGrid.content.getChildCount()
m.loadedRows = m.loadedItems / m.itemGrid.numColumns
m.Loading = false
2020-07-11 13:37:33 +00:00
2021-07-09 20:08:32 +00:00
'If there are no items to display, show message
if m.loadedItems = 0
m.emptyText.text = tr("NO_ITEMS").Replace("%1", m.top.parentItem.Type)
m.emptyText.visible = true
end if
2020-07-11 13:37:33 +00:00
2021-07-09 20:08:32 +00:00
m.itemGrid.setFocus(true)
2020-07-11 13:37:33 +00:00
2020-06-10 16:43:32 +00:00
end sub
'
'Set Background Image
sub SetBackground(backgroundUri as string)
2021-07-09 20:08:32 +00:00
'If a new image is being loaded, or transitioned to, store URL to load next
if m.swapAnimation.state <> "stopped" or m.newBackdrop.loadStatus = "loading"
m.queuedBGUri = backgroundUri
return
end if
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.newBackdrop.uri = backgroundUri
2020-06-10 16:43:32 +00:00
end sub
'
'Handle new item being focused
sub onItemFocused()
2021-07-09 20:08:32 +00:00
focusedRow = CInt(m.itemGrid.itemFocused / m.itemGrid.numColumns) + 1
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
itemInt = m.itemGrid.itemFocused
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
' If no selected item, set background to parent backdrop
if itemInt = -1
return
end if
2020-07-11 13:37:33 +00:00
2021-07-09 20:08:32 +00:00
' Set Background to item backdrop
SetBackground(m.itemGrid.content.getChild(m.itemGrid.itemFocused).backdropUrl)
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
' Load more data if focus is within last 3 rows, and there are more items to load
if focusedRow >= m.loadedRows - 3 and m.loadeditems < m.loadItemsTask.totalRecordCount
loadMoreData()
end if
2020-08-16 14:44:03 +00:00
end sub
2020-06-10 16:43:32 +00:00
'
'When Image Loading Status changes
sub newBGLoaded()
2021-07-09 20:08:32 +00:00
'If image load was sucessful, start the fade swap
if m.newBackdrop.loadStatus = "ready"
m.swapAnimation.control = "start"
end if
2020-06-10 16:43:32 +00:00
end sub
'
'Swap Complete
sub swapDone()
2021-07-09 20:08:32 +00:00
if m.swapAnimation.state = "stopped"
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
'Set main BG node image and hide transitioning node
m.backdrop.uri = m.newBackdrop.uri
m.backdrop.opacity = 0.25
m.newBackdrop.opacity = 0
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
'If there is another one to load
if m.newBackdrop.uri <> m.queuedBGUri and m.queuedBGUri <> ""
SetBackground(m.queuedBGUri)
m.queuedBGUri = ""
end if
2020-06-10 16:43:32 +00:00
end if
end sub
'
'Load next set of items
sub loadMoreData()
2021-07-09 20:08:32 +00:00
if m.Loading = true then return
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
m.Loading = true
m.loadItemsTask.startIndex = m.loadedItems
m.loadItemsTask.observeField("content", "ItemDataLoaded")
m.loadItemsTask.control = "RUN"
2020-06-10 16:43:32 +00:00
end sub
'
'Item Selected
sub onItemSelected()
2021-07-09 20:08:32 +00:00
m.top.selectedItem = m.itemGrid.content.getChild(m.itemGrid.itemSelected)
2020-08-08 20:43:37 +00:00
end sub
2020-08-16 14:44:03 +00:00
'
'Check if options updated and any reloading required
sub optionsClosed()
2020-11-23 17:13:57 +00:00
2021-09-06 04:02:56 +00:00
if m.top.parentItem.collectionType = "livetv" and m.options.view <> m.view
if m.options.view = "tvGuide"
m.view = "tvGuide"
set_user_setting("display.livetv.landing", "guide")
showTVGuide()
return
else
m.view = "livetv"
set_user_setting("display.livetv.landing", "channels")
if m.tvGuide <> invalid
' Try to hide the TV Guide
m.top.removeChild(m.tvGuide)
end if
end if
2021-07-09 20:08:32 +00:00
end if
reload = false
if m.options.sortField <> m.sortField or m.options.sortAscending <> m.sortAscending
m.sortField = m.options.sortField
m.sortAscending = m.options.sortAscending
reload = true
2021-09-06 04:02:56 +00:00
'Store sort settings
if m.sortAscending = true
sortAscendingStr = "true"
else
sortAscendingStr = "false"
end if
if m.top.parentItem.collectionType = "livetv"
set_user_setting("display.livetv.sortField", m.sortField)
set_user_setting("display.livetv.sortAscending", sortAscendingStr)
else
set_user_setting("display." + m.top.parentItem.Id + ".sortField", m.sortField)
set_user_setting("display." + m.top.parentItem.Id + ".sortAscending", sortAscendingStr)
end if
2021-07-09 20:08:32 +00:00
end if
if m.options.filter <> m.filter
m.filter = m.options.filter
2021-09-14 02:43:11 +00:00
updateTitle()
2021-07-09 20:08:32 +00:00
reload = true
2021-09-06 04:02:56 +00:00
'Store filter setting
if m.top.parentItem.collectionType = "livetv"
set_user_setting("display.livetv.filter", m.options.filter)
else
set_user_setting("display." + m.top.parentItem.Id + ".filter", m.options.filter)
end if
2021-07-09 20:08:32 +00:00
end if
if reload
m.loadedRows = 0
m.loadedItems = 0
m.data = CreateObject("roSGNode", "ContentNode")
m.itemGrid.content = m.data
loadInitialItems()
end if
m.itemGrid.setFocus(true)
2021-09-06 20:03:30 +00:00
if m.tvGuide <> invalid
m.tvGuide.lastFocus.setFocus(true)
end if
2020-08-16 14:44:03 +00:00
end sub
2021-08-01 07:45:12 +00:00
sub showTVGuide()
2021-07-09 20:08:32 +00:00
if m.tvGuide = invalid
m.tvGuide = createObject("roSGNode", "Schedule")
2021-08-01 08:24:57 +00:00
m.top.signalBeacon("EPGLaunchInitiate") ' Required Roku Performance monitoring
2021-09-05 19:17:43 +00:00
m.tvGuide.observeField("watchChannel", "onChannelSelected")
2021-07-09 20:08:32 +00:00
end if
2021-09-06 04:02:56 +00:00
m.tvGuide.filter = m.filter
2021-07-09 20:08:32 +00:00
m.top.appendChild(m.tvGuide)
m.tvGuide.lastFocus.setFocus(true)
2020-11-29 11:18:23 +00:00
end sub
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
sub onChannelSelected(msg)
node = msg.getRoSGNode()
m.top.lastFocus = lastFocusedChild(node)
if node.watchChannel <> invalid
' Clone the node when it's reused/update in the TimeGrid it doesn't automatically start playing
m.top.selectedItem = node.watchChannel.clone(false)
end if
2020-11-23 17:13:57 +00:00
end sub
2020-08-08 20:43:37 +00:00
function onKeyEvent(key as string, press as boolean) as boolean
2020-08-16 14:44:03 +00:00
2021-07-09 20:08:32 +00:00
if not press then return false
if key = "options"
if m.options.visible = true
m.options.visible = false
m.top.removeChild(m.options)
optionsClosed()
else
m.options.visible = true
m.top.appendChild(m.options)
m.options.setFocus(true)
end if
return true
else if key = "back"
if m.options.visible = true
m.options.visible = false
optionsClosed()
return true
end if
else if key = "play"
markupGrid = m.top.getChild(2)
itemToPlay = markupGrid.content.getChild(markupGrid.itemFocused)
if itemToPlay <> invalid and (itemToPlay.type = "Movie" or itemToPlay.type = "Episode")
m.top.quickPlayNode = itemToPlay
end if
return true
2020-12-08 09:08:19 +00:00
end if
2021-07-09 20:08:32 +00:00
return false
2020-08-08 20:43:37 +00:00
end function
2021-09-14 02:43:11 +00:00
sub updateTitle()
if m.filter = "All"
m.top.overhangTitle = m.top.parentItem.title
else if m.filter = "Favorites"
m.top.overhangTitle = m.top.parentItem.title + " (Favorites)"
else
m.top.overhangTitle = m.top.parentItem.title + " (Filtered)"
end if
end sub