Skip to content

Commit

Permalink
add SGDEX, minor UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rorpage committed May 9, 2019
1 parent 322cc1c commit 7e89198
Show file tree
Hide file tree
Showing 70 changed files with 8,730 additions and 30 deletions.
30 changes: 21 additions & 9 deletions components/NTunesScene.brs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
sub init()
sub show(args as Object)
m.top.setFocus(true)

m.is_playing = false

m.top.backgroundColor = "0x0960CCFF"
m.top.backgroundUri = ""

setUpLabels()

buildNTunesTask()
Expand Down Expand Up @@ -40,25 +44,33 @@ function setUpAudio() as void

m.audio = m.top.findNode("audio_player")
m.audio.content = audiocontent

m.audiobutton = m.top.findNode("audio_control_button")
m.audiobutton.observeField("buttonSelected", "playAudio")
end function

function refreshData() as void
m.nTunesTask.control = "RUN"
end function

function playAudio() as void
if (m.is_playing) then
m.audio.control = "stop"
m.audiobutton.text = "Play"
m.is_playing = false
else
m.audio.control = "play"
m.audiobutton.text = "Stop"
m.is_playing = true
end if
end function

function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false

if press then
if (key = "play") then
if (m.is_playing) then
m.audio.control = "stop"
m.is_playing = false
else
m.audio.control = "play"
m.is_playing = true
end if

playAudio()
handled = true
endif
endif
Expand Down
33 changes: 12 additions & 21 deletions components/NTunesScene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="NTunesScene" extends="Scene" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd" initialFocus="audio_control_button">
<component name="NTunesScene" extends="BaseScene" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd" initialFocus="audio_control_button">
<script type="text/brightscript" uri="pkg:/components/NTunesScene.brs" />
<children>
<Group id="artwork">
Expand All @@ -9,28 +9,19 @@
height="500"
translation="[100, 100]" />
</Group>
<Group id="song_info">
<Label id="title" text="Now Playing" font="font:LargeBoldSystemFont" translation="[700, 100]" />
<Label id="current_track_title" font="font:MediumBoldSystemFont" text="Loading..." translation="[700, 160]" />
<Label id="current_track_artist_name" translation="[700, 220]" />
<Label id="current_show_name" translation="[700, 280]" />
<Group id="song_info" translation="[700, 100]">
<Label id="title" text="Now Playing" font="font:LargeBoldSystemFont" translation="[0, 0]" />
<Label id="current_track_title" font="font:MediumBoldSystemFont" text="Loading..." translation="[0, 60]" />
<Label id="current_track_artist_name" translation="[0, 120]" />
<Label id="current_show_name" translation="[0, 180]" />
</Group>
<Group id="control_buttons">
<!-- <Label
id="Play"
color="0xFFFFFFFF"
width="100"
height="120"
text="N"
translation="[910,10]">
<Font
id="Sosa-Regular"
role="font"
uri="pkg:/fonts/sosa-regular-webfont.ttf"
size="90" />
</Label> -->
<Group>
<Button
id="audio_control_button"
translation="[100, 700]"
text="Play" />
</Group>
<Audio id="audio_player" />
<Timer id="refresh_timer" repeat="true" duration="5" />
<Timer id="refresh_timer" repeat="true" duration="10" />
</children>
</component>
106 changes: 106 additions & 0 deletions components/SGDEX/ComponentController/ComponentController.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
' Copyright (c) 2018 Roku, Inc. All rights reserved.

sub Init()
m.top.ViewManager = createObject("roSGNode", "ViewManager")
viewStackUI = m.top.findNode("ViewStack")
m.top.ViewManager.viewStackUI = viewStackUI
m.top.ViewManager.observeField("currentView","OnCurrentViewChange")
m.top.observeField("allowCloseChannelOnLastView","OnAllowCloseChannel")
m.top.allowCloseChannelOnLastView = true
end sub

function Show(config as Object)
if GetInterface(config, "ifAssociativeArray") = invalid then
? "Error: Component controller, received wrong config"

return invalid
end if
View = config.View
if View = invalid then View = config.view
contentManager = config.contentManager

data = {}

if View <> invalid then
subTypesSupported = { GridView: "" }
subtype = View.subtype()
parentType = View.parentSubtype(View.subtype())
createContentManager = false
if subtype <> invalid and subTypesSupported[subtype] <> invalid then
createContentManager = true
else if parentType <> invalid and subTypesSupported[parentType] <> invalid then
createContentManager = true
end if

if createContentManager then
if contentManager = invalid then contentManager = CreateObject("roSgNode", "ContentManager")
' attach this View to this content manager
contentManager.Parent = m.top.getparent()

contentManager.callFunc("setView", View)
data.contentManager = contentManager
end if
end if

m.top.ViewManager.callFunc("runProcedure", {
fn: "addView"
fp: [View, data]
})

if contentManager <> invalid then
contentManager.control = "start"
end if
'do other stuff for proper registering and unregistering events
end function

sub OnCurrentViewChange()
m.top.currentView = m.top.ViewManager.currentView
end sub

sub OnAllowCloseChannel(event as Object)
allowCloseChannel = event.getData()
' need to pass this flag to View stack; it will set scene.exitChannel to true if no Views left
m.top.ViewManager.allowCloseChannelWhenNoViews = allowCloseChannel
end sub

function onkeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press AND key = "back"
handled = closeView()
end if

return handled
end function

' handles closing View in View stack
' if no View left, closes scene and exits channel
function closeView() as Boolean
' developer should receive back button when all Views are closed

' save flags locally because developer can change it in wasClosed callback
allowCloseLastViewOnBack = m.top.allowCloseLastViewOnBack
allowCloseChannelOnLastView = m.top.allowCloseChannelOnLastView

result = m.top.ViewManager.ViewCount > 1

' allowCloseLastViewOnBack is checked here because if it is set to true we need to close the View even it is last View in stack
if result or allowCloseLastViewOnBack
m.top.ViewManager.callFunc("runProcedure", {
fn: "closeView"
fp: ["", {}]
})

' result is bool if count of Views is 2 or more, so View in stach is closed and back button successfully handled
if result then return true

' if last View is closed check if developer opens a new one in wasClosed callback, if so, back is handled
if allowCloseLastViewOnBack and not allowCloseChannelOnLastView
if m.top.ViewManager.ViewCount > 0 then return true
end if

if allowCloseLastViewOnBack then
return false
end if
end if
return not allowCloseChannelOnLastView
end function
47 changes: 47 additions & 0 deletions components/SGDEX/ComponentController/ComponentController.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2018 Roku, Inc. All rights reserved. -->

<!-- @Public
ComponentController (CC) is a node that responsible to make basic View interaction logic.
From developer side, CC is used to show Views for different use cases.
There are 2 flags to handle close behaviour:
allowCloseChannelOnLastView:bool=true and allowCloseLastViewOnBack:bool=true
@Sample:
' in Scene context in channel
m.top.ComponentController.callFunc("show", {
view: View
})
-->
<component name="ComponentController" extends="Group" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<interface>
<!-- @Public -->
<!--
holds the reference to view that is currently shown.
Can be used for checking in onkeyEvent
-->
<field id="currentView" type="node" />

<!-- @Public -->
<!-- If developer set this flag channel closes when press back or set close=true on last view -->
<field id="allowCloseChannelOnLastView" type="boolean" value="true" alwaysNotify="true" />

<!-- @Public -->
<!-- If developer set this flag the last View will be closed and developer can open another in wasClosed callback -->
<field id="allowCloseLastViewOnBack" type="boolean" value="true" alwaysNotify="true" />

<!-- @Public -->
<!--
Function that has to be called when you want to add view to view stack
-->
<function name="show" />

<!-- View manager is a reference to node that handles all View stack functionality -->
<field id="ViewManager" type="node" />
</interface>
<script type="text/brightscript" uri="ComponentController.brs" />

<children>
<ViewStack id="ViewStack" />
</children>
</component>
Loading

0 comments on commit 7e89198

Please sign in to comment.