Skip to content

Commit de0ade9

Browse files
Add component library sample project
1 parent d2937d1 commit de0ade9

File tree

13 files changed

+325
-0
lines changed

13 files changed

+325
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "brightscript",
6+
"request": "launch",
7+
"name": "Debug",
8+
"rootDir": "${workspaceFolder}/app",
9+
"stopOnEntry": false,
10+
"files": [
11+
"**/*"
12+
],
13+
"componentLibrariesPort": 8080,
14+
"componentLibraries": [
15+
{
16+
"rootDir": "${workspaceFolder}/complib/",
17+
"outFile": "complib.zip",
18+
"files": [
19+
"**/*"
20+
]
21+
}
22+
]
23+
}
24+
]
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
sub init()
2+
loadComplib()
3+
end sub
4+
5+
sub loadComplib()
6+
componentLibrary = m.top.createChild("ComponentLibrary")
7+
componentLibrary.observeFieldScoped("loadStatus", "onComponentLibraryLoadStatusChange")
8+
'get the complib url from the manifest
9+
componentLibrary.uri = createObject("roAppInfo").GetValue("complib_url")
10+
end sub
11+
12+
' observe the ComponentLibrary's loadStatus
13+
sub onComponentLibraryLoadStatusChange(event as object)
14+
status = event.getData()
15+
component = event.getRoSgNode()
16+
print "Complib loadStatus: ", status
17+
18+
'complib has started loading (but isn't ready yet)
19+
if status = "loading" then return
20+
21+
if status = "ready" then
22+
'Complib has loaded and is ready to use
23+
render()
24+
else
25+
'there was an error loading the complib
26+
m.dialog = createObject("roSGNode", "Dialog")
27+
'show a popup explaining that the complib failed to load
28+
dialog.update({
29+
title: "Error!",
30+
message: "Failed to load component library"
31+
})
32+
end if
33+
end sub
34+
35+
sub render()
36+
m.top.createChild("SampleComplib:RedditViewer")
37+
end sub
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<component name="MainScene" extends="Scene">
3+
<script uri="MainScene.brs" />
4+
</component>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Channel Details
2+
title=app
3+
major_version=1
4+
minor_version=0
5+
build_version=0
6+
splash_color=#808080
7+
splash_min_time=0
8+
ui_resolutions=fhd
9+
bs_const=DEBUG=true
10+
complib_url=http://192.168.1.22:8080/complib.zip
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sub Main(inputArguments as object)
2+
screen = createObject("roSGScreen")
3+
m.port = createObject("roMessagePort")
4+
screen.setMessagePort(m.port)
5+
scene = screen.CreateScene("MainScene")
6+
screen.show()
7+
scene.setFocus(true)
8+
9+
while true
10+
msg = wait(0, m.port)
11+
msgType = type(msg)
12+
13+
if msgType = "roSGScreenEvent" then
14+
if msg.isScreenClosed() then
15+
return
16+
end if
17+
end if
18+
end while
19+
end sub
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
sub init()
2+
m.list = m.top.FindNode("list")
3+
m.list.observeField("itemSelected", "onItemSelected")
4+
updateList()
5+
end sub
6+
7+
sub updateList()
8+
if m.progress = invalid then
9+
m.progress = createObject("roSGNode", "ProgressDialog")
10+
m.progress.title = "Loading..."
11+
m.progress.message = "Did you know:" + chr(10) + "You can use the replay key to update the list!"
12+
m.dialog = m.progress
13+
end if
14+
15+
if m.subRedditRequest <> invalid then
16+
m.subRedditRequest.unobserveField("content")
17+
end if
18+
m.subRedditRequest = createObject("roSGNode", "GetSubReddit")
19+
m.subRedditRequest.subReddit = "/r/Roku"
20+
m.subRedditRequest.observeField("content", "onSubRedditRequestContentChange")
21+
m.subRedditRequest.control = "RUN"
22+
end sub
23+
24+
sub onSubRedditRequestContentChange(event as object)
25+
content = event.getData()
26+
m.list.content = content
27+
m.list.setFocus(true)
28+
29+
if m.progress <> invalid then
30+
m.progress.close = true
31+
m.progress = invalid
32+
end if
33+
34+
end sub
35+
36+
sub onItemSelected(event as object)
37+
post = event.getRoSGNode().content.getChild(event.getData())
38+
39+
m.dialog = createObject("roSGNode", "Dialog")
40+
m. dialog.title = post.title
41+
m.dialog.message = post.description
42+
print post
43+
end sub
44+
45+
function onKeyEvent(key as string, press as boolean) as boolean
46+
handled = false
47+
if not press then return handled
48+
49+
if key = "back" then
50+
m.top.appExit = true
51+
else if key = "replay" then
52+
updateList()
53+
end if
54+
55+
return handled
56+
end function
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<component name="RedditViewer" extends="Group">
3+
<script type="text/brightscript" uri="RedditViewer.brs" />
4+
5+
<interface>
6+
<field id="appExit" type="bool" alwaysnotify="true" value="false"/>
7+
</interface>
8+
9+
<children>
10+
<MarkupList id="list" itemComponentName="ListItem" itemSize="[1900, 250]" itemSpacing="[0, 20]" drawFocusFeedback="false" translation="[20, 20]" wrapDividerBitmapUri="" />
11+
</children>
12+
</component>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
sub init()
2+
m.top.functionName = "fetch"
3+
end sub
4+
5+
sub fetch()
6+
listContent = createObject("roSGNode", "ContentNode")
7+
request = createObject("roUrlTransfer")
8+
request.setCertificatesFile("common:/certs/ca-bundle.crt")
9+
request.initClientCertificates()
10+
request.setUrl("https://www.reddit.com" + m.top.subReddit + "/.json")
11+
response = request.getToString()
12+
json = parseJson(response)
13+
14+
listItems = []
15+
for each postDataContainer in json.data.children
16+
postData = postDataContainer.data
17+
post = {
18+
title: postData.title,
19+
selfText: postData.selfText,
20+
thumbnail: postData.thumbnail,
21+
isVideo: postData.is_video,
22+
url: postData.url,
23+
isSelf: postData.isSelf
24+
}
25+
26+
itemContent = {
27+
subType: "ContentNode"
28+
isSelf: post.isSelf
29+
title: post.title
30+
description: post.selfText
31+
url: post.url
32+
}
33+
if post.thumbnail <> "self" and post.thumbnail <> "default" and post.thumbnail <> "image" then
34+
itemContent.SDPosterUrl = post.thumbnail
35+
end if
36+
37+
if post.isVideo then
38+
itemContent.videoUrl = postData.secure_media.reddit_video.hls_url
39+
itemContent.streamformat = "hls"
40+
end if
41+
42+
if postData.media <> invalid and postData.media.type = "youtube.com" then
43+
itemContent.videoUrl = postData.url
44+
itemContent.streamFormat = "youtube"
45+
end if
46+
47+
extension = right(postData.url, 4)
48+
if extension = ".png" or extension = ".jpg" then
49+
itemContent.SDPosterUrl = postData.url
50+
end if
51+
52+
if postData.media <> invalid and postData.media.reddit_video <> invalid then
53+
itemContent.isRedditVideo = true
54+
else
55+
itemContent.isRedditVideo = false
56+
end if
57+
58+
listItems.push(itemContent)
59+
end for
60+
61+
listContent.update(listItems, true)
62+
m.top.content = listContent
63+
end sub
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<component name="GetSubReddit" extends="Task">
3+
<script type="text/brightscript" uri="GetSubReddit.brs" />
4+
5+
<interface>
6+
<field id="subReddit" type="string"/>
7+
<field id="content" type="Node"/>
8+
</interface>
9+
</component>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sub init()
2+
m.imagePoster = m.top.findNode("imagePoster")
3+
m.itemCursor = m.top.findNode("itemCursor")
4+
m.labelGroup = m.top.findNode("labelGroup")
5+
m.titleLabel = m.top.findNode("titleLabel")
6+
m.descriptionLabel = m.top.findNode("descriptionLabel")
7+
m.maxWidth = 1880
8+
m.top.maxLabelWidth = m.maxWidth
9+
end sub
10+
11+
sub onItemContentChange()
12+
m.itemContent = m.top.itemContent
13+
m.titleLabel.text = m.itemContent.title
14+
m.descriptionLabel.text = m.itemContent.description
15+
16+
image = m.top.itemContent.SDPOSTERURL
17+
if image = "" then
18+
m.imagePoster.visible = false
19+
m.labelGroup.translation = [0, 0]
20+
m.maxLabelWidth = m.maxLabelWidth
21+
else
22+
m.imagePoster.uri = m.top.itemContent.SDPOSTERURL
23+
m.imagePoster.visible = true
24+
m.labelGroup.translation = [m.imagePoster.width + 20, 0]
25+
m.top.maxLabelWidth = m.maxWidth - (m.imagePoster.width + 20 + 40)
26+
end if
27+
end sub
28+
29+
sub onFocusPercentChange()
30+
m.itemCursor.opacity = m.top.focusPercent
31+
end sub

0 commit comments

Comments
 (0)