Forum Discussion

xoceunder's avatar
xoceunder
Roku Guru
5 years ago

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

 

7 Replies