Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
xoceunder
Roku Guru

help with being able to open individual category in grid screen

help with being able to open individual category in grid screen

New SG

Function Init()
	Print"[GridScreen] Init"
	m.rowList=m.top.findNode("RowList")
	m.description=m.top.findNode("Description")
	m.background=m.top.findNode("Background")
	m.top.observeField("visible","onVisibleChange")
	m.top.observeField("focusedChild","OnFocusedChildChange")
End Function

'handler of focused item in RowList
Sub OnItemFocused()
	itemFocused=m.top.itemFocused

	'When an item gains the key focus, set to a 2-element array,
	'where element 0 contains the index of the focused row,
	'and element 1 contains the index of the focused item in that row.
	If itemFocused.Count()=2
		focusedContent=m.top.content.getChild(itemFocused[0]).getChild(itemFocused[1])
		If focusedContent<>invalid
			m.top.focusedContent=focusedContent
			m.description.content=focusedContent
			m.background.uri=focusedContent.hdBackgroundImageUrl
		End If
	End If
End Sub

'set proper focus to RowList in case if return from Details Screen
Sub onVisibleChange()
	If m.top.visible=TRUE
		m.rowList.setFocus(TRUE)
	End If
End Sub

'set proper focus to RowList in case if return from Details Screen
Sub OnFocusedChildChange() 
	If m.top.isInFocusChain() And Not m.rowList.hasFocus()
		m.rowList.setFocus(TRUE)
	End If
End Sub

old

Sub showMoviesScreen()
	
	' Configura el Grid
    screen = CreateObject("roGridScreen")
    port = CreateObject("roMessagePort")
    screen.SetMessagePort(port)
    screen.SetDisplayMode("scale-to-fill")
    screen.SetGridStyle("flat-movie")
    screen.SetDescriptionVisible(true)	
	screen.SetBreadcrumbEnabled(true)

    generos_list = getCategoryListMovies()
	
    categoryList = CreateObject("roArray",generos_list.count(),false)
    for each titles in generos_list
        categoryList.Push( titles )
    end for
    screen.setupLists(categoryList.count())
    screen.SetListNames(categoryList)
	screen.ClearMessage()
	screen.show()
	
    categoryLoaded = CreateObject("roArray",categoryList.count(),false)
    next_page_to_load = CreateObject("roArray",categoryList.count(),false)
	
    for i = 0 to categoryList.count() - 1

        if i<=1 then
            'print "Primera carga de "+generos_list[i]
			category_items = getMoviesByCategory(generos_list[i])
            screen.SetContentList(i, category_items)
        else
            category_items = Invalid
        end if

        categoryLoaded.Push( category_items )
        next_page_to_load.Push( 2 )

    end for
	
    screen.ClearMessage()
	screen.show()

    while (true)
        msg = wait(250, port)
		
        if msg <> invalid and type(msg) = "roGridScreenEvent" then
            row = msg.GetIndex()
            col = msg.getData()
            if msg.isScreenClosed() then
                exit while 
            else if msg.isStatusMessage()
                mensaje = msg.getMessage()
                status = msg.GetIndex()
			else if msg.isPlaybackPosition() 
                nowpos = msg.GetIndex()
                print "Tiempo conectado: "; nowpos
	        else if msg.isListItemFocused()
	             print "Focused msg: ";msg.GetMessage();" row: ";msg.GetIndex();
	             print " col: ";msg.GetData()
				 
                ' Comprueba si debe leer las categorías
                if categoryLoaded[row]=Invalid then
                    loadCategoryMovies(screen,row,categoryLoaded,generos_list)
                end if
                if (row+1)<categoryLoaded.count() and categoryLoaded[row+1]=Invalid then
                    loadCategoryMovies(screen,row+1,categoryLoaded,generos_list)
                end if
				
            else if msg.isListItemSelected()  
                 print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();			
				 showSpringboardScreenMovies(categoryLoaded[row] , col)
				
			else
			    print "Unexpected msg type: "; msg.GetType()
                print "mensaje: "; msg.getMessage()
            end if
        end if
		
    end while
    
End Sub

Function getCategoryListMovies() as object

    http = NewHTTP(Servidor()+"/categorias.php")
    http.AddParam("t", "peliculas")
    response= http.GetToStringWithTimeout(90)
    json = ParseJSON(response)
    return json
	
End Function


Function getMoviesByCategory(category)

    serial = GetDeviceESN()
	
    http = NewHTTP(Servidor()+"/movie.php")
    http.AddParam("cat", category)
	http.AddParam("serial", serial)
    response= http.GetToStringWithTimeout(90)
    json = ParseJSON(response)
	
    itemlist = CreateObject("roArray",json.Videos.count(),false)
    for each parsed_item in json.Videos
        itemlist.Push( parsed_item )
    end for
	
    return itemlist

End Function

Function loadCategoryMovies(screen, row , categoryLoaded, generos_list)

    categoryLoaded[row] = getMoviesByCategory(generos_list[row])
    screen.SetContentList(row, categoryLoaded[row])
    screen.ClearMessage()
	screen.show()
	
End Function

How can I do the same to avoid so much waiting when loading the content

 

0 Kudos
7 REPLIES 7
xoceunder
Roku Guru

Re: help with being able to open individual category in grid screen

please help

0 Kudos
RokuJonathanD
Community Moderator
Community Moderator

Re: help with being able to open individual category in grid screen

Hi @xoceunder,

Have you looked at our master sample channel in GitHub. This is a good resource for creating a grid screen and then launching content from it.

Take a look at the following samples:

Grid Screen: https://github.com/rokudev/scenegraph-master-sample/tree/master/GridScreen

Video Player: https://github.com/rokudev/scenegraph-master-sample/tree/master/VideoPlayer

0 Kudos
xoceunder
Roku Guru

Re: help with being able to open individual category in grid screen

I am using that same example but my idea is to load 2 category and each time I select a category I load 2 more

0 Kudos
RokuJamesM
Reel Rookie

Re: help with being able to open individual category in grid screen

Hello! Let's try to resolve your question! In preparation for escalation, please let me know what you hoped would happen and what actually happened. Thanks for the source code that you have already provided and please include more if that would be helpful to direct our attention to the problem area. Once I have this information in hand, I can discuss it with our engineering team; I'll let you know their observations and recommendations.

Awaiting your response; James

xoceunder
Roku Guru

Re: help with being able to open individual category in grid screen

thank you very much

0 Kudos
RokuJonathanD
Community Moderator
Community Moderator

Re: help with being able to open individual category in grid screen

So you could implement logic that gets the next two category rows from the roUrltransfer object when the user navigates down. You may want to take a look at our threading documentation.

https://developer.roku.com/docs/references/scenegraph/control-nodes/task.md

https://developer.roku.com/docs/developer-program/core-concepts/threads.md

https://developer.roku.com/docs/references/brightscript/interfaces/ifurltransfer.md

0 Kudos
xoceunder
Roku Guru

Re: help with being able to open individual category in grid screen

I am doing practice and making an implement for the new operation so I would have a suggestion of how I could do it, thanks with your help

0 Kudos