the code
Sub showMoviesScreen()
port=CreateObject("roMessagePort")
dialogPort=CreateObject("roMessagePort")
subMovies = getCategoryListMovies()
countsubMovies = subMovies.Count()
subRedditNamesAfterAsync = CreateObject("roArray", subMovies.Count(), true)
grid = CreateObject("roGridScreen")
grid.SetMessagePort(port)
grid.SetDisplayMode("scale-to-fit")
grid.SetGridStyle("flat-portrait")
grid.SetupLists(countsubMovies)
grid.show()
dialog = showLoadingScreen("Downloading subMovies: 0/" +(countsubMovies-1).tostr(),dialogPort)
list = CreateObject("roArray", subMovies.Count(), true)
request = CreateObject("roArray", 100, true)
'httpPort=CreateObject("roMessagePort")
for j = 1 to subMovies.Count() -1
request[j] = CreateObject("roUrlTransfer")
request[j].SetPort(port)
category = subMovies[j]
api_url = UrlServidor()+"/movies.php?cat="+category
request[j].SetUrl(api_url)
request[j].AsyncGetToString()
print "init list " + j.tostr()
end for
countListAsync = 1 'counting the list but for when the async returns
timer = CreateObject("roTimespan")
while true
msg = wait(0, port)
TotalSeconds = timer.TotalSeconds()
if(TotalSeconds > 90) 'prevent infinite while loop while
exit while
end if
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
print "Codigo:";code
if (code = 200)
newList = invalid
response = msg.GetString()
json = ParseJSON(response)
if(json = invalid)
'do nothing
else
newList = parseJsonPosts(json)
subRedditName = newList[0].subReddit
if(subRedditName <> invalid)
print "got the subreddit= " + subRedditName
subRedditNamesAfterAsync.push(subRedditName)
end if
list[countListAsync] = newList
if(list[countListAsync] = invalid)
'build a failed to load icon for the grid
list[countListAsync] = buildErrorGrid()
END IF
dialog.SetTitle( "Downloading subMovies: "+countListAsync.tostr()+ "/" + (countsubMovies-1).tostr() )
dialog.Show()
'print "[" + msg.GetString() + "]"
END IF
countListAsync = countListAsync+1
if(countListAsync = countsubMovies )
exit while
end if
else
'code was not 200
print "HTTP response was not 200"
END IF
END IF
end while
grid.SetListNames(subRedditNamesAfterAsync) 'we are now setting these asyncornously
dialog.SetTitle( "Loading subMovies" )
dialog.Show()
for i = 0 to subMovies.Count() -1
grid.SetContentList(i, list[i])
end for
grid.SetFocusedListItem(2,0)
'grid.show()
dialog.Close()
while true
msg = wait(10, port)
if msg <> invalid and type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
exit while
else if msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
else if msg.isListItemSelected() then
print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();
'selection = seriesList.GetEntry(msg.GetIndex())[msg.GetData()]
list = seriesList.GetEntry(msg.GetIndex())
if list <> invalid then
selection = list[msg.GetData()]
end if
if selection.Title = "Search"
searchMovies()
else if selection.Title = "Favorites"
FavoritesMovies()
else
showSpringboardScreenMovies(selection)
end if
end if
end if
end while
End Sub
Function getCategoryListMovies() as object
jsonAsString = CreateObject("roUrlTransfer")
jsonAsString.SetURL(UrlServidor()+"/category.php?t=movies")
json = ParseJson(jsonAsString.GetToString())
return json
End Function
Function showLoadingScreen(msg As String,port)
dialog = CreateObject( "roOneLineDialog" )
dialog.SetMessagePort(port)
dialog.ShowBusyAnimation()
dialog.SetTitle( msg )
dialog.Show()
return dialog
END FUNCTION
Function parseJsonPosts(json)
tmpList = CreateObject("roArray", 28, true)
count = 0
for each curShow in json.Videos
'fetch all values from the xml for the current show
item.ContentId = curShow.ContentId
item.ContentType = "episode"
item.Title = curShow.Title
item.Description = curShow.Description
item.Length = curShow.Length
item.Rating = curShow.Rating
item.StarRating = curShow.StarRating
item.Categories = curShow.Categories
item.Director = curShow.Director
item.Actors = curShow.Actors
item.ReleaseDate = curShow.ReleaseDate
item.StreamFormat = curShow.StreamFormat
item.StreamBitrates = curShow.StreamBitrates
item.StreamUrl = curShow.StreamUrl
item.SubtitleUrl = curShow.SubtitleUrl
item.StreamQualities = curShow.StreamQualities
item.HDPosterUrl = curShow.HDPosterUrl
item.SDPosterUrl = curShow.SDPosterUrl
'Set Default screen values for items not in feed
item.HDBranded = curShow.SubtitleUrl
item.IsHD = curShow.SubtitleUrl
item.fullHD = curShow.fullHD
item.Categories = curShow.Categories
item.Actors = curShow.Actors
item.Director = curShow.Director
item.Font = "Large"
item.TextAttrs = {
Color:"#FFCCCCCC",
Font:"Large",
HAlign:"HCenter",
VAlign:"VCenter",
Direction:"LeftToRight"
}
count = count+1
tmpList.Push(item)
end for
return tmpList
END FUNCTION
the json
{"Videos":[{"ContentId":"2162","ContentType":"movie","Title":"Rocky 1 (4K)","Description":"When world heavyweight boxing champ Apollo Creed wants to give an unknown fighter a shot at the title as a publicity stunt, his handlers pick palooka Rocky Balboa, an uneducated collector for a Philadelphia loan shark.","Watched":true,"Length":"7140","Rating":"PG","StarRating":77,"Categories":"4k ","Director":"John G. Avildsen","Actors":"Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers","ReleaseDate":"1976","StreamFormat":"MKV","StreamBitrates":"0","StreamUrl":"20Latino.mkv","SDPosterUrl":"1451440544587.jpg","HDPosterUrl":"1451440544587.jpg","SubtitleUrl":"1451440689145.srt","quality":true,"HDBranded":true,"isHD":true,"fullHD":false}]}
the problem generated
Our system http://www.rokumanager.com