content: Sub init()
  	m.screenBG=m.top.findNode("screenBG")
  	m.screenBG.color="#000000"
  
  	m.AC_Font_28= CreateObject("roSGNode","Font")
  	m.AC_Font_28.uri="pkg://fonts/AvenirNextBold/AvenirNext-Bold.ttf"
  	m.AC_Font_28.size=30
  
  
  	m.AC_Font_36= CreateObject("roSGNode","Font")
  	m.AC_Font_36.uri="pkg://fonts/AvenirNextBold/AvenirNext-Bold.ttf"
  	m.AC_Font_36.size=36
  
  	m.AC_Font_32= CreateObject("roSGNode","Font")
  	m.AC_Font_32.uri="pkg://fonts/AvenirNextBold/AvenirNext-DemiBold.ttf"
  	m.AC_Font_32.size=32
  
  	m.appLaunch=false
  	m.customOverlay=m.top.findNode("customOverlay")
  	m.bannerImage=m.top.findNode("bannerImage")
  	m.bannerTitle=m.top.findNode("bannerTitle")
  	m.bannerTimeStamp=m.top.findNode("bannerTimeStamp")
  	m.bannerDesc=m.top.findNode("bannerDesc")
  	m.releaseYear=m.top.findNode("releaseYear")
  	m.contentMetadata=m.top.FindNode("contentMetadata")' as Object
  	m.contentCredit=m.top.findNode("contentCredit")
  	m.contentGenres=m.top.findNode("contentGenres")
  	m.hdText=m.top.findNode("hdText")
  	m.viewsCount=m.top.findNode("viewsCount")
  	m.viewsIcon=m.top.findNode("viewsIcon")
  
  
  	m.contentRow=m.top.findNode("contentRow")
  	m.contentRow.focusXOffset=[(0)]
  	m.contentRow.itemSize=[(1700),(250)]
  	m.contentRow.translation=[(150),(600)]
  	m.contentRow.numRows=(10)
  	'm.contentRow.focusXOffset=[(200)]
  	m.contentRow.itemSpacing=[0,30]
  	m.contentRow.rowItemSpacing= [[(10),(3)]]
  	m.contentRow.rowLabelOffset= [(0),(17)]
  	m.contentRow.rowCounterRightOffset=0.10
  	m.contentRow.rowLabelFont=m.AC_Font_28
  	m.contentRow.rowLabelColor="#ffffff"
  
  
  	m.contentRow.ObserveField("rowItemSelected","homeContentSelection")' as Boolean
  	m.contentRow.ObserveField("rowItemFocused","homeContentFocused")' as Boolean
  
  
  	m.appLogo=m.top.findNode("appLogo")
  	m.appLogo.height=m.global.appLogoHeight
  	m.appLogo.width=m.global.appLogoWidth
  	m.appLogo.translation=[1920-m.global.appLogoWidth-100,1080-m.global.appLogoHeight-50]
  
  	m.videoPlayer=m.top.findNode("videoPlayer")
  	m.videoPlayer.ObserveField("state","onStateChangedForVideo")' as Boolean
  	m.videoPlayer.ObserveField("position","onVideoPositionRender")' as Boolean
  
  
  	m.peviousestate=""
  	m.adPlayToBeDone=false
  	m.adPlayBackInterval=0
  	m.introVideo = m.top.createChild("Video")
      m.introVideo.observeField("state", "onIntroVideoStateChange")
      m.introVideoContent = createObject("roSGNode", "ContentNode")
      m.introVideoContent.url = "https://adilo.bigcommand.com/33b5dad2-f10c-43eb-a910-346c2b4eeee9.mp4"
      m.introVideoContent.streamFormat = "mp4"
      m.introVideoContent.title = ""
      m.introVideo.content = m.introVideoContent
      m.introVideo.control = "play"
      m.introVideo.visible = true
  	m.top.signalBeacon("AppLaunchComplete")
  end sub
  
  sub onIntroVideoStateChange()
      if m.introVideo.state = "finished" then
          m.introVideo.visible = false
          m.introVideo.unobserveField("state")
          m.introVideo.control = "stop"
          loadDataForUI()
      end if
  end sub
  
  
  Sub loadDataForUI()
  	getURLCallGet("https://api.npoint.io/b1f1581fcb537ed08ceb","contentDataCall")
  ENd Sub
  
  SUb setFocus()
  	m.focusKey=0
  	updateFocus()
  End SUb
  
  Sub loadContentData(json As Object)
  	jsonData=parseJSON(json)
  	deeplink=(m.top.deeplinkValues) ' as Object
  	if jsonData<>invalid
  		if jsonData.tvSpecials<>invalid and jsonData.tvSpecials.Count()>0
  			m.container=[]
  			for each item in jsonData.tvSpecials
                  dateTime=createObject("roDateTime")
                  if item.releaseDate<>invalid
                      releaseDate=item.releaseDate+"T00:00:00+00:00"
                      dateTime.FromISO8601String(releaseDate)
                      item.AddReplace("newReleaseDate",dateTime.AsSeconds())
                  end if
                  m.container.Push(item)
              end for
              m.finalContainer=[]
  
              for each item in jsonData.categories
                  contentData=[]
                  'for each item2 in jsonData.tvSpecials
                  ''	for each item3 in item2.itemIds
                 			for each  content in m.container
                 				for each item2 in content.tags
  	                    		if item.query = item2
  	                        		contentData.Push(content)
  	                        	end if
  	                        end for
                          end for
                     '' end for
                 'end for
                  item.AddReplace("contents",contentData)
                  m.finalContainer.Push(item)
              end for
  
              rowItemSize=[]
              rowHeights=[]
  
              parentNode=createObject("roSGNode","ContentNode")
  			for each item in m.finalContainer
  				if item.contents.Count()>0
  					rowHeights.Push([250])
  					rowItemSize.Push([(345),(194)])
  					shelfNode=createObject("roSGNode","ContentNode")
  					shelfNode.title=Ucase(item.name)
  					for each item2 in item.contents
  						if deeplink<>invalid and deeplink.id<>invalid and item2.id=deeplink.id
  							deeplinkData=item2
  						end if
  						itemNode=createObject("roSGNode","CustomContentNode")
  						itemNode.placeHolderImage="pkg://images/demo-thumb3.png"
  						itemNode.thumbnailImage=item2.thumbnail
  						itemNode.contentTitle=item2.title
  						itemNode.shortDesc=item2.shortDescription
  						itemNode.detailContent=formatJSON(item2)
  						dateTime=createObject("roDateTime")
  						dateTime.FromISO8601String(item2.releaseDate+"T00:00:00+00:00")
  						itemNode.contentReleaseYear=dateTime.GetYear().toStr()
  						itemNode.streamURL=item2.content.videos[0].url
  						if item2.adPlayBackonStartOfVideo<>invalid and item2.adPlayBackURL<>invalid and Lcase(type(item2.adPlayBackURL)).inStr("string")>=0
  							itemNode.addField("adPlayBackonStartOfVideo","bool",true)
  							itemNode.adPlayBackonStartOfVideo=item2.adPlayBackonStartOfVideo
  							itemNode.addField("adPlayBackURL","string",true)
  							itemNode.adPlayBackURL=item2.adPlayBackURL
  							itemNode.adPlayBackInterval=item2.adPlayBackInterval
  						else if item2.adPlayBackonStartOfVideo<>invalid and item2.adPlayBackURL<>invalid and type(item2.adPlayBackURL)="roArray"
  							itemNode.addField("adPlayBackonStartOfVideo","bool",true)
  							itemNode.adPlayBackonStartOfVideo=item2.adPlayBackonStartOfVideo
  							itemNode.addField("adPlayBackURL","array",true)
  							itemNode.adPlayBackURL=item2.adPlayBackURL
  							itemNode.adPlayBackInterval=item2.adPlayBackInterval
  						end if
  						shelfNode.appendChild(itemNode)
  					end for
  					parentNode.appendChild(shelfNode)
  				end if
  			end for
  
  
  			m.contentRow.rowItemSize=rowItemSize
  			m.contentRow.rowHeights=rowHeights
  			m.contentRow.content=parentNode
  			if  deeplink<>invalid and deeplink.type<>invalid
  				contentData=createObject("roSGNode","ContentNode")
  				contentData.title=deeplinkData.title
  				contentData.url=deeplinkData.content.videos[0].url
  				contentData.streamFormat="Auto"
  
  				m.videoplayer.content=contentData
  				m.videoPlayer.control="Play"
  				m.videoPlayer.visible=true
  				m.videoPlayer.EnableTrickPlay=true
  				m.focusKey=3
  				updateFocus()
  			else
  				m.contentRow.visible=true
  				m.focusKey=0
  				updateFocus()
  			end if
  		end if
  	end if
  
  
  End Sub
  
  SUb homeContentSelection()
  
  	content=m.contentRow.content.getChild(m.contentRow.rowItemSelected[0]).getChild(m.contentRow.rowItemSelected[1])
  	m.contentData=createObject("roSGNode","ContentNode")
  	m.contentData.title=content.contentTitle
  	'contentData.live=true
  	m.exactPlayerMediaSeek=0
  	m.contentData.url=content.streamURL
  	m.contentData.streamFormat="Auto"
  	if content.adPlayBackonStartOfVideo<>invalid and content.adPlayBackonStartOfVideo
  		if content.adPlayBackURL<>invalid and Lcase(type(content.adPlayBackURL)).inStr("string")>=0
  			m.adcontent_main=createObject("roSGNode","ContentNode")
  			m.adcontent_main.title=content.contentTitle
  			m.adcontent_main.url=content.adPlayBackURL
  			m.adcontent_main.streamFormat="Auto"
  			m.videoplayer.content=m.adcontent_main
  			m.videoPlayer.control="Play"
  			m.videoPlayer.visible=true
  			m.videoPlayer.EnableTrickPlay=false
  			m.adPlayToBeDone=true
  		else  if content.adPlayBackURL<>invalid and type(content.adPlayBackURL)="roArray"
  			m.adcontent_main=createObject("roSGNode","ContentNode")
  			for each item in content.adPlayBackURL
  				adcontent=createObject("roSGNode","ContentNode")
  				adcontent.title=content.contentTitle
  				adcontent.url=item
  				adcontent.streamFormat="Auto"
  				m.adcontent_main.appendChild(adcontent)
  			end for
  			m.videoplayer.content=m.adcontent_main
  			m.videoplayer.contentIsPlaylist=true
  			m.videoPlayer.control="Play"
  			m.videoPlayer.visible=true
  			m.videoPlayer.EnableTrickPlay=false
  			m.adPlayToBeDone=true
  		end if
  	else
  		m.adPlayToBeDone=false
  		m.videoplayer.content=m.contentData
  		m.videoPlayer.control="Play"
  		m.videoPlayer.visible=true
  		m.videoPlayer.EnableTrickPlay=true
  	end if
  	if content.adPlayBackInterval<>invalid and content.adPlayBackInterval>0
  		m.adPlayBackInterval=content.adPlayBackInterval
  	end if
  	m.focusKey=3
  	updateFocus()
  ENd Sub
  
  Sub homeContentFocused()
  
  	contentData=m.contentRow.content.getChild(m.contentRow.rowItemFocused[0]).getChild(m.contentRow.rowItemFocused[1])
  	m.bannerImage.uri=contentData.thumbnailImage
  	m.bannerTitle.text=Ucase(contentData.contentTitle)
  	m.bannerDesc.text=contentData.shortDesc
  	m.releaseYear.text=contentData.contentReleaseYear
  	m.contentMetadata.visible=true
  	contentJson=parseJSON(contentData.detailContent)
  
  
  
  
  	m.contentGenres.text=""
  	genreIndex=0
  	if contentJson.genres<>invalid and contentJson.genres.Count()>0
  		for each genre in contentJson.genres
  			genreIndex+=1
  			if genreIndex=contentJson.genres.Count()
  				m.contentGenres.text+=genre
  			else
  				m.contentGenres.text+=genre+", "
  			end if
  		end for
  	end if
  End Sub
  
  Sub playLiveVideo()
  	if m.jsonApiData.liveStreaming<>invalid and m.jsonApiData.liveStreaming.enabled<>invalid and m.jsonApiData.liveStreaming.enabled and m.jsonApiData.liveStreaming.src<>invalid and m.jsonApiData.liveStreaming.src<>""
  		m.liveSection.visible=true
  
  		contentData=createObject("roSGNode","ContentNode")
  		contentData.title="Live"
  		'contentData.live=true
  		contentData.url=m.jsonApiData.liveStreaming.src
  		contentData.streamFormat="Auto"
  		m.videoplayer.content=contentData
  		m.videoPlayer.control="Play"
  		m.videoPlayer.visible=true
  		m.videoPlayer.EnableTrickPlay=false
  		m.videoPlayer.enableUI=true
  		m.focusKey=3
  		updateFocus()
  	end if
  End SUb
  
  
  Sub updateFocus()
  
  	if m.focusKey=0
  		m.videoPlayer.visible=false
  		m.contentRow.setFocus(true)
  		m.contentRow.visible=true
  	else if m.focusKey=3
  		m.videoPlayer.setFocus(true)
  	end if
  End SUb
  
  Sub onVideoPositionRender()
  	if m.adPlayBackInterval>0 AND m.adPlayToBeDone=false
  		if m.videoPlayer.state="playing"
  			if Cint(m.videoPlayer.Position)>0 and (Cint(m.videoPlayer.Position) mod m.adPlayBackInterval=0)
  				m.exactPlayerMediaSeek=Cint(m.videoPlayer.Position)+5
  				m.videoPlayer.control="Stop"
  				m.videoplayer.content=m.adcontent_main
  				m.videoplayer.contentIsPlaylist=true
  				m.videoPlayer.control="Play"
  				m.videoPlayer.visible=true
  				m.videoPlayer.EnableTrickPlay=false
  				m.adPlayToBeDone=true
  			end if
  		end if
  	end if
  end sub
  
  SUB onStateChangedForVideo()
  
    print"the state of the video==>"m.videoPlayer.state
    if m.videoPlayer.state="finished"
  
    	if m.adPlayToBeDone=true
    		?"check here"
    		m.adPlayToBeDone=false
  		m.videoplayer.content=m.contentData
    		m.videoPlayer.seek=m.exactPlayerMediaSeek
  		m.videoPlayer.control="Play"
  		m.videoPlayer.visible=true
  		m.videoPlayer.EnableTrickPlay=true
    	else
    		?"check here2"
  	    m.videoPlayer.control="stop"
  	    m.videoPlayer.visible=false
  	    m.focusKey=0
  	    updateFocus()
    	end if
    else if m.videoPlayer.state="buffering"
    else if m.videoPlayer.state="stopped"
  
      m.videoPlayer.control="stop"
      m.focusKey=2
      updateFocus()
    else if m.videoPlayer.state="error"
  
  	m.videoPlayer.control="stop"
  	m.videoPlayer.visible=false
      m.focusKey=0
      updateFocus()
    else if m.videoPlayer.state = "paused"
  
    else if m.videoPlayer.state = "playing" AND m.peviousestate = "paused"
      m.animateOffSet=false
  
    else if m.videoPlayer.state="playing"
  
    else
      m.videoPlayer.control="stop"
  
      m.focusKey=0
      updateFocus()
    end if
  
  
  ENd SUB
  
  
  function onKeyEvent(key as String, press as Boolean) as Boolean
      result = false
  
      if press then
         if key="back"
         		if m.videoPlayer.visible=true
         			m.videoPlayer.visible=false
         			m.videoPlayer.control="Stop"
         			m.focusKey=0
         			updateFocus()
         			result=true
  			end if
  
  		else if key="options"
  
  		else if key="play"
  		else if key="right"
  			if m.focusKey=1 and m.liveSection.visible
  				m.focuskey=2
  				updateFocus()
  				result=true
  			end if
  		else if key="left"
  			if m.focusKey=2
  				m.focuskey=1
  				updateFocus()
  				result=true
  			end if
  		else if key="down"
  			if m.focusKey=1 or m.focusKey=2
  				m.focuskey=0
  				updateFocus()
  				result=true
  			end if
  		else if key="up"
  			if m.focusKey=0
  				m.focuskey=1
  				updateFocus()
  				result=true
  			end if
  
  
         end if
      end if
      return result
  end function
  