Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ItemGrid backdrop when alpha is active and prevent loading background twice on first load #1896

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions components/ItemGrid/ItemGrid.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "pkg:/source/roku_modules/log/LogMixin.brs"

sub init()
m.log = log.Logger("ItemGrid")
m.log.debug("start init()")
m.options = m.top.findNode("options")

m.showItemCount = m.global.session.user.settings["itemgrid.showItemCount"]
Expand Down Expand Up @@ -70,6 +71,7 @@ sub init()
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]

m.top.gridTitles = m.global.session.user.settings["itemgrid.gridTitles"]
m.log.debug("end init()")
end sub

'Genre Item Selected
Expand All @@ -79,6 +81,7 @@ end sub

'Load initial set of Data
sub loadInitialItems()
m.log.debug("start loadInitialItems()")
m.loadItemsTask.control = "stop"
startLoadingSpinner()

Expand Down Expand Up @@ -227,6 +230,7 @@ sub loadInitialItems()
startLoadingSpinner(false)
m.loadItemsTask.control = "RUN"
SetUpOptions()
m.log.debug("end loadInitialItems()")
end sub

' Set Movies view, sort, and filter options
Expand Down Expand Up @@ -438,6 +442,7 @@ end sub

'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
m.log.debug("start ItemDataLoaded()")
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []
Expand Down Expand Up @@ -494,22 +499,28 @@ sub ItemDataLoaded(msg)
end if

stopLoadingSpinner()
m.log.debug("end ItemDataLoaded()")
end sub

'Set Background Image
sub SetBackground(backgroundUri as string)

m.log.debug("start SetBackground()", backgroundUri, m.swapAnimation.state, m.newBackdrop.loadStatus)
'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
if not m.top.alphaActive
if m.swapAnimation.state <> "stopped" or m.newBackdrop.loadStatus = "loading"
m.log.debug("caching new background URI")
m.queuedBGUri = backgroundUri
return
end if
end if

m.newBackdrop.uri = backgroundUri
m.log.debug("end SetBackground()")
end sub

'Handle new item being focused
sub onItemFocused()
m.log.debug("start onItemFocused()", m.itemGrid.currFocusRow, m.itemGrid.itemFocused)

focusedRow = m.itemGrid.currFocusRow

Expand All @@ -518,7 +529,7 @@ sub onItemFocused()
updateTitle()

' If no selected item, set background to parent backdrop
if itemInt = -1
if itemInt = -1 or focusedRow = -1
return
end if

Expand All @@ -531,6 +542,7 @@ sub onItemFocused()
if focusedRow >= m.loadedRows - 5 and m.loadeditems < m.loadItemsTask.totalRecordCount
loadMoreData()
end if
m.log.debug("end onItemFocused()")
end sub

'When Image Loading Status changes
Expand All @@ -551,6 +563,7 @@ sub swapDone()

'If there is another one to load
if m.newBackdrop.uri <> m.queuedBGUri and m.queuedBGUri <> ""
m.log.debug("Loading queued backdrop image", m.queuedBGUri)
SetBackground(m.queuedBGUri)
m.queuedBGUri = ""
end if
Expand All @@ -559,13 +572,15 @@ end sub

'Load next set of items
sub loadMoreData()
m.log.debug("start loadMoreData()")
if m.Loading = true then return

startLoadingSpinner(false)
m.Loading = true
m.loadItemsTask.startIndex = m.loadedItems
m.loadItemsTask.observeField("content", "ItemDataLoaded")
m.loadItemsTask.control = "RUN"
m.log.debug("end loadMoreData()")
end sub

'Item Selected
Expand Down Expand Up @@ -760,6 +775,20 @@ function getItemFocused()
return invalid
end function

sub alphaActiveChanged()
m.log.debug("start alphaActiveChanged()", m.top.alphaActive)

if m.top.alphaActive
' fade into an empty backdrop
m.swapAnimation.state = "stop"
m.queuedBGUri = ""
' use a 1px image because we can't use the animation to fade into a blank uri string
SetBackground("pkg:/images/1px-262626.png")
end if

m.log.debug("end alphaActiveChanged()")
end sub

function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false

Expand Down Expand Up @@ -826,11 +855,14 @@ function onKeyEvent(key as string, press as boolean) as boolean
return true
end if
else if key = "left" and topGrp.isinFocusChain()
m.log.debug("Now entering alpha menu")
m.top.alphaActive = true
topGrp.setFocus(false)
m.alphaMenu.setFocus(true)

return true
else if key = "right" and m.alpha.isinFocusChain()
m.log.debug("Now leaving alpha menu")
m.top.alphaActive = false
m.alphaMenu.setFocus(false)
topGrp.setFocus(true)
Expand Down
2 changes: 1 addition & 1 deletion components/ItemGrid/ItemGrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<field id="quickPlayNode" type="node" alwaysNotify="true" />
<field id="imageDisplayMode" type="string" value="scaleToZoom" />
<field id="alphaSelected" type="string" alias="alpha.letterSelected" alwaysNotify="true" onChange="alphaSelectedChanged" />
<field id="alphaActive" type="boolean" value="false" />
<field id="alphaActive" type="boolean" value="false" onChange="alphaActiveChanged" />
<field id="jumpToItem" type="integer" value="" />
<field id="gridTitles" type="string" />
</interface>
Expand Down
Binary file added images/1px-262626.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading