Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
svencoop
Level 7

Simple extends="TimeGrid" code

UPDATE:
Figured out the first step!
TimeGridNode = m.top.findNode("IDTimeGrid")
tempContentNode = CreateObject("roSGNode", "ContentNode")
tempContentNode.Update(rootData)
TimeGridNode.content = tempContentNode

***But cannot figure out how to update the “row” data?***
This is what I am trying:
tempContentNode = CreateObject("roSGNode", "ContentNode")
tempContentNode.Update(RowChildrenData)

row = TimeGridNode.content.GetChild(RowNumberToUpdate)
row.content = tempContentNode


---
I have an existing channel that I wish to add a TimeGrid that does not need to be realtime or lazy loading, etc

As you know, the SGDEX example does show a TimeGrid, but when I tried to merge it with my existing program I had problems! (ComponentController does not want to play with others, etc)
Since I do not want or need the overhead of SGDEX, does anybody have a simple example of how to use the TimeGrid?

Roku confirms that documentation is coming, but it is months away!
Thanks,
Steve
0 Kudos
2 Replies
svencoop
Level 7

Re: Simple extends="TimeGrid" code

Roku finally sent me another example of how to build a time grid (it does not work 100% correctly, but is was helpful!)
So, to add "programs" to the "channel" row:
...
    nextShow = {}
    nextShow.title = "Program Name Here"
    nextShow.description = "Be sure to watch this!"
    nextShow.playStart = PlayStartSeconds
    nextShow.playDuration = PlayDurationSeconds
    newShowItem = row.CreateChild("ContentNode")
    newShowItem.Update(nextShow) 'SetFields() also works...
Hope this helps someone!
0 Kudos
svencoop
Level 7

Re: Simple extends="TimeGrid" code

How I used the TimeGrid: Instead of "channels" this lists by days for 7 days...

Obviously, this is based on the data I had to parse/load, your data will be different...

xml:<interface> I have no idea if these are required, but I just kept from example!

        <field id="contentStartTime" type="integer"  alias="ID_SchedTimeGrid.contentStartTime" />
        <field id="maxDays" type="integer" alias="ID_SchedTimeGrid.maxDays" />
        <field id="gridItemSelected" type="array" alwaysNotify="true" />
...

xml:<children>

        <TimeGrid id="ID_SchedTimeGrid" translation="[1, 810]" >  </TimeGrid>

brs:The "root" is the first column of "channels" - we use for days (only needs to be done once...)

    tgSetObserveFieldState(false)

    m.SchedTimeGridNode = m.top.findNode("ID_SchedTimeGrid")
'STOP
    currentTime = CreateObject("roDateTime")
    t = currentTime.AsSeconds()
    t = t - (t mod 1800)    ' set to a 30m mark...
    m.SchedTimeGridNode.contentStartTime = t

    'Start at midnight (local date)
    currentDate = CreateObject("roDateTime")
    currentDate.ToLocalTime()
    sDateStr = currentDate.ToISOString()
    aDateParts = sDateStr.Tokenize("T")
    currentTime.FromISO8601String(aDateParts[0] + " 00:00:00")
'STOP
    t = currentTime.AsSeconds()
    t += currentTime.GetTimeZoneOffset() * 60
    m.SchedTimeGridNode.contentStartTime = t
'STOP
    m.SchedTimeGridNode.leftEdgeTargetTime = currentTime.AsSeconds()
    m.SchedTimeGridNode.leftEdgeTargetTime = t      'hidden later...
    m.SchedTimeGridNode.channelNoDataText = "..."
    m.SchedTimeGridNode.loadingDataText = "Loading..."
    m.SchedTimeGridNode.channelInfoColumnLabel = "[DOWN] to Nav"
    m.SchedTimeGridNode.automaticLoadingDataFeedback = true
'    m.SchedTimeGridNode.numRows = 4
'    m.SchedTimeGridNode.numColumns = 1         'Root columns default
    m.SchedTimeGridNode.itemSpacing = [3,3]     'row spaces
    m.SchedTimeGridNode.maxDays = 1
    m.SchedTimeGridNode.duration = 4900         'program time box width - larger is smaller?
    m.SchedTimeGridNode.fillProgramGaps = true
    'm.SchedTimeGridNode.autoDismissTime = 9
    'm.SchedTimeGridNode.timeBarTwoLineLayout = false
    'm.SchedTimeGridNode.timeBarMessageText = ""
    m.SchedTimeGridNode.timeBarMessagingLayout = true   'Hide date!
    m.SchedTimeGridNode.timeBarHeight = 64              'Smaller just for times...
    TGrootChildren = {
        children: []
    } ' channels array
    TGdaysOfWeek = []
    TGdaysOfWeek.Push("Sunday")
    TGdaysOfWeek.Push("Monday")
    TGdaysOfWeek.Push("Tuesday")
    TGdaysOfWeek.Push("Wednesday")
    TGdaysOfWeek.Push("Thursday")
    TGdaysOfWeek.Push("Friday")
    TGdaysOfWeek.Push("Saturday")
    currDayOfWeek = currentTime.GetDayOfWeek()
    currDayName = currentTime.GetWeekday()
'STOP
    nDayNum = currDayOfWeek
    rowLocalBaseDateObj = CreateObject("roDateTime")
    rowLocalBaseDateObj.ToLocalTime()
    WholeDaySecs = 60 * 60 * 24
    nDayOffset = 0
    while(nDayOffset < 7)
        nextWkDay = TGdaysOfWeek[nDayNum]
        sMon = rowLocalBaseDateObj.GetMonth()
        sDay = rowLocalBaseDateObj.GetDayOfMonth()
        sDtDay = sMon.ToStr() + "/" + sDay.ToStr() + " " + nextWkDay
        channelNode = makeWeekdayChNode(sDtDay, nDayNum)
        TGrootChildren.children.Push(channelNode)
        nDayNum++
        if(nDayNum > 6) then nDayNum = 0
        nDayOffset++
        tempDtSecs = rowLocalBaseDateObj.AsSeconds()
        tempDtSecs += WholeDaySecs
        rowLocalBaseDateObj.FromSeconds(tempDtSecs)
    end while
    m.SchedTimeGridNode = m.top.findNode("ID_SchedTimeGrid")
    tempContentNode = CreateObject("roSGNode", "ContentNode")
    tempContentNode.Update(TGrootChildren)
    m.SchedTimeGridNode.content = tempContentNode

 

brs:After you have loaded the data, use this to load from m.gAllShowsAry

    'Divide up days...load by Day...
    setUTCBaseDateObj = CreateObject("roDateTime")
    print "UTC  :"; setUTCBaseDateObj.ToISOString(), "TZ:";setUTCBaseDateObj.GetTimeZoneOffset()
    setLocalBaseDateObj = CreateObject("roDateTime")
    setLocalBaseDateObj.ToLocalTime()
'STOP
    xUTCDateStr = setUTCBaseDateObj.ToISOString()
    dateParts = xUTCDateStr.Tokenize("T")       'assumes 2019-08-29T11:10:00Z
    sGridRowsBaseDate = dateParts[0]            'like 2019-08-29
'STOP
    nDayOffset = 0
    while(nDayOffset < 7)   'Loop for 7 days
        xRowDateMatchStr = setLocalBaseDateObj.ToISOString()
        xRowDateMatchStr = xRowDateMatchStr.Mid(0, 10)
        m.SchedTimeGridNode = m.top.findNode("ID_SchedTimeGrid")
        currRowObj = m.SchedTimeGridNode.content.GetChild(nDayOffset)
?"nDayOffset / xRowDateMatchStr: "; nDayOffset, xRowDateMatchStr
        WholeDaySecs = 60 * 60 * 24
        nProgCounter = 0
?"m.CurrentShowsType:"m.CurrentShowsType
        for each nextShow in m.gAllShowsAry
            xProgDate = nextShow.tgProgramLocalStart.ToISOString()
'?"[]xProgDate / xRowDateMatchStr ";xProgDate, xRowDateMatchStr
            if(xProgDate.Mid(0, 10) = xRowDateMatchStr) then
'STOP
                programInfo = {}
                programInfo.title = getCleanStr(nextShow.ProgramName)
                programInfo.description = getCleanStr(nextShow.TitleSynopsis)
                if(nextShow.TitleSynopsis = invalid) then programInfo.description = getCleanStr(nextShow.ProgramSynopsis)
                if("P" = nextShow.TitlePremiereIndicatorCurrentSchedule)
                    programInfo.description = "NEW: " + programInfo.description
                end if
'?m.SchedTimeGridNode
                programInfo.TitleName = getCleanStr(nextShow.TitleName)
                programInfo.TitleCode = getCleanStr(nextShow.TitleCode)
                programInfo.playStart = nextShow.tgProgramUTCStart.AsSeconds()
                programInfo.playDuration = nextShow.tgProgramSecsLen
'STOP
                'Adjust base time for each row...
                fixBaseDtTime = CreateObject("roDateTime")
                fixBaseDtTime.FromSeconds(programInfo.playStart)
                fixDayOffset = fixBaseDtTime.AsSeconds()
                fixDayOffset -= WholeDaySecs * nDayOffset
                fixBaseDtTime.FromSeconds(fixDayOffset)
                programInfo.playStart = fixBaseDtTime.AsSeconds()
'STOP
'?"nDayOffset:";nDayOffset, "utc:";nextShow.tgProgramUTCStart.toisostring(), "cst:";nextShow.tgProgramLocalStart.toisostring(),
'              ?programInfo.playstart, programInfo.playduration, programInfo.title
                if(nProgCounter < 123) then
                    newShowItem = currRowObj.CreateChild("ContentNode")
                    newShowItem.AddFields({ TitleName: "TitleName" })
                    newShowItem.AddFields({ TitleCode: "TitleCode" })
                    newShowItem.SetFields(programInfo)
                else
                    'silly, cuz this should not happen, ever!
                    chkPS = CreateObject("roDateTime")
                    chkPS.FromSeconds(programInfo.PlayStart)
                    ?"nProgCounter:"nProgCounter, programInfo, chkPS.ToISOString()
                end if
                nProgCounter++
            end if
        end for
        nDayOffset++
        tempDtSecs = setLocalBaseDateObj.AsSeconds()
        tempDtSecs += WholeDaySecs
        setLocalBaseDateObj.FromSeconds(tempDtSecs)
    end while
'    m.ProgramDesc1.text = ""
'    m.ProgramDesc2.text = "[DOWN] to Nav"
    'Reset so grid jumps to current time...
    m.SchedTimeGridNode.leftEdgeTargetTime = 0
    m.SchedTimeGridNode.jumpToTime = 0
    tgSetObserveFieldState(true)
    currentTime = CreateObject("roDateTime")
    t = currentTime.AsSeconds()
    t = t - (t mod 1800)    ' set to a 30m mark...
    m.SchedTimeGridNode.leftEdgeTargetTime = t
    m.SchedTimeGridNode.jumpToTime = t
 
brs:Helper to avoid "events" during loading...
Sub tgSetObserveFieldState(bActive)
'STOP
    m.SchedTimeGridNode = m.top.findNode("ID_SchedTimeGrid")
    if(bActive) then
        m.SchedTimeGridNode.observeField("focusedChild", "tgChildFocused")
        m.SchedTimeGridNode.observeField("itemFocused", "tgItemFocused")
        m.SchedTimeGridNode.observeField("programFocused", "tgProgramFocused")
        m.SchedTimeGridNode.observeField("programSelected", "tgProgramSelected")
        m.SchedTimeGridNode.observeField("channelInfoSelected", "tgChannelInfoSelected")
        m.SchedTimeGridNode.observeField("channelInfoFocused", "tgChannelInfoFocused")
        m.SchedTimeGridNode.observeField("itemUnfocused", "tgChannelUnfocused")
        m.SchedTimeGridNode.observeField("programUnfocused", "tgProgramUnfocused")
        m.SchedTimeGridNode.observeField("channelInfoUnfocused", "tgChannelInfoUnfocused")
    else
        m.SchedTimeGridNode.unobserveField("focusedChild")
        m.SchedTimeGridNode.unobserveField("itemFocused")
        m.SchedTimeGridNode.unobserveField("programFocused")
        m.SchedTimeGridNode.unobserveField("programSelected")
        m.SchedTimeGridNode.unobserveField("channelInfoSelected")
        m.SchedTimeGridNode.unobserveField("channelInfoFocused")
        m.SchedTimeGridNode.unobserveField("itemUnfocused")
        m.SchedTimeGridNode.unobserveField("programUnfocused")
        m.SchedTimeGridNode.unobserveField("channelInfoUnfocused")
    end if
 

Enjoy!

 

0 Kudos