sdornan
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011
01:25 PM
Delay Category Feed Load
I'm trying to modify the showPosterScreen() function from the video player sample in the SDK for my app.
One thing I've noticed is that Roku will fetch the feed for a focused category even when the user is only focusing on that category on his/her way to another category. For example, if the user moves from category 1 to category 6, Roku fetches the feeds for categories 2 through 5 before the content for category 6 is displayed. This has a big negative effect on my app's performance.
Is there an easy way to delay the fetching of a category feed without it affecting the responsiveness of the UI? Perhaps only fetch the category if the user remains focused on the category for a second or something?
Thanks!
One thing I've noticed is that Roku will fetch the feed for a focused category even when the user is only focusing on that category on his/her way to another category. For example, if the user moves from category 1 to category 6, Roku fetches the feeds for categories 2 through 5 before the content for category 6 is displayed. This has a big negative effect on my app's performance.
Is there an easy way to delay the fetching of a category feed without it affecting the responsiveness of the UI? Perhaps only fetch the category if the user remains focused on the category for a second or something?
Thanks!
Function showPosterScreen(screen As Object) As Integer
if validateParam(screen, "roPosterScreen", "showPosterScreen") = false return -1
m.curCategory = 0
m.curShow = 0
initCategoryList()
categoryList = getCategoryList(m.Categories)
screen.SetListNames(m.CategoryNames)
screen.SetContentList(getShowsForCategoryItem(categoryList[m.curCategory]))
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roPosterScreenEvent" then
print "showPosterScreen | msg = "; msg.GetMessage() " | index = "; msg.GetIndex()
if msg.isListFocused() then
m.curCategory = msg.GetIndex()
m.curShow = 0
'get the list of shows for the currently selected item
empty_list = CreateObject("roArray", 10, true)
screen.SetContentList(empty_list)
screen.ShowMessage("retrieving...")
screen.SetContentList(getShowsForCategoryItem(categoryList[msg.GetIndex()]))
screen.SetFocusedListItem(m.curShow)
print "list focused | current category = "; m.curCategory
else if msg.isListItemFocused() then
print "list item focused | current show = "; msg.GetIndex()
else if msg.isListItemSelected() then
m.curShow = msg.GetIndex()
print "list item selected | current show = "; m.curShow
m.curShow = displayShowDetailScreen(categoryList[m.curCategory], msg.GetIndex())
screen.setFocusedListItem(m.curShow)
else if msg.isScreenClosed() then
return -1
end if
end If
end while
End Function
7 REPLIES 7


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011
02:26 PM
Re: Delay Category Feed Load
You probably want to move the content loading logic out of the isListFocused() handler and just set a flag there instead. Then, delay the content load till you're reasonably sure the user has stopped scrolling. viewtopic.php?f=34&t=35345
sdornan
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2011
04:13 PM
Re: Delay Category Feed Load
Got it working. Thanks!
ionatan
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2012
12:21 AM
Re: Delay Category Feed Load
How exactly you added this delay? Thanks

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2012
12:30 AM
Re: Delay Category Feed Load
You can use rotimespan, executing mark() on each islistfocused() and loading content after timer.totalmilliseconds()>500 for example.
There are other approaches, I usually just cache all data in an array so that there is no need to go to the server every time the user changes categories. Usually I ignore the is listselected() event.
Joel
There are other approaches, I usually just cache all data in an array so that there is no need to go to the server every time the user changes categories. Usually I ignore the is listselected() event.
Joel
ionatan
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2012
04:46 AM
Re: Delay Category Feed Load
Thanks, I will try rotimespan. I'm not sure how can be the content loaded after 500 ms, how can I make the script to wait, and just after 500 ms to load the content?!
Why are you ignoring islistselected()? By "I usually just cache all data in an array" you mean that you are saving the feed in tmp:/ ? Thanks
Why are you ignoring islistselected()? By "I usually just cache all data in an array" you mean that you are saving the feed in tmp:/ ? Thanks

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2012
10:25 AM
Re: Delay Category Feed Load
Here's a very rough outline of both caching and delaying category load:
as far as caching goes, if you have five sections:
screen.setlistnames(["zero","one","two","three","four"]]
then you would need to load MycontentarrayCache[0] with an array containing each poster item for section zero, and MycontentarrayCache[1] with an array containing each poster item for section one, etc.
Hope that is helpful.
- Joel
function posterscreen()
screen=creatobject("roposterscreen")
screen.show()
screen.setlistnames(["zero","one","two","three","four"]]
'load all content for this screen into a cache variable:
MycontentarrayCache=getAndParseDataFromMyWebsite()
screen.setcontentlist(MyContentArrayCache[0])
timer=createobject("rotimespan")
timer.mark()
while true
msg=wait(1,port)
if type(msg)="roPosterScreenEvent" then
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.totalmilliseconds() >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()
ndx=msg.getindex()
'do nothing, although you *could* do a
'screen.setcontentlist here to override the timer, since this event
'indicates the user definitely wants to see this category
else if msg.islistitemfocused()
print "a list item is focused!"
else if msg.islistitemselected()
print "a list item is selected, do something"
end if
end while
end function
as far as caching goes, if you have five sections:
screen.setlistnames(["zero","one","two","three","four"]]
then you would need to load MycontentarrayCache[0] with an array containing each poster item for section zero, and MycontentarrayCache[1] with an array containing each poster item for section one, etc.
Hope that is helpful.
- Joel
ionatan
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2012
10:03 AM
Re: Delay Category Feed Load
I tried this but timer return always 0
I found the issue. I changed this:
In this
I found the issue. I changed this:
if type(msg)="roPosterScreenEvent" then
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.totalmilliseconds() >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()
In this
if type(msg)="roPosterScreenEvent" then
time_delay = timer.totalmilliseconds()
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.time_delay >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()