2023-10-03 16:11:25 +00:00
import "pkg:/source/utils/misc.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/deviceCapabilities.bs"
2023-10-03 16:27:07 +00:00
import "pkg:/source/roku_modules/log/LogMixin.brs"
2020-06-10 16:43:32 +00:00
2023-05-03 21:21:04 +00:00
sub init()
m.log = log.Logger("ItemGrid")
2021-07-09 20:08:32 +00:00
m.options = m.top.findNode("options")
2022-05-14 10:13:28 +00:00
2023-06-01 12:43:27 +00:00
m.showItemCount = m.global.session.user.settings["itemgrid.showItemCount"]
2022-05-23 06:19:22 +00:00
2021-07-09 20:08:32 +00:00
m.tvGuide = invalid
2022-05-14 10:13:28 +00:00
m.channelFocused = 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
2022-12-30 16:11:19 +00:00
m.genreList = m.top.findNode("genrelist")
m.genreList.observeField("itemSelected", "onGenreItemSelected")
m.genreData = CreateObject("roSGNode", "ContentNode")
m.genreList.content = m.genreData
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")
2022-09-05 06:50:13 +00:00
m.itemGrid.observeField("alphaSelected", "onItemalphaSelected")
'Voice filter setup
m.voiceBox = m.top.findNode("voiceBox")
m.voiceBox.voiceEnabled = true
m.voiceBox.active = true
m.voiceBox.observeField("text", "onvoiceFilter")
'set voice help text
m.voiceBox.hintText = tr("Use voice remote to search")
'backdrop
2021-07-09 20:08:32 +00:00
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"
2022-05-14 10:13:28 +00:00
m.favorite = "Favorite"
2020-10-24 22:50:07 +00:00
2021-07-09 20:08:32 +00:00
m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2")
2022-05-23 06:19:22 +00:00
'set inital counts for overhang before content is loaded.
m.loadItemsTask.totalRecordCount = 0
2022-07-09 08:39:29 +00:00
2022-05-06 07:05:57 +00:00
m.spinner = m.top.findNode("spinner")
m.spinner.visible = true
2022-09-05 06:50:13 +00:00
2022-04-29 07:03:01 +00:00
m.Alpha = m.top.findNode("AlphaMenu")
m.AlphaSelected = m.top.findNode("AlphaSelected")
2022-06-10 03:15:35 +00:00
'Get reset folder setting
2023-06-01 12:43:27 +00:00
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]
2022-09-05 06:50:13 +00:00
m.micButton = m.top.findNode("micButton")
m.micButtonText = m.top.findNode("micButtonText")
'Hide voice search if device does not have voice remote
2023-03-27 16:50:44 +00:00
if m.global.device.hasVoiceRemote = false
2022-09-05 06:50:13 +00:00
m.micButton.visible = false
m.micButtonText.visible = false
end if
2020-06-10 16:43:32 +00:00
end sub
2022-12-30 16:11:19 +00:00
'
'Genre Item Selected
sub onGenreItemSelected()
m.top.selectedItem = m.genreList.content.getChild(m.genreList.rowItemSelected[0]).getChild(m.genreList.rowItemSelected[1])
end sub
2020-06-10 16:43:32 +00:00
'
'Load initial set of Data
2020-08-16 14:44:03 +00:00
sub loadInitialItems()
2022-09-05 06:50:13 +00:00
m.loadItemsTask.control = "stop"
m.spinner.visible = true
2022-07-09 08:39:29 +00:00
if m.top.parentItem.json.Type = "CollectionFolder" 'or m.top.parentItem.json.Type = "Folder"
m.top.HomeLibraryItem = m.top.parentItem.Id
end if
2022-09-05 06:50:13 +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
2023-06-01 12:43:27 +00:00
viewSetting = m.global.session.user.settings["display.livetv.landing"]
2022-09-05 06:50:13 +00:00
'Move mic to be visiable on TV Guide screen
2023-03-27 16:50:44 +00:00
if m.global.device.hasVoiceRemote = true
2022-09-05 06:50:13 +00:00
m.micButton.translation = "[1540, 92]"
m.micButtonText.visible = true
m.micButtonText.translation = "[1600,130]"
m.micButtonText.font.size = 22
m.micButtonText.text = tr("Search")
end if
2021-09-06 04:02:56 +00:00
if viewSetting = "guide"
m.view = "tvGuide"
else
m.view = "livetv"
end if
2023-06-01 12:43:27 +00:00
m.sortField = m.global.session.user.settings["display.livetv.sortField"]
sortAscendingStr = m.global.session.user.settings["display.livetv.sortAscending"]
m.filter = m.global.session.user.settings["display.livetv.filter"]
2022-06-07 00:31:57 +00:00
else if m.top.parentItem.collectionType = "music"
2023-06-01 12:43:27 +00:00
m.view = m.global.session.user.settings["display.music.view"]
m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
2021-09-06 04:02:56 +00:00
else
2023-06-01 12:43:27 +00:00
m.sortField = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortField"]
sortAscendingStr = m.global.session.user.settings["display." + m.top.parentItem.Id + ".sortAscending"]
m.filter = m.global.session.user.settings["display." + m.top.parentItem.Id + ".filter"]
m.view = m.global.session.user.settings["display." + m.top.parentItem.Id + ".landing"]
2021-09-06 04:02:56 +00:00
end if
2023-10-27 18:27:14 +00:00
if m.sortField = invalid
' Set the default order for boxsets to the Release Date - API calls it PremiereDate
if LCase(m.top.parentItem.json.Type) = "boxset"
m.sortField = "PremiereDate"
else
m.sortField = "SortName"
end if
end if
2021-09-06 04:02:56 +00:00
if m.filter = invalid then m.filter = "All"
2023-06-24 14:16:27 +00:00
if sortAscendingStr = invalid or sortAscendingStr = true
2021-09-06 04:02:56 +00:00
m.sortAscending = true
else
m.sortAscending = false
end if
2022-07-22 00:06:50 +00:00
' Set Studio Id
2022-07-09 08:39:29 +00:00
if m.top.parentItem.json.type = "Studio"
2022-07-22 00:06:50 +00:00
m.loadItemsTask.studioIds = m.top.parentItem.id
2022-07-09 08:39:29 +00:00
m.loadItemsTask.itemId = m.top.parentItem.parentFolder
m.loadItemsTask.genreIds = ""
2022-07-22 00:09:53 +00:00
' Set Genre Id
2022-07-09 08:39:29 +00:00
else if m.top.parentItem.json.type = "Genre"
2022-07-22 00:06:50 +00:00
m.loadItemsTask.genreIds = m.top.parentItem.id
2022-07-09 08:39:29 +00:00
m.loadItemsTask.itemId = m.top.parentItem.parentFolder
m.loadItemsTask.studioIds = ""
else if (m.view = "Shows" or m.options.view = "Shows") or (m.view = "Movies" or m.options.view = "Movies")
m.loadItemsTask.studioIds = ""
m.loadItemsTask.genreIds = ""
2022-07-22 00:06:50 +00:00
else
m.loadItemsTask.itemId = m.top.parentItem.Id
2022-07-09 08:39:29 +00:00
end if
updateTitle()
2021-09-06 04:02:56 +00:00
2022-09-05 06:50:13 +00:00
m.loadItemsTask.nameStartsWith = m.top.alphaSelected
m.loadItemsTask.searchTerm = m.voiceBox.text
2022-04-29 07:03:01 +00:00
m.emptyText.visible = false
2021-07-09 20:08:32 +00:00
m.loadItemsTask.sortField = m.sortField
m.loadItemsTask.sortAscending = m.sortAscending
m.loadItemsTask.filter = m.filter
m.loadItemsTask.startIndex = 0
2022-09-05 06:50:13 +00:00
2022-07-22 00:06:50 +00:00
' Load Item Types
2022-09-05 06:50:13 +00:00
if getCollectionType() = "movies"
2021-07-09 20:08:32 +00:00
m.loadItemsTask.itemType = "Movie"
2022-07-09 08:39:29 +00:00
m.loadItemsTask.itemId = m.top.parentItem.Id
2022-09-05 06:50:13 +00:00
else if getCollectionType() = "tvshows"
2021-07-09 20:08:32 +00:00
m.loadItemsTask.itemType = "Series"
2022-07-09 08:39:29 +00:00
m.loadItemsTask.itemId = m.top.parentItem.Id
2022-09-05 06:50:13 +00:00
else if getCollectionType() = "music"
2022-06-07 00:31:57 +00:00
' Default Settings
2022-09-27 01:26:17 +00:00
m.loadItemsTask.recursive = true
m.itemGrid.itemSize = "[290, 290]"
2022-09-05 06:50:13 +00:00
2022-09-27 01:26:17 +00:00
m.loadItemsTask.itemType = "MusicArtist"
2022-07-09 08:39:29 +00:00
m.loadItemsTask.itemId = m.top.parentItem.Id
2022-06-07 00:31:57 +00:00
2023-06-01 12:43:27 +00:00
m.view = m.global.session.user.settings["display.music.view"]
2022-06-07 00:31:57 +00:00
2022-09-27 01:26:17 +00:00
if m.view = "music-album"
2022-06-07 00:31:57 +00:00
m.loadItemsTask.itemType = "MusicAlbum"
end if
2021-07-09 20:08:32 +00:00
else if m.top.parentItem.collectionType = "livetv"
2022-09-05 06:50:13 +00:00
m.loadItemsTask.itemType = "TvChannel"
m.loadItemsTask.itemId = " "
2022-07-22 00:06:50 +00:00
' For LiveTV, we want to "Fit" the item images, not zoom
2021-07-09 20:08:32 +00:00
m.top.imageDisplayMode = "scaleToFit"
2023-06-01 12:43:27 +00:00
if m.global.session.user.settings["display.livetv.landing"] = "guide" and m.options.view <> "livetv"
2021-08-01 07:45:12 +00:00
showTvGuide()
2021-07-09 20:08:32 +00:00
end if
2022-09-05 06:50:13 +00:00
else if m.top.parentItem.collectionType = "CollectionFolder" or m.top.parentItem.type = "CollectionFolder" or m.top.parentItem.collectionType = "boxsets" or m.top.parentItem.Type = "Boxset" or m.top.parentItem.Type = "Boxsets" or m.top.parentItem.Type = "Folder" or m.top.parentItem.Type = "Channel"
if m.voiceBox.text <> ""
m.loadItemsTask.recursive = true
else
' non recursive for collections (folders, boxsets, photo albums, etc)
m.loadItemsTask.recursive = false
end if
2022-07-09 08:39:29 +00:00
else if m.top.parentItem.json.type = "Studio"
m.loadItemsTask.itemId = m.top.parentItem.parentFolder
m.loadItemsTask.itemType = "Series,Movie"
2021-07-09 20:08:32 +00:00
m.top.imageDisplayMode = "scaleToFit"
2022-07-09 08:39:29 +00:00
else if m.top.parentItem.json.type = "Genre"
m.loadItemsTask.itemType = "Series,Movie"
m.loadItemsTask.itemId = m.top.parentItem.parentFolder
2021-07-09 20:08:32 +00:00
else
2023-05-03 21:21:04 +00:00
m.log.warn("Unknown Item Type", m.top.parentItem)
2021-07-09 20:08:32 +00:00
end if
2022-07-22 00:09:53 +00:00
2022-07-09 08:39:29 +00:00
if m.top.parentItem.type <> "Folder" and (m.options.view = "Networks" or m.view = "Networks" or m.options.view = "Studios" or m.view = "Studios")
m.loadItemsTask.view = "Networks"
m.top.imageDisplayMode = "scaleToFit"
else if m.top.parentItem.type <> "Folder" and (m.options.view = "Genres" or m.view = "Genres")
m.loadItemsTask.StudioIds = m.top.parentItem.Id
m.loadItemsTask.view = "Genres"
else if m.top.parentItem.type <> "Folder" and (m.options.view = "Shows" or m.view = "Shows")
m.loadItemsTask.studioIds = ""
m.loadItemsTask.view = "Shows"
else if m.top.parentItem.type <> "Folder" and (m.options.view = "Movies" or m.view = "Movies")
m.loadItemsTask.studioIds = ""
m.loadItemsTask.view = "Movies"
end if
2020-06-15 16:05:48 +00:00
2021-07-09 20:08:32 +00:00
m.loadItemsTask.observeField("content", "ItemDataLoaded")
2022-07-09 08:39:29 +00:00
m.spinner.visible = true
2021-07-09 20:08:32 +00:00
m.loadItemsTask.control = "RUN"
SetUpOptions()
2020-08-16 14:44:03 +00:00
end sub
2022-06-10 12:33:54 +00:00
' Set Movies view, sort, and filter options
sub setMoviesOptions(options)
options.views = [
2022-07-09 08:39:29 +00:00
{ "Title": tr("Movies"), "Name": "Movies" },
{ "Title": tr("Studios"), "Name": "Studios" },
{ "Title": tr("Genres"), "Name": "Genres" }
2022-06-10 12:33:54 +00:00
]
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" },
2022-12-14 23:55:46 +00:00
{ "Title": tr("Favorites"), "Name": "Favorites" },
{ "Title": tr("Played"), "Name": "Played" },
2022-12-15 00:10:40 +00:00
{ "Title": tr("Unplayed"), "Name": "Unplayed" },
{ "Title": tr("Resumable"), "Name": "Resumable" }
2022-06-10 12:33:54 +00:00
]
end sub
' Set Boxset view, sort, and filter options
sub setBoxsetsOptions(options)
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" },
2022-12-14 23:55:46 +00:00
{ "Title": tr("Favorites"), "Name": "Favorites" },
{ "Title": tr("Played"), "Name": "Played" },
{ "Title": tr("Unplayed"), "Name": "Unplayed" }
2022-06-10 12:33:54 +00:00
]
end sub
' Set TV Show view, sort, and filter options
sub setTvShowsOptions(options)
2022-07-09 08:39:29 +00:00
options.views = [
{ "Title": tr("Shows"), "Name": "Shows" },
{ "Title": tr("Networks"), "Name": "Networks" },
{ "Title": tr("Genres"), "Name": "Genres" }
]
2022-06-10 12:33:54 +00:00
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" },
]
options.filter = [
{ "Title": tr("All"), "Name": "All" },
2022-12-14 23:55:46 +00:00
{ "Title": tr("Favorites"), "Name": "Favorites" },
{ "Title": tr("Played"), "Name": "Played" },
{ "Title": tr("Unplayed"), "Name": "Unplayed" }
2022-06-10 12:33:54 +00:00
]
2022-12-30 16:11:19 +00:00
2023-01-02 14:48:45 +00:00
if isValid(m.view)
if LCase(m.options.view) = "genres" or LCase(m.view) = "genres"
options.sort = [{ "Title": tr("TITLE"), "Name": "SortName" }]
options.filter = []
end if
2022-12-30 16:11:19 +00:00
end if
2022-06-10 12:33:54 +00:00
end sub
' Set Live TV view, sort, and filter options
sub setLiveTvOptions(options)
options.views = [
{ "Title": tr("Channels"), "Name": "livetv" },
{ "Title": tr("TV Guide"), "Name": "tvGuide" }
]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" }
]
options.filter = [
{ "Title": tr("All"), "Name": "All" },
{ "Title": tr("Favorites"), "Name": "Favorites" }
]
options.favorite = [
{ "Title": tr("Favorite"), "Name": "Favorite" }
]
end sub
' Set Music view, sort, and filter options
sub setMusicOptions(options)
2022-06-21 18:50:46 +00:00
options.views = [
{ "Title": tr("Artists"), "Name": "music-artist" },
{ "Title": tr("Albums"), "Name": "music-album" },
]
2022-06-10 12:33:54 +00:00
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" }
]
end sub
' Set Photo Album view, sort, and filter options
sub setPhotoAlbumOptions(options)
2022-11-19 14:29:57 +00:00
options.views = [
{ "Title": tr("Slideshow Off"), "Name": "singlephoto" }
{ "Title": tr("Slideshow On"), "Name": "slideshowphoto" }
2022-12-02 13:26:47 +00:00
{ "Title": tr("Random Off"), "Name": "singlephoto" }
{ "Title": tr("Random On"), "Name": "randomphoto" }
2022-11-19 14:29:57 +00:00
]
2022-06-10 12:33:54 +00:00
options.sort = []
2022-11-19 14:29:57 +00:00
options.filter = []
2022-06-10 12:33:54 +00:00
end sub
' Set Default view, sort, and filter options
sub setDefaultOptions(options)
options.views = [
{ "Title": tr("Default"), "Name": "default" }
]
options.sort = [
{ "Title": tr("TITLE"), "Name": "SortName" }
]
end sub
' Return parent collection type
function getCollectionType() as string
2022-06-19 14:08:43 +00:00
if m.top.parentItem.collectionType = invalid
2022-06-18 02:27:20 +00:00
return m.top.parentItem.Type
else
return m.top.parentItem.CollectionType
end if
2022-06-10 12:33:54 +00:00
end function
' Search string array for search value. Return if it's found
function inStringArray(array, searchValue) as boolean
for each item in array
if lcase(item) = lcase(searchValue) then return true
end for
return false
end function
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 = []
2022-05-14 10:13:28 +00:00
options.favorite = []
2022-07-09 08:39:29 +00:00
2022-06-10 12:33:54 +00:00
if getCollectionType() = "movies"
setMoviesOptions(options)
2022-06-19 14:08:43 +00:00
else if inStringArray(["boxsets", "Boxset"], getCollectionType())
2022-06-10 12:33:54 +00:00
setBoxsetsOptions(options)
else if getCollectionType() = "tvshows"
setTvShowsOptions(options)
else if getCollectionType() = "livetv"
setLiveTvOptions(options)
else if inStringArray(["photoalbum", "photo", "homevideos"], getCollectionType())
setPhotoAlbumOptions(options)
else if getCollectionType() = "music"
setMusicOptions(options)
2022-07-09 08:39:29 +00:00
2021-07-09 20:08:32 +00:00
else
2022-06-10 12:33:54 +00:00
setDefaultOptions(options)
2020-08-16 14:44:03 +00:00
end if
2022-06-10 12:33:54 +00:00
' Set selected view option
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
2022-06-10 12:33:54 +00:00
' Set selected sort option
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
2022-06-10 12:33:54 +00:00
' Set selected filter option
2021-07-09 20:08:32 +00:00
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-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)
2022-06-04 03:29:22 +00:00
m.top.alphaActive = false
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
2022-12-30 16:11:19 +00:00
if m.loadItemsTask.view = "Genres"
' Reset genre list data
m.genreData.removeChildren(m.genreData.getChildren(-1, 0))
for each item in itemData
m.genreData.appendChild(item)
end for
m.itemGrid.opacity = "0"
m.genreList.opacity = "1"
m.itemGrid.setFocus(false)
m.genreList.setFocus(true)
m.loading = false
m.spinner.visible = false
return
end if
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
2022-12-30 16:11:19 +00:00
m.itemGrid.opacity = "1"
m.genreList.opacity = "0"
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
'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)
2022-12-30 16:11:19 +00:00
m.genreList.setFocus(false)
2022-05-06 07:05:57 +00:00
m.spinner.visible = false
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()
2022-05-06 07:05:57 +00:00
focusedRow = m.itemGrid.currFocusRow
2020-06-10 16:43:32 +00:00
2021-07-09 20:08:32 +00:00
itemInt = m.itemGrid.itemFocused
2022-05-23 06:19:22 +00:00
updateTitle()
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
2022-05-14 10:13:28 +00:00
m.selectedFavoriteItem = m.itemGrid.content.getChild(m.itemGrid.itemFocused)
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
2022-07-09 08:39:29 +00:00
' Load more data if focus is within last 5 rows, and there are more items to load
2022-05-06 07:05:57 +00:00
if focusedRow >= m.loadedRows - 5 and m.loadeditems < m.loadItemsTask.totalRecordCount
2021-07-09 20:08:32 +00:00
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()
2022-07-09 08:39:29 +00:00
m.spinner.visible = true
2021-07-09 20:08:32 +00:00
if m.Loading = true then return
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
2022-09-05 06:50:13 +00:00
sub onItemalphaSelected()
if m.top.alphaSelected <> ""
m.loadedRows = 0
m.loadedItems = 0
m.data = CreateObject("roSGNode", "ContentNode")
m.itemGrid.content = m.data
m.loadItemsTask.searchTerm = ""
m.VoiceBox.text = ""
m.loadItemsTask.nameStartsWith = m.alpha.itemAlphaSelected
m.spinner.visible = true
loadInitialItems()
end if
end sub
sub onvoiceFilter()
if m.VoiceBox.text <> ""
m.loadedRows = 0
m.loadedItems = 0
m.data = CreateObject("roSGNode", "ContentNode")
m.itemGrid.content = m.data
m.top.alphaSelected = ""
m.loadItemsTask.NameStartsWith = " "
m.loadItemsTask.searchTerm = m.voiceBox.text
m.loadItemsTask.recursive = true
m.spinner.visible = true
loadInitialItems()
end if
2022-04-29 07:03:01 +00:00
end sub
2020-08-08 20:43:37 +00:00
2020-08-16 14:44:03 +00:00
'
'Check if options updated and any reloading required
sub optionsClosed()
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
2022-11-19 14:29:57 +00:00
if m.top.parentItem.Type = "CollectionFolder" or m.top.parentItem.Type = "Folder" or m.top.parentItem.CollectionType = "CollectionFolder"
2022-12-02 13:26:47 +00:00
' Did the user just request "Random" on a PhotoAlbum?
2022-02-06 17:10:29 +00:00
if m.options.view = "singlephoto"
2022-11-19 14:29:57 +00:00
set_user_setting("photos.slideshow", "false")
2022-12-02 13:26:47 +00:00
set_user_setting("photos.random", "false")
2022-11-19 14:29:57 +00:00
else if m.options.view = "slideshowphoto"
set_user_setting("photos.slideshow", "true")
2022-12-02 13:26:47 +00:00
set_user_setting("photos.random", "false")
else if m.options.view = "randomphoto"
set_user_setting("photos.random", "true")
2022-11-19 20:17:35 +00:00
set_user_setting("photos.slideshow", "false")
2022-02-06 17:10:29 +00:00
end if
end if
2021-07-09 20:08:32 +00:00
reload = false
2022-06-07 00:31:57 +00:00
if m.top.parentItem.collectionType = "music"
if m.options.view <> m.view
2022-10-02 18:23:42 +00:00
m.view = m.options.view
2022-06-07 00:31:57 +00:00
set_user_setting("display.music.view", m.view)
reload = true
end if
2022-07-09 08:39:29 +00:00
else
2023-06-01 12:43:27 +00:00
m.view = m.global.session.user.settings["display." + m.top.parentItem.Id + ".landing"]
2022-07-09 08:39:29 +00:00
if m.options.view <> m.view
'reload and store new view setting
m.view = m.options.view
set_user_setting("display." + m.top.parentItem.Id + ".landing", m.view)
reload = true
end if
2022-06-07 00:31:57 +00:00
end if
2021-07-09 20:08:32 +00:00
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
2022-12-30 16:11:19 +00:00
m.itemGrid.setFocus(m.itemGrid.opacity = 1)
m.genreList.setFocus(m.genreList.opacity = 1)
2021-09-06 20:03:30 +00:00
if m.tvGuide <> invalid
m.tvGuide.lastFocus.setFocus(true)
end if
2022-09-05 06:50:13 +00:00
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")
2022-05-14 10:13:28 +00:00
m.tvGuide.observeField("focusedChannel", "onChannelFocused")
2021-07-09 20:08:32 +00:00
end if
2021-09-06 04:02:56 +00:00
m.tvGuide.filter = m.filter
2022-09-05 06:50:13 +00:00
m.tvGuide.searchTerm = m.voiceBox.text
2021-07-09 20:08:32 +00:00
m.top.appendChild(m.tvGuide)
2023-09-24 01:31:01 +00:00
m.scheduleGrid = m.top.findNode("scheduleGrid")
2021-07-09 20:08:32 +00:00
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
2022-05-14 10:13:28 +00:00
sub onChannelFocused(msg)
node = msg.getRoSGNode()
m.channelFocused = node.focusedChannel
end sub
2023-09-23 16:32:50 +00:00
'Returns Focused Item
function getItemFocused()
if m.itemGrid.isinFocusChain() and isValid(m.itemGrid.itemFocused)
return m.itemGrid.content.getChild(m.itemGrid.itemFocused)
else if m.genreList.isinFocusChain() and isValid(m.genreList.rowItemFocused)
return m.genreList.content.getChild(m.genreList.rowItemFocused[0]).getChild(m.genreList.rowItemFocused[1])
2023-09-24 01:31:01 +00:00
else if m.scheduleGrid.isinFocusChain() and isValid(m.scheduleGrid.itemFocused)
return m.scheduleGrid.content.getChild(m.scheduleGrid.itemFocused)
2023-09-23 16:32:50 +00:00
end if
return invalid
end function
2020-08-08 20:43:37 +00:00
function onKeyEvent(key as string, press as boolean) as boolean
2021-07-09 20:08:32 +00:00
if not press then return false
2022-12-30 16:11:19 +00:00
if m.itemGrid.opacity = 1
topGrp = m.itemGrid
else
topGrp = m.genreList
end if
2022-09-05 06:50:13 +00:00
searchGrp = m.top.findNode("voiceBox")
if key = "left" and searchGrp.isinFocusChain()
topGrp.setFocus(true)
searchGrp.setFocus(false)
end if
2022-12-30 16:11:19 +00:00
2021-07-09 20:08:32 +00:00
if key = "options"
if m.options.visible = true
m.options.visible = false
m.top.removeChild(m.options)
optionsClosed()
else
2022-05-14 10:13:28 +00:00
channelSelected = m.channelFocused
itemSelected = m.selectedFavoriteItem
if itemSelected <> invalid
m.options.selectedFavoriteItem = itemSelected
end if
if channelSelected <> invalid
if channelSelected.type = "TvChannel"
m.options.selectedFavoriteItem = channelSelected
end if
end if
2021-07-09 20:08:32 +00:00
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
2022-09-05 06:50:13 +00:00
else
m.global.sceneManager.callfunc("popScene")
m.loadItemsTask.control = "stop"
return true
2021-07-09 20:08:32 +00:00
end if
2023-11-12 01:25:22 +00:00
else if key = "OK"
2022-09-05 06:50:13 +00:00
markupGrid = m.top.findNode("itemGrid")
2023-09-23 16:32:50 +00:00
itemToPlay = getItemFocused()
2022-04-29 07:03:01 +00:00
2023-11-12 01:25:22 +00:00
if itemToPlay <> invalid and itemToPlay.type = "Photo"
2022-02-06 17:10:29 +00:00
' Spawn photo player task
2022-11-19 05:57:40 +00:00
photoPlayer = CreateObject("roSgNode", "PhotoDetails")
2023-11-13 14:16:00 +00:00
photoPlayer.itemsNode = markupGrid
2022-11-19 05:57:40 +00:00
photoPlayer.itemIndex = markupGrid.itemFocused
m.global.sceneManager.callfunc("pushScene", photoPlayer)
2022-02-06 22:37:40 +00:00
return true
2021-07-09 20:08:32 +00:00
end if
2023-11-12 01:25:22 +00:00
else if key = "play"
itemToPlay = getItemFocused()
if itemToPlay <> invalid
m.top.quickPlayNode = itemToPlay
return true
end if
2022-06-03 02:06:05 +00:00
else if key = "left" and topGrp.isinFocusChain()
2022-06-04 03:29:22 +00:00
m.top.alphaActive = true
2022-04-29 07:03:01 +00:00
topGrp.setFocus(false)
2022-09-05 06:50:13 +00:00
alpha = m.alpha.getChild(0).findNode("Alphamenu")
2022-04-29 07:03:01 +00:00
alpha.setFocus(true)
return true
2022-09-05 06:50:13 +00:00
2022-06-03 02:06:05 +00:00
else if key = "right" and m.Alpha.isinFocusChain()
2022-06-04 03:29:22 +00:00
m.top.alphaActive = false
2022-04-29 07:03:01 +00:00
m.Alpha.setFocus(false)
m.Alpha.visible = true
topGrp.setFocus(true)
return true
2022-06-10 03:15:35 +00:00
else if key = "replay" and topGrp.isinFocusChain()
if m.resetGrid = true
2022-06-10 20:28:51 +00:00
m.itemGrid.animateToItem = 0
2022-06-10 03:15:35 +00:00
else
2022-06-10 20:28:51 +00:00
m.itemGrid.jumpToItem = 0
2022-06-10 03:15:35 +00:00
end if
2020-12-08 09:08:19 +00:00
end if
2022-06-10 20:28:51 +00:00
2022-09-05 06:50:13 +00:00
if key = "replay"
m.spinner.visible = true
m.loadItemsTask.searchTerm = ""
m.loadItemsTask.nameStartsWith = ""
m.voiceBox.text = ""
m.top.alphaSelected = ""
m.loadItemsTask.filter = "All"
m.filter = "All"
m.data = CreateObject("roSGNode", "ContentNode")
m.itemGrid.content = m.data
loadInitialItems()
return true
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()
2023-01-02 00:04:18 +00:00
m.top.overhangTitle = m.top.parentItem.title
if m.filter = "Favorites"
2022-05-23 06:19:22 +00:00
m.top.overhangTitle = m.top.parentItem.title + " " + tr("(Favorites)")
2022-04-29 07:03:01 +00:00
end if
2023-01-02 00:04:18 +00:00
2022-09-05 06:50:13 +00:00
if m.voiceBox.text <> ""
m.top.overhangTitle = m.top.parentItem.title + tr(" (Filtered by ") + m.loadItemsTask.searchTerm + ")"
end if
2023-01-02 00:04:18 +00:00
2022-09-05 06:50:13 +00:00
if m.top.alphaSelected <> ""
m.top.overhangTitle = m.top.parentItem.title + tr(" (Filtered by ") + m.loadItemsTask.nameStartsWith + ")"
2021-09-14 02:43:11 +00:00
end if
2022-05-23 06:19:22 +00:00
2022-10-02 18:23:42 +00:00
if m.view = "music-artist"
m.top.overhangTitle = "%s (%s)".Format(m.top.parentItem.title, tr("Artists"))
else if m.view = "music-album"
m.top.overhangTitle = "%s (%s)".Format(m.top.parentItem.title, tr("Albums"))
end if
2022-07-09 08:39:29 +00:00
if m.options.view = "Networks" or m.view = "Networks"
m.top.overhangTitle = "%s (%s)".Format(m.top.parentItem.title, tr("Networks"))
end if
2023-01-02 00:04:18 +00:00
2022-07-09 08:39:29 +00:00
if m.options.view = "Studios" or m.view = "Studios"
m.top.overhangTitle = "%s (%s)".Format(m.top.parentItem.title, tr("Studios"))
end if
2023-01-02 00:04:18 +00:00
2022-07-09 08:39:29 +00:00
if m.options.view = "Genres" or m.view = "Genres"
m.top.overhangTitle = "%s (%s)".Format(m.top.parentItem.title, tr("Genres"))
end if
2023-01-02 00:04:18 +00:00
2022-05-23 06:19:22 +00:00
actInt = m.itemGrid.itemFocused + 1
2023-01-02 00:04:18 +00:00
if m.showItemCount and m.loadItemsTask.totalRecordCount > 0 and m.options.view <> "Genres" and m.view <> "Genres"
2022-05-23 06:19:22 +00:00
m.top.overhangTitle += " (" + tr("%1 of %2").Replace("%1", actInt.toStr()).Replace("%2", m.loadItemsTask.totalRecordCount.toStr()) + ")"
end if
2022-03-13 08:46:03 +00:00
end sub