From 88bc02b8b3f546befde384f0aebb2e5336f54aef Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Mon, 13 Nov 2023 09:16:00 -0500 Subject: [PATCH] make photos work from homescreen --- components/ItemGrid/ItemGrid.bs | 2 +- components/data/HomeData.bs | 28 ++++++++++++++++- components/home/HomeItem.bs | 35 +++++++++++++++++++++ components/photos/LoadPhotoTask.bs | 20 ++++++++---- components/photos/LoadPhotoTask.xml | 3 +- components/photos/PhotoDetails.bs | 48 ++++++++++++++++++++++++++--- components/photos/PhotoDetails.xml | 3 +- source/Main.bs | 28 ++++++++++++++++- source/utils/misc.bs | 3 ++ 9 files changed, 154 insertions(+), 16 deletions(-) diff --git a/components/ItemGrid/ItemGrid.bs b/components/ItemGrid/ItemGrid.bs index ce531c28..ea3299b0 100644 --- a/components/ItemGrid/ItemGrid.bs +++ b/components/ItemGrid/ItemGrid.bs @@ -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 diff --git a/components/data/HomeData.bs b/components/data/HomeData.bs index 8563bc85..6309a750 100644 --- a/components/data/HomeData.bs +++ b/components/data/HomeData.bs @@ -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 diff --git a/components/home/HomeItem.bs b/components/home/HomeItem.bs index a5cdc106..9ccdc1b5 100644 --- a/components/home/HomeItem.bs +++ b/components/home/HomeItem.bs @@ -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 diff --git a/components/photos/LoadPhotoTask.bs b/components/photos/LoadPhotoTask.bs index 5f45c548..4e8721fc 100644 --- a/components/photos/LoadPhotoTask.bs +++ b/components/photos/LoadPhotoTask.bs @@ -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 diff --git a/components/photos/LoadPhotoTask.xml b/components/photos/LoadPhotoTask.xml index f6ca68c6..c7277392 100644 --- a/components/photos/LoadPhotoTask.xml +++ b/components/photos/LoadPhotoTask.xml @@ -2,7 +2,8 @@ - + + \ No newline at end of file diff --git a/components/photos/PhotoDetails.bs b/components/photos/PhotoDetails.bs index d2dbdf32..53bb5cd9 100644 --- a/components/photos/PhotoDetails.bs +++ b/components/photos/PhotoDetails.bs @@ -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 diff --git a/components/photos/PhotoDetails.xml b/components/photos/PhotoDetails.xml index 3cf423c7..4afe4a0a 100644 --- a/components/photos/PhotoDetails.xml +++ b/components/photos/PhotoDetails.xml @@ -19,7 +19,8 @@ - + + \ No newline at end of file diff --git a/source/Main.bs b/source/Main.bs index 4ed19833..2a16fb50 100644 --- a/source/Main.bs +++ b/source/Main.bs @@ -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) diff --git a/source/utils/misc.bs b/source/utils/misc.bs index 3aae717a..3cb48ed9 100644 --- a/source/utils/misc.bs +++ b/source/utils/misc.bs @@ -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