2020-06-10 16:43:32 +00:00
|
|
|
sub init()
|
|
|
|
|
2020-08-08 20:43:37 +00:00
|
|
|
m.options = m.top.findNode("options")
|
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
m.itemGrid = m.top.findNode("itemGrid")
|
|
|
|
m.backdrop = m.top.findNode("backdrop")
|
|
|
|
m.newBackdrop = m.top.findNode("backdropTransition")
|
2020-07-11 13:37:33 +00:00
|
|
|
m.emptyText = m.top.findNode("emptyText")
|
2020-06-10 16:43:32 +00:00
|
|
|
|
|
|
|
m.swapAnimation = m.top.findNode("backroundSwapAnimation")
|
|
|
|
m.swapAnimation.observeField("state", "swapDone")
|
2020-08-16 14:44:03 +00:00
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
m.loadedRows = 0
|
|
|
|
m.loadedItems = 0
|
|
|
|
|
|
|
|
m.data = CreateObject("roSGNode", "ContentNode")
|
|
|
|
|
|
|
|
m.itemGrid.content = m.data
|
|
|
|
m.itemGrid.setFocus(true)
|
|
|
|
|
|
|
|
m.itemGrid.observeField("itemFocused", "onItemFocused")
|
|
|
|
m.itemGrid.observeField("itemSelected", "onItemSelected")
|
|
|
|
m.newBackdrop.observeField("loadStatus", "newBGLoaded")
|
|
|
|
|
|
|
|
'Background Image Queued for loading
|
|
|
|
m.queuedBGUri = ""
|
|
|
|
|
2020-08-16 14:44:03 +00:00
|
|
|
'Item sort - maybe load defaults from user prefs?
|
|
|
|
m.sortField = "SortName"
|
|
|
|
m.sortAscending = true
|
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2")
|
2020-08-16 14:44:03 +00:00
|
|
|
m.loadItemsTask.observeField("content", "ItemDataLoaded")
|
|
|
|
|
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
|
|
|
|
2020-07-11 13:37:33 +00:00
|
|
|
if m.top.parentItem.backdropUrl <> invalid then
|
|
|
|
SetBackground(m.top.parentItem.backdropUrl)
|
|
|
|
end if
|
|
|
|
|
2020-06-15 16:05:48 +00:00
|
|
|
m.loadItemsTask.itemId = m.top.parentItem.Id
|
2020-08-16 14:44:03 +00:00
|
|
|
m.loadItemsTask.sortField = m.sortField
|
|
|
|
m.loadItemsTask.sortAscending = m.sortAscending
|
|
|
|
m.loadItemsTask.startIndex = 0
|
2020-06-15 16:05:48 +00:00
|
|
|
|
|
|
|
if m.top.parentItem.collectionType = "movies" then
|
|
|
|
m.loadItemsTask.itemType = "Movie"
|
|
|
|
else if m.top.parentItem.collectionType = "tvshows" then
|
|
|
|
m.loadItemsTask.itemType = "Series"
|
|
|
|
end if
|
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
m.loadItemsTask.control = "RUN"
|
2020-08-16 14:44:03 +00:00
|
|
|
|
|
|
|
SetUpOptions()
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
|
2020-08-16 16:17:41 +00:00
|
|
|
'Movies
|
2020-08-16 14:44:03 +00:00
|
|
|
if m.top.parentItem.collectionType = "movies" then
|
|
|
|
options.views = [{ "Title": tr("Movies"), "Name": "movies" }]
|
|
|
|
options.sort = [
|
2020-08-17 15:48:23 +00:00
|
|
|
{ "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" }
|
2020-08-16 14:44:03 +00:00
|
|
|
]
|
2020-08-16 16:17:41 +00:00
|
|
|
'TV Shows
|
2020-08-16 14:44:03 +00:00
|
|
|
else if m.top.parentItem.collectionType = "tvshows" then
|
|
|
|
options.views = [{ "Title": tr("Shows"), "Name": "shows" }]
|
|
|
|
options.sort = [
|
2020-08-17 15:48:23 +00:00
|
|
|
{ "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" },
|
2020-08-16 14:44:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
for each o in options.sort
|
|
|
|
if o.Name = m.sortField then
|
|
|
|
o.Selected = true
|
|
|
|
o.Ascending = m.sortAscending
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
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)
|
2020-08-16 14:44:03 +00:00
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
itemData = msg.GetData()
|
|
|
|
data = msg.getField()
|
|
|
|
|
2020-08-16 14:44:03 +00:00
|
|
|
if itemData = invalid then
|
2020-06-10 16:43:32 +00:00
|
|
|
m.Loading = false
|
2020-08-16 14:44:03 +00:00
|
|
|
return
|
2020-06-10 16:43:32 +00:00
|
|
|
end if
|
|
|
|
|
|
|
|
for each item in itemData
|
|
|
|
m.data.appendChild(item)
|
|
|
|
end for
|
|
|
|
|
|
|
|
'Update the stored counts
|
2020-08-16 14:44:03 +00:00
|
|
|
m.loadedItems = m.itemGrid.content.getChildCount()
|
2020-06-10 16:43:32 +00:00
|
|
|
m.loadedRows = m.loadedItems / m.itemGrid.numColumns
|
|
|
|
m.Loading = false
|
2020-07-11 13:37:33 +00:00
|
|
|
|
|
|
|
'If there are no items to display, show message
|
|
|
|
if m.loadedItems = 0 then
|
|
|
|
m.emptyText.text = tr("NO_ITEMS").Replace("%1", m.top.parentItem.Type)
|
|
|
|
m.emptyText.visible = true
|
|
|
|
end if
|
|
|
|
|
|
|
|
m.itemGrid.setFocus(true)
|
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
'
|
|
|
|
'Set Background Image
|
|
|
|
sub SetBackground(backgroundUri as string)
|
|
|
|
|
|
|
|
'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" then
|
|
|
|
m.queuedBGUri = backgroundUri
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
m.newBackdrop.uri = backgroundUri
|
|
|
|
end sub
|
|
|
|
|
|
|
|
'
|
|
|
|
'Handle new item being focused
|
|
|
|
sub onItemFocused()
|
|
|
|
|
|
|
|
focusedRow = CInt(m.itemGrid.itemFocused / m.itemGrid.numColumns) + 1
|
|
|
|
|
|
|
|
itemInt = m.itemGrid.itemFocused
|
|
|
|
|
2020-07-11 13:37:33 +00:00
|
|
|
' If no selected item, set background to parent backdrop
|
|
|
|
if itemInt = -1 then
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
' Set Background to item backdrop
|
2020-06-10 16:43:32 +00:00
|
|
|
SetBackground(m.itemGrid.content.getChild(m.itemGrid.itemFocused).backdropUrl)
|
|
|
|
|
|
|
|
' 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 then
|
|
|
|
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()
|
|
|
|
'If image load was sucessful, start the fade swap
|
|
|
|
if m.newBackdrop.loadStatus = "ready"
|
|
|
|
m.swapAnimation.control = "start"
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
'
|
|
|
|
'Swap Complete
|
|
|
|
sub swapDone()
|
|
|
|
|
|
|
|
if m.swapAnimation.state = "stopped" then
|
2020-08-16 14:44:03 +00:00
|
|
|
|
2020-06-10 16:43: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
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
'If there is another one to load
|
2020-08-16 14:44:03 +00:00
|
|
|
if m.newBackdrop.uri <> m.queuedBGUri and m.queuedBGUri <> "" then
|
|
|
|
SetBackground(m.queuedBGUri)
|
|
|
|
m.queuedBGUri = ""
|
2020-06-10 16:43:32 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
'
|
|
|
|
'Load next set of items
|
|
|
|
sub loadMoreData()
|
|
|
|
|
|
|
|
if m.Loading = true then return
|
|
|
|
|
|
|
|
m.Loading = true
|
|
|
|
m.loadItemsTask.startIndex = m.loadedItems
|
|
|
|
m.loadItemsTask.control = "RUN"
|
|
|
|
end sub
|
|
|
|
|
|
|
|
'
|
|
|
|
'Item Selected
|
|
|
|
sub onItemSelected()
|
|
|
|
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()
|
|
|
|
if m.options.sortField <> m.sortField or m.options.sortAscending <> m.sortAscending then
|
|
|
|
m.sortField = m.options.sortField
|
|
|
|
m.sortAscending = m.options.sortAscending
|
|
|
|
m.loadedRows = 0
|
|
|
|
m.loadedItems = 0
|
|
|
|
m.data = CreateObject("roSGNode", "ContentNode")
|
|
|
|
m.itemGrid.content = m.data
|
|
|
|
loadInitialItems()
|
|
|
|
end if
|
|
|
|
m.itemGrid.setFocus(true)
|
|
|
|
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
|
|
|
|
|
|
|
if not press then return false
|
|
|
|
|
|
|
|
if key = "options"
|
|
|
|
if m.options.visible = true then
|
|
|
|
m.options.visible = false
|
|
|
|
optionsClosed()
|
|
|
|
else
|
|
|
|
m.options.visible = true
|
|
|
|
m.options.setFocus(true)
|
|
|
|
end if
|
|
|
|
return true
|
|
|
|
else if key = "back" then
|
|
|
|
if m.options.visible = true then
|
|
|
|
m.options.visible = false
|
|
|
|
optionsClosed()
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
end if
|
2020-08-08 20:43:37 +00:00
|
|
|
return false
|
|
|
|
end function
|