-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from neilsb/collections
Fix Collections for Movies, Episodes & Series
- Loading branch information
Showing
13 changed files
with
242 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,116 @@ | ||
sub init() | ||
main = m.top.findNode("main_group") | ||
dimensions = m.top.getScene().currentDesignResolution | ||
|
||
main.translation=[50, 50] | ||
m.rowList = m.top.findNode("RowList") ' createObject("roSGNode", "RowList") | ||
' m.top.appendChild(m.rowList) | ||
|
||
m.rowList.itemComponentName = "HomeItem" | ||
|
||
formatRowList() | ||
|
||
m.rowList.setfocus(true) | ||
|
||
m.rowList.observeField("rowItemSelected", "itemSelected") | ||
|
||
m.top.findNode("buttons").setFocus(true) | ||
end sub | ||
|
||
sub itemContentChanged() | ||
' Updates video metadata | ||
item = m.top.itemContent | ||
itemData = item.json | ||
sub formatRowList() | ||
|
||
m.top.findNode("poster").uri = m.top.itemContent.posterURL | ||
' how many rows are visible on the screen | ||
m.rowList.numRows = 2 | ||
|
||
' Handle all "As Is" fields | ||
m.top.overhangTitle = itemData.name | ||
setFieldText("releaseYear", itemData.productionYear) | ||
setFieldText("officialRating", itemData.officialRating) | ||
setFieldText("communityRating", str(itemData.communityRating)) | ||
setFieldText("overview", itemData.overview) | ||
m.rowList.rowFocusAnimationStyle = "fixedFocusWrap" | ||
m.rowList.vertFocusAnimationStyle = "fixedFocus" | ||
|
||
setFieldText("runtime", stri(getRuntime()) + " mins") | ||
setFieldText("ends-at", tr("Ends at %1").Replace("%1", getEndTime())) | ||
m.rowList.showRowLabel = [true] | ||
m.rowList.rowLabelOffset = [0, 20] | ||
m.rowList.showRowCounter = [true] | ||
|
||
if itemData.genres.count() > 0 | ||
setFieldText("genres", itemData.genres.join(", ")) | ||
end if | ||
director = invalid | ||
for each person in itemData.people | ||
if person.type = "Director" | ||
director = person.name | ||
exit for | ||
end if | ||
end for | ||
if director <> invalid | ||
setFieldText("director", "Director: " + director) | ||
end if | ||
setFieldText("video_codec", "Video: " + itemData.mediaStreams[0].displayTitle) | ||
setFieldText("audio_codec", "Audio: " + itemData.mediaStreams[1].displayTitle) | ||
' TODO - cmon now. these are buttons, not words | ||
if itemData.taglines.count() > 0 | ||
setFieldText("tagline", itemData.taglines[0]) | ||
end if | ||
setFavoriteColor() | ||
setWatchedColor() | ||
end sub | ||
sideborder = 100 | ||
m.rowList.translation = [111, 155] | ||
|
||
sub setFieldText(field, value) | ||
node = m.top.findNode(field) | ||
if node = invalid or value = invalid then return | ||
m.rowItemSizes = [] | ||
|
||
' Handle non strings... Which _shouldn't_ happen, but hey | ||
if type(value) = "roInt" or type(value) = "Integer" then | ||
value = str(value) | ||
else if type(value) <> "roString" and type(value) <> "String" then | ||
value = "" | ||
end if | ||
itemWidth = 480 | ||
itemHeight = 330 | ||
|
||
m.rowList.itemSize = [1920 - 111 - 27, itemHeight] | ||
' spacing between rows | ||
m.rowList.itemSpacing = [0, 105] | ||
|
||
' spacing between items in a row | ||
m.rowList.rowItemSpacing = [20, 0] | ||
|
||
node.text = value | ||
m.rowList.visible = true | ||
end sub | ||
|
||
function getRuntime() as integer | ||
itemData = m.top.itemContent.json | ||
|
||
' A tick is .1ms, so 1/10,000,000 for ticks to seconds, | ||
' then 1/60 for seconds to minutess... 1/600,000,000 | ||
return round(itemData.RunTimeTicks / 600000000.0) | ||
end function | ||
sub setupRows() | ||
|
||
function getEndTime() as string | ||
itemData = m.top.itemContent.json | ||
for each item in m.top.objects.Items | ||
|
||
date = CreateObject("roDateTime") | ||
duration_s = int(itemData.RunTimeTicks / 10000000.0) | ||
date.fromSeconds(date.asSeconds() + duration_s) | ||
date.toLocalTime() | ||
homeItem = CreateObject("roSGNode", "HomeData") | ||
homeItem.json = item.json | ||
|
||
return formatTime(date) | ||
end function | ||
if homeItem.Type = "Video" or homeItem.Type = "Movie" or homeItem.Type = "Episode" then | ||
|
||
if m.videoRow = invalid then | ||
m.videoRow = CreateObject("roSGNode", "HomeRow") | ||
m.videoRow.title = tr("Videos") | ||
m.videoRow.usePoster = true | ||
m.videoRow.imageWidth = 180 | ||
end if | ||
|
||
m.videoRow.appendChild(homeItem) | ||
|
||
sub setFavoriteColor() | ||
fave = m.top.itemContent.favorite | ||
fave_button = m.top.findNode("favorite-button") | ||
if fave | ||
fave_button.textColor = "#00ff00ff" | ||
fave_button.focusedTextColor = "#269926ff" | ||
else | ||
fave_button.textColor = "0xddddddff" | ||
fave_button.focusedTextColor = "#262626ff" | ||
else if homeItem.Type = "MusicAlbum" | ||
|
||
if m.albumRow = invalid then | ||
m.albumRow = CreateObject("roSGNode", "HomeRow") | ||
m.albumRow.imageWidth = 261 | ||
m.albumRow.title = tr("Albums") | ||
m.albumRow.usePoster = true | ||
end if | ||
|
||
m.albumRow.appendChild(homeItem) | ||
|
||
else if homeItem.Type = "Series" | ||
|
||
if m.seriesRow = invalid then | ||
m.seriesRow = CreateObject("roSGNode", "HomeRow") | ||
m.seriesRow.title = tr("Series") | ||
m.seriesRow.usePoster = true | ||
m.seriesRow.imageWidth = 180 | ||
end if | ||
|
||
m.seriesRow.appendChild(homeItem) | ||
|
||
else | ||
print "Collection - Unknown Type ", homeItem.Type | ||
end if | ||
end for | ||
|
||
data = CreateObject("roSGNode", "ContentNode") | ||
|
||
if m.videoRow <> invalid then | ||
data.appendChild(m.videoRow) | ||
m.rowItemSizes.push([188, 331]) | ||
end if | ||
end sub | ||
|
||
sub setWatchedColor() | ||
watched = m.top.itemContent.watched | ||
watched_button = m.top.findNode("watched-button") | ||
if watched | ||
watched_button.textColor = "#ff0000ff" | ||
watched_button.focusedTextColor = "#992626ff" | ||
else | ||
watched_button.textColor = "0xddddddff" | ||
watched_button.focusedTextColor = "#262626ff" | ||
if m.seriesRow <> invalid then | ||
data.appendChild(m.seriesRow) | ||
m.rowItemSizes.push([188, 331]) | ||
end if | ||
end sub | ||
|
||
function round(f as float) as integer | ||
' BrightScript only has a "floor" round | ||
' This compares floor to floor + 1 to find which is closer | ||
m = int(f) | ||
n = m + 1 | ||
x = abs(f - m) | ||
y = abs(f - n) | ||
if y > x | ||
return m | ||
else | ||
return n | ||
if m.albumRow <> invalid then | ||
data.appendChild(m.albumRow) | ||
m.rowItemSizes.push([261, 331]) | ||
end if | ||
end function | ||
|
||
m.rowList.rowItemSize = m.rowItemSizes | ||
m.rowList.content = data | ||
|
||
end sub | ||
|
||
function itemSelected() | ||
m.top.selectedItem = m.rowList.content.getChild(m.rowList.rowItemSelected[0]).getChild(m.rowList.rowItemSelected[1]) | ||
end function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<component name="CollectionDetail" extends="JFGroup"> | ||
<children> | ||
<LayoutGroup id="main_group" layoutDirection="horiz" > | ||
<Poster id="poster" | ||
translation="[250,150]" | ||
width="400" height="600" /> | ||
<LayoutGroup layoutDirection="vert" translation="[355, 150]" itemSpacings="[25]"> | ||
<LayoutGroup layoutDirection="horiz" itemSpacings="[150]"> | ||
<Label id="releaseYear" /> | ||
<Label id="runtime" /> | ||
<Label id="officialRating" /> | ||
<Label id="communityRating" /> | ||
<Label id="ends-at" /> | ||
</LayoutGroup> | ||
<Label id="genres" /> | ||
<Label id="director" /> | ||
<Label id="video_codec" /> | ||
<Label id="audio_codec" /> | ||
<ButtonGroupHoriz id="buttons" itemSpacings="[10]"> | ||
<Button text="Play" id="play-button" /> | ||
<Button text="Watched" id="watched-button" /> | ||
<Button text="Favorite" id="favorite-button" /> | ||
</ButtonGroupHoriz> | ||
<Label id="tagline" /> | ||
<Label id="overview" /> | ||
|
||
</LayoutGroup> | ||
</LayoutGroup> | ||
<RowList id="rowList" /> | ||
</children> | ||
<interface> | ||
<field id="itemContent" type="node" onChange="itemContentChanged" /> | ||
<field id="collectionId" type="string" onChange="collectionIdChanged" /> | ||
<field id="selectedItem" type="node" alwaysNotify="true" /> | ||
<field id="objects" type="associativearray" onChange="setupRows" /> | ||
</interface> | ||
<script type="text/brightscript" uri="pkg:/source/utils/misc.brs" /> | ||
<script type="text/brightscript" uri="CollectionDetail.brs" /> | ||
</component> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sub setFields() | ||
datum = m.top.json | ||
|
||
m.top.id = datum.id | ||
m.top.title = datum.name | ||
end sub | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<component name="AlbumData" extends="ContentNode"> | ||
<interface> | ||
<field id="id" type="string" /> | ||
<field id="title" type="string" /> | ||
<field id="json" type="associativearray" onChange="setFields" /> | ||
</interface> | ||
<script type="text/brightscript" uri="AlbumData.brs" /> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sub setFields() | ||
datum = m.top.json | ||
|
||
m.top.id = datum.id | ||
m.top.title = datum.name | ||
|
||
end sub | ||
|
||
sub setPoster() | ||
if m.top.image <> invalid | ||
m.top.posterURL = m.top.image.url | ||
else | ||
m.top.posterURL = "" | ||
end if | ||
|
||
end sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<component name="VideoData" extends="ContentNode"> | ||
<interface> | ||
<field id="id" type="string" /> | ||
<field id="title" type="string" /> | ||
<field id="json" type="associativearray" onChange="setFields" /> | ||
<field id="image" type="node" onChange="setPoster" /> | ||
<field id="posterUrl" type="string" /> | ||
</interface> | ||
<script type="text/brightscript" uri="VideoData.brs" /> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.