From 78ab9e9233f431ccd9af452a3ef415bb077093d7 Mon Sep 17 00:00:00 2001 From: Jimi Date: Fri, 18 Nov 2022 22:57:40 -0700 Subject: [PATCH 1/5] Support left, right navigation while viewing photos --- components/ItemGrid/ItemGrid.brs | 7 +++-- components/photos/PhotoDetails.brs | 42 ++++++++++++++++++++++++--- components/photos/PhotoDetails.xml | 3 +- components/photos/PhotoPlayerTask.brs | 17 ----------- components/photos/PhotoPlayerTask.xml | 8 ----- 5 files changed, 44 insertions(+), 33 deletions(-) delete mode 100644 components/photos/PhotoPlayerTask.brs delete mode 100644 components/photos/PhotoPlayerTask.xml diff --git a/components/ItemGrid/ItemGrid.brs b/components/ItemGrid/ItemGrid.brs index 2ddaaca2..f5bd3b9d 100644 --- a/components/ItemGrid/ItemGrid.brs +++ b/components/ItemGrid/ItemGrid.brs @@ -724,9 +724,10 @@ function onKeyEvent(key as string, press as boolean) as boolean return true else if itemToPlay <> invalid and itemToPlay.type = "Photo" ' Spawn photo player task - photoPlayer = CreateObject("roSgNode", "PhotoPlayerTask") - photoPlayer.itemContent = itemToPlay - photoPlayer.control = "RUN" + photoPlayer = CreateObject("roSgNode", "PhotoDetails") + photoPlayer.items = markupGrid + photoPlayer.itemIndex = markupGrid.itemFocused + m.global.sceneManager.callfunc("pushScene", photoPlayer) return true end if else if key = "left" and topGrp.isinFocusChain() diff --git a/components/photos/PhotoDetails.brs b/components/photos/PhotoDetails.brs index 0903a779..c65d00ac 100644 --- a/components/photos/PhotoDetails.brs +++ b/components/photos/PhotoDetails.brs @@ -1,13 +1,17 @@ sub init() m.top.optionsAvailable = false ' Change once Shuffle option is added m.top.overhangVisible = false + itemContentChanged() end sub sub itemContentChanged() - m.LoadLibrariesTask = createObject("roSGNode", "LoadPhotoTask") - m.LoadLibrariesTask.itemContent = m.top.itemContent - m.LoadLibrariesTask.observeField("results", "onPhotoLoaded") - m.LoadLibrariesTask.control = "RUN" + if isValidToContinue(m.top.itemIndex) + m.LoadLibrariesTask = createObject("roSGNode", "LoadPhotoTask") + itemContent = m.top.items.content.getChild(m.top.itemIndex) + m.LoadLibrariesTask.itemContent = itemContent + m.LoadLibrariesTask.observeField("results", "onPhotoLoaded") + m.LoadLibrariesTask.control = "RUN" + end if end sub sub onPhotoLoaded() @@ -19,3 +23,33 @@ sub onPhotoLoaded() message_dialog("This image type is not supported.") end if end sub + +function onKeyEvent(key as string, press as boolean) as boolean + if not press then return false + + if key = "right" + if isValidToContinue(m.top.itemIndex + 1) + m.top.itemIndex++ + end if + return true + end if + + if key = "left" + if isValidToContinue(m.top.itemIndex - 1) + m.top.itemIndex-- + end if + return true + end if + + return false +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() + return true + end if + end if + + return false +end function diff --git a/components/photos/PhotoDetails.xml b/components/photos/PhotoDetails.xml index ea7d7f7e..016c963f 100644 --- a/components/photos/PhotoDetails.xml +++ b/components/photos/PhotoDetails.xml @@ -6,7 +6,8 @@ - + +