make photos work from homescreen

This commit is contained in:
Charles Ewert 2023-11-13 09:16:00 -05:00
parent 92cdeb4155
commit 88bc02b8b3
9 changed files with 154 additions and 16 deletions

View File

@ -808,7 +808,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
if itemToPlay <> invalid and itemToPlay.type = "Photo"
' Spawn photo player task
photoPlayer = CreateObject("roSgNode", "PhotoDetails")
photoPlayer.items = markupGrid
photoPlayer.itemsNode = markupGrid
photoPlayer.itemIndex = markupGrid.itemFocused
m.global.sceneManager.callfunc("pushScene", photoPlayer)
return true

View File

@ -72,7 +72,7 @@ sub setData()
m.top.widePosterUrl = ImageURL(datum.Id, "Backdrop", imgParams)
end if
else if datum.type = "Movie" or datum.type = "Video"
else if datum.type = "Movie"
m.top.isWatched = datum.UserData.Played
imgParams = {}
@ -96,6 +96,20 @@ sub setData()
imgParams["Tag"] = datum.BackdropImageTags[0]
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
end if
else if datum.type = "Video"
m.top.isWatched = datum.UserData.Played
imgParams = {
"maxHeight": 261,
"maxWidth": 464
}
if datum.ImageTags <> invalid and datum.ImageTags.Primary <> invalid
imgParams.Append({ "Tag": datum.ImageTags.Primary })
end if
m.top.posterURL = ImageURL(datum.id, "Primary", imgParams)
m.top.thumbnailUrl = m.top.posterURL
else if datum.type = "MusicAlbum"
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 261 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
@ -106,5 +120,17 @@ sub setData()
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.iconUrl = "pkg:/images/media_type_icons/live_tv_white.png"
else if datum.type = "Photo"
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.posterUrl = m.top.thumbnailURL
else if datum.type = "PhotoAlbum"
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.posterUrl = m.top.thumbnailURL
end if
end sub

View File

@ -30,6 +30,13 @@ end sub
sub itemContentChanged()
itemData = m.top.itemContent
if itemData = invalid then return
print "itemData=", itemData
if itemData.json <> invalid
print "itemData.json=", itemData.json
if itemData.json.UserData <> invalid
print "itemData.json.UserData=", itemData.json.UserData
end if
end if
itemData.Title = itemData.name ' Temporarily required while we move from "HomeItem" to "JFContentItem"
@ -261,6 +268,34 @@ sub itemContentChanged()
return
end if
if itemData.type = "Photo"
m.itemText.text = itemData.name
m.itemTextExtra.text = ""
m.itemPoster.uri = ImageURL(itemData.id)
' subtext
if isValidAndNotEmpty(itemData.json)
if isValidAndNotEmpty(itemData.json.ProductionYear)
m.itemTextExtra.text = tr("Year") + ": " + itemData.json.ProductionYear.ToStr().trim()
end if
if isValidAndNotEmpty(itemData.json.Album)
if m.itemTextExtra.text = ""
m.itemTextExtra.text = tr("Album") + ": " + itemData.json.Album.trim()
else
m.itemTextExtra.text = m.itemTextExtra.text + " - " + tr("Album") + ": " + itemData.json.Album.trim()
end if
end if
end if
return
end if
if itemData.type = "PhotoAlbum"
m.itemText.text = itemData.name
m.itemPoster.uri = ImageURL(itemData.id)
return
end if
m.log.warn("Unhandled Home Item Type", itemData.type)
end sub

View File

@ -1,20 +1,28 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/misc.bs"
sub init()
m.top.functionName = "loadItems"
end sub
sub loadItems()
item = m.top.itemContent
if item <> invalid
params = {
maxHeight: 1080,
maxWidth: 1920
}
params = {
maxHeight: 1080,
maxWidth: 1920
}
if isValid(m.top.itemNodeContent)
item = m.top.itemNodeContent
m.top.results = ImageURL(item.Id, "Primary", params)
else if isValid(m.top.itemArrayContent)
item = m.top.itemArrayContent
m.top.results = ImageURL(item.Id, "Primary", params)
else
m.top.results = invalid
end if
end sub

View File

@ -2,7 +2,8 @@
<component name="LoadPhotoTask" extends="Task">
<interface>
<field id="itemContent" type="node" />
<field id="itemNodeContent" type="node" />
<field id="itemArrayContent" type="assocarray" />
<field id="results" type="string" />
</interface>
</component>

View File

@ -21,11 +21,27 @@ end sub
sub itemContentChanged()
if isValidToContinue(m.top.itemIndex)
print "isValidToContinue() = true"
m.LoadLibrariesTask = createObject("roSGNode", "LoadPhotoTask")
itemContent = m.top.items.content.getChild(m.top.itemIndex)
m.LoadLibrariesTask.itemContent = itemContent
if isValid(m.top.itemsNode)
print "using m.top.itemsNode"
if isValid(m.top.itemsNode.content)
m.LoadLibrariesTask.itemNodeContent = m.top.itemsNode.content.getChild(m.top.itemIndex)
else if isValidAndNotEmpty(m.top.itemsNode.id)
m.LoadLibrariesTask.itemNodeContent = m.top.itemsNode
end if
else if isValid(m.top.itemsArray)
print "using m.top.itemsArray"
itemContent = m.top.itemsArray[m.top.itemIndex]
m.LoadLibrariesTask.itemArrayContent = itemContent
else
return
end if
m.LoadLibrariesTask.observeField("results", "onPhotoLoaded")
m.LoadLibrariesTask.control = "RUN"
else
print "isValidToContinue() = false"
end if
end sub
@ -53,7 +69,18 @@ sub nextSlide()
m.slideshowTimer.control = "start"
end if
else if m.random = true
index = rnd(m.top.items.content.getChildCount() - 1)
index = invalid
if isValid(m.top.itemsNode)
if isValidAndNotEmpty(m.top.itemsNode.content)
index = rnd(m.top.itemsNode.content.getChildCount() - 1)
end if
else if isValid(m.top.itemsArray)
if isValid(m.top.itemsArray.count() > 0)
index = rnd(m.top.itemsArray.count() - 1)
end if
end if
if isValidToContinue(index)
m.top.itemIndex = index
m.slideshowTimer.control = "start"
@ -116,8 +143,19 @@ function onKeyEvent(key as string, press as boolean) as boolean
end function
function isValidToContinue(index as integer)
if isValid(m.top.items) and isValid(m.top.items.content)
if index >= 0 and index < m.top.items.content.getChildCount()
if isValid(m.top.itemsNode)
print "m.top.itemsNode is valid"
if isValidAndNotEmpty(m.top.itemsNode.content)
print "m.top.itemsNode.content is ValidAndNotEmpty"
if index >= 0 and index < m.top.itemsNode.content.getChildCount()
return true
end if
else if isValidAndNotEmpty(m.top.itemsNode) and index = 0
return true
end if
else if isValidAndNotEmpty(m.top.itemsArray)
print "m.top.itemsArray is ValidAndNotEmpty"
if index >= 0 and index < m.top.itemsArray.count()
return true
end if
end if

View File

@ -19,7 +19,8 @@
</children>
<interface>
<field id="items" type="node" />
<field id="itemsNode" type="node" />
<field id="itemsArray" type="roArray" />
<field id="itemIndex" type="integer" value="-1" onChange="itemContentChanged" />
</interface>
</component>

View File

@ -293,7 +293,33 @@ sub Main (args as dynamic) as void
end if
else if selectedItemType = "Photo"
' Nothing to do here, handled in ItemGrid
' only handle selection if it's from the home screen
if selectedItem.isSubType("HomeData")
print "a photo was selected from the home screen"
print "selectedItem=", selectedItem
photoPlayer = CreateObject("roSgNode", "PhotoDetails")
photoPlayer.itemsNode = selectedItem
photoPlayer.itemIndex = 0
m.global.sceneManager.callfunc("pushScene", photoPlayer)
end if
else if selectedItemType = "PhotoAlbum"
print "a photo album was selected"
print "selectedItem=", selectedItem
' grab all photos inside photo album
photoData = api.users.GetItemsByQuery(m.global.session.user.id, {
"parentId": selectedItem.id,
"includeItemTypes": "Photo",
"Recursive": true
})
print "photoData=", photoData
if isValid(photoData) and isValidAndNotEmpty(photoData.items)
photoPlayer = CreateObject("roSgNode", "PhotoDetails")
photoPlayer.itemsArray = photoData.items
photoPlayer.itemIndex = 0
m.global.sceneManager.callfunc("pushScene", photoPlayer)
end if
else if selectedItemType = "MusicArtist"
group = CreateArtistView(selectedItem.json)
if not isValid(group)

View File

@ -309,6 +309,9 @@ function isValidAndNotEmpty(input as dynamic) as boolean
if inputType = "string" or inputType = "rostring"
trimmedInput = input.trim()
return trimmedInput <> ""
else if inputType = "rosgnode"
inputId = input.id
return inputId <> invalid
else if countableTypes.doesExist(inputType)
return input.count() > 0
else