Hey guys,
One other issue tonight. Building a free preview channel that will upgrade to my currently published pay channel. I am working on the appdetailscreen with the GetUpgrade() and can't seem to get the showpurchasescreen to open when using the Upgrade Button that I installed on the detail screen. I am testing with FakeServer which should allow this to happen based on my understanding. My detail screen is below, any help would be awesome!
Function preShowDetailScreen(breadA=invalid, breadB=invalid) As Object
port=CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")
screen.SetDescriptionStyle("movie")
screen.SetMessagePort(port)
if breadA<>invalid and breadB<>invalid then
screen.SetBreadcrumbText(breadA, breadB)
end if
return screen
End Function
'***************************************************************
'** The show detail screen (springboard) is where the user sees
'** the details for a show and is allowed to select a show to
'** begin playback. This is the main event loop for that screen
'** and where we spend our time waiting until the user presses a
'** button and then we decide how best to handle the event.
'***************************************************************
Function showDetailScreen(screen As Object, showList As Object, showIndex as Integer) As Integer
if validateParam(screen, "roSpringboardScreen", "showDetailScreen") = false return -1
if validateParam(showList, "roArray", "showDetailScreen") = false return -1
refreshShowDetail(screen, showList, showIndex)
'remote key id's for left/right navigation
remoteKeyLeft = 4
remoteKeyRight = 5
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSpringboardScreenEvent" then
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isRemoteKeyPressed()
print "Remote key pressed"
if msg.GetIndex() = remoteKeyLeft then
showIndex = getPrevShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
else if msg.GetIndex() = remoteKeyRight
showIndex = getNextShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
endif
else if msg.isButtonPressed()
print "ButtonPressed"
print "ButtonPressed"
if msg.GetIndex() = 1
PlayStart = RegRead(showList[showIndex].ContentId)
if PlayStart <> invalid then
showList[showIndex].PlayStart = PlayStart.ToInt()
endif
showVideoScreen(showList[showIndex])
refreshShowDetail(screen,showList,showIndex)
endif
if msg.GetIndex() = 2
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
refreshShowDetail(screen,showList,showIndex)
endif
if msg.GetIndex() = 3
endif
if msg.GetIndex() = 4
ShowPurchaseScreen()
endif
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while
return showIndex
End Function
function ShowPurchaseScreen() as Void
' First screen: wait for GetUpgrade from Channel Store
store = CreateObject("roChannelStore")
store.FakeServer(true)
if store = invalid then return
screen1 = CreateObject("roParagraphScreen")
upgrade = ScreenGetUpgrade(screen1, store)
if upgrade = invalid then return
' Second screen: buy offer
screen2 = CreateObject("roParagraphScreen")
if not ScreenPurchase(screen2, screen1, store, upgrade) then return
' Third screen: thanks for buying
screen3 = CreateObject("roParagraphScreen")
ScreenThanks(screen3, screen2)
end function
' ---------------------------------------------------------------------
function ScreenGetUpgrade(screen as Object, store as Object) as Dynamic
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Please wait a moment...")
screen.Show()
store.SetMessagePort(msgport)
store.GetUpgrade()
timer = CreateObject("roTimeSpan")
timer.Mark()
while true
msg = wait(1000, msgport)
if type(msg) = "roChannelStoreEvent" then
if msg.IsRequestSucceeded() then
items = msg.GetResponse()
if items <> invalid and items.count() > 0 then return items[0]
exit while
elseif msg.IsRequestFailed() then
print "channel store req failed: ";msg.GetStatusMessage()
exit while
end if
elseif type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then return invalid
end if
if timer.TotalMilliseconds() > 8000 then
print "Channel Store timeout"
exit while
end if
end while
return invalid
end function
' ---------------------------------------------------------------------
function ScreenPurchase(screen as Object, old_screen as Object, store as Object, upgrade as Object) as Boolean
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Do you want to upgrade?")
screen.AddButton(1, "Buy for " + upgrade.cost)
screen.Show()
old_screen.Close()
while true
msg = wait(0, msgport)
if type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then
return false
elseif msg.IsButtonPressed()
button = msg.GetIndex()
if button = 1 then ' Buy
item = store.DoUpgrade()
if item <> invalid and item <> "" then
print "buy succeeded, item ";item
return true
end if
print "buy failed"
end if
end if
end if
end while
end function
' ---------------------------------------------------------------------
function ScreenThanks(screen as Object, old_screen as Object) as Void
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Thank you for upgrading.")
screen.AddParagraph("Press OK to return to the Roku home screen.")
screen.AddButton(1, "OK")
screen.Show()
old_screen.Close()
while true
msg = wait(0, msgport)
if type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then
return
elseif msg.IsButtonPressed()
return
end if
end if
end while
end function
'**************************************************************
'** Refresh the contents of the show detail screen. This may be
'** required on initial entry to the screen or as the user moves
'** left/right on the springboard. When the user is on the
'** springboard, we generally let them press left/right arrow keys
'** to navigate to the previous/next show in a circular manner.
'** When leaving the screen, the should be positioned on the
'** corresponding item in the poster screen matching the current show
'**************************************************************
Function refreshShowDetail(screen As Object, showList As Object, showIndex as Integer) As Integer
if validateParam(screen, "roSpringboardScreen", "refreshShowDetail") = false return -1
if validateParam(showList, "roArray", "refreshShowDetail") = false return -1
show = showList[showIndex]
'Uncomment this statement to dump the details for each show
'PrintAA(show)
screen.ClearButtons()
if regread(show.contentid) <> invalid and regread(show.contentid).toint() >=30 then
screen.AddButton(1, "Resume playing")
screen.AddButton(2, "Play from beginning")
screen.addbutton(4,"Upgrade")
screen.SetStaticRatingEnabled(false)
else
screen.addbutton(2,"Play")
screen.addbutton(4,"Upgrade")
screen.SetStaticRatingEnabled(false)
end if
screen.SetContent(show)
screen.Show()
End Function
'********************************************************
'** Get the next item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getNextShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getNextShow") = false return -1
nextIndex = showIndex + 1
if nextIndex >= showList.Count() or nextIndex < 0 then
nextIndex = 0
end if
show = showList[nextIndex]
if validateParam(show, "roAssociativeArray", "getNextShow") = false return -1
return nextIndex
End Function
'********************************************************
'** Get the previous item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getPrevShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getPrevShow") = false return -1
prevIndex = showIndex - 1
if prevIndex < 0 or prevIndex >= showList.Count() then
if showList.Count() > 0 then
prevIndex = showList.Count() - 1
else
return -1
end if
end if
show = showList[prevIndex]
if validateParam(show, "roAssociativeArray", "getPrevShow") = false return -1
return prevIndex
End Function