0

since i have one api with gives two parameter i.e:valid with have 0 and 1 and atuh which have random code and bu using task nod i became successful to display that auth random code in screen but our logic when that random code is registered by user the valid parameter automatically give 1 previously it will have 0 so my problem is when the user is not registered the API valid will have 0 so the screen will be on random ode display and after that user will enter that code and register o after entering that code valid will have 1 response so now i want the screen automatically redirect to the channel listing from random code display o how can we do i will

main.brs

' ********** Copyright 2016 Roku Corp.  All Rights Reserved. ********** 

 sub RunUserInterface()
    screen = CreateObject("roSGScreen")
     port = CreateObject("roMessagePort")
    screen.SetMessagePort(port)
    m.simpleTask.ObserveField("taskValid", "onTaskVallid")
m.simpleTask.control = "RUN"


    res=getauth()
    response = parseJSON(res)
'    print "what we got:"response
'    
'    print response.valid
'    print response.atuh
'    chck=status.valid
'    print chck
status=response.valid

    if status = "1" then
    scene = screen.CreateScene("HomeScene")
      screen.Show()

    else 

    scene = screen.CreateScene("MessageTaskScene") 

      screen.Show()
      'while false sleep and hit api

      'scene/screen ko value 

    endif



    oneRow = GetApiArray()
    list = [
        {
            Title:"First row"
            ContentList : oneRow
        }
        {
            Title:"Second row"
            ContentList : oneRow
        }
    ]
    scene.gridContent = ParseXMLContent(list)

    while true
        msg = wait(0, port)
        print "------------------"
        print "msg = "; msg
    end while

    if screen <> invalid then
        screen.Close()
        screen = invalid
    end if
end sub


Function ParseXMLContent(list As Object)
    RowItems = createObject("RoSGNode","ContentNode")

    for each rowAA in list
        row = createObject("RoSGNode","ContentNode")
        row.Title = rowAA.Title

        for each itemAA in rowAA.ContentList
            item = createObject("RoSGNode","ContentNode")
            ' We don't use item.setFields(itemAA) as doesn't cast streamFormat to proper value
            for each key in itemAA
                item[key] = itemAA[key]
            end for
            row.appendChild(item)
        end for
        RowItems.appendChild(row)
    end for

    return RowItems
End Function


Function GetApiArray()
    url = CreateObject("roUrlTransfer")
    url.SetUrl("http://api.delvenetworks.com/rest/organizations/59021fabe3b645968e382ac726cd6c7b/channels/1cfd09ab38e54f48be8498e0249f5c83/media.rss")
    rsp = url.GetToString()

    responseXML = ParseXML(rsp)
    responseXML = responseXML.GetChildElements()
    responseArray = responseXML.GetChildElements()

    result = []

    for each xmlItem in responseArray
        if xmlItem.getName() = "item"
            itemAA = xmlItem.GetChildElements()
            if itemAA <> invalid
                item = {}
                for each xmlItem in itemAA
                    item[xmlItem.getName()] = xmlItem.getText()
                    if xmlItem.getName() = "media:content"
                        item.stream = {url : xmlItem.url}
                        item.url = xmlItem.getAttributes().url
                        item.streamFormat = "mp4"

                        mediaContent = xmlItem.GetChildElements()
                        for each mediaContentItem in mediaContent
                            if mediaContentItem.getName() = "media:thumbnail"
                                item.HDPosterUrl = mediaContentItem.getattributes().url
                                item.hdBackgroundImageUrl = mediaContentItem.getattributes().url
                            end if
                        end for
                    end if
                end for
                result.push(item)
            end if
        end if
    end for

    return result
End Function


Function ParseXML(str As String) As dynamic
    if str = invalid return invalid
    xml = CreateObject("roXMLElement")
    if not xml.Parse(str) return invalid
    return xml
End Function


function getauth() As string

    url = CreateObject("roUrlTransfer") 
    url.SetUrl("http://demo5770907.mockable.io/roku/validate")
    rsp = url.GetToString()


    return rsp



end function

MessageTaskScene.brs

function init()
m.top.setFocus(true)
m.myLabel = m.top.findNode("myLabel")
m.simpleTask = CreateObject("roSGNode", "SimpleTask")
m.simpleTask.ObserveField("taskRamdomCode", "onTaskResult")
m.simpleTask.ObserveField("taskValid", "onTaskValid")
m.simpleTask.control = "RUN"
'print m.simpleTask
' m.myLabel.text = "HOW"


end function

function onTaskResult() as void
'print stri(m.simpleTask.taskResult)+"helo"
'print  m.simpleTask.taskRamdomCode

messge="You havent login yet so please login in your Roku login page with this registration code:"+m.simpleTask.taskRamdomCode
m.myLabel.text=messge

m.myLabel.font.size=40
'
'    'Set the color to light blue
m.myLabel.color="0x72D7EEFF"
end function

function  onTaskValid() as string

return  m.simpleTask.taskValid

end function

MessageTaskscene.xml

<?xml version="1.0" encoding="UTF-8"?>
<component name="MessageTaskScene" extends="Scene" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">


<script type="text/brightscript" uri="pkg:/components/screens/MessageTaskScene/MessageTaskScene.brs"/>


    <children>
       <Label id="myLabel" 
        text="This is first screen message"
        width="1280" 
        height="720" 
        horizAlign="left"
        vertAlign="center"
        wrap ="true"
        />




    </children>

</component>

SimpleTask.xml

<?xml version="1.0" encoding="UTF-8"?>
<component name="SimpleTask" extends="Task" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<interface>
    <field id="taskRamdomCode" type="string" value="0" />
     <field id="taskValid" type="string" value="0" />
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()
    m.top.functionName = "getcode"
end sub

function getcode() As void
flag =true
while (flag)
    sleep(2000)
    url = CreateObject("roUrlTransfer") 
    url.SetUrl("http://demo5770907.mockable.io/roku/validate")
    rsp = url.GetToString()
    response = parseJSON(rsp)

   m.top.taskRamdomCode=response.atuh
   m.top.taskValid=response.valid
   if(response.valid = "1")
    flag = false
   endif

endwhile


end function

]]>
</script>

</component>

Can anyone help me out?i want to change the screen from MessageTaskscene to HomeScene automatically as soon as user entered that random code and get registred

Ajay Paudel
  • 322
  • 1
  • 12
  • 1
    hello, Ajay Paudel I have the same issue as your question. pls, add an answer in your question if you found the solution. – Nikunj Chaklasiya Jul 05 '19 at 04:59
  • Hello, I made task and then in task there is a funtion and insid function we use while(true) then condition so when true we use screen.show(particular screen) that how we did,Hope you understand – Ajay Paudel Jul 05 '19 at 05:34
  • I made on one screen and in a screen two button in a click on first button to open another screen it is possible. – Nikunj Chaklasiya Jul 05 '19 at 05:37
  • yes when clicking a button first made a task and call that and make it run when clicked that particular button it runs that task and in that task call the scene or screen on which you to make redirect,it's possible – Ajay Paudel Jul 05 '19 at 06:02
  • here you write `scene = screen.CreateScene("keyboarddialogscene")` and `screen.Show()` its not work from my side – Nikunj Chaklasiya Jul 05 '19 at 06:13
  • hve u made a task? and have u called that task when button is clicked? – Ajay Paudel Jul 05 '19 at 06:14
  • https://stackoverflow.com/questions/56753908/redirect-to-home-page-after-clicked-save-button-using-brightscript this is my question if you check... – Nikunj Chaklasiya Jul 05 '19 at 08:49
  • I simply create one screen extends with the scene and call another file function using like this `function loadNavContent() as boolean ? "loadNavContent is calling here........" m.NavigationTask = createObject("roSGNode","Login") m.NavigationTask.functionName = "LoginScren" m.NavigationTask.backExitsScene = false m.NavigationTask.control ="RUN" print "LoginScreen" handled = true return true end function` But its didnt response – Nikunj Chaklasiya Jul 09 '19 at 07:17
  • I also wrote function in Login Screen code `function LoginScren() as boolean ? "here the write a LoginScreen Function available here" showdialogid() showdialogpass() end function` – Nikunj Chaklasiya Jul 09 '19 at 07:17

0 Answers0