Skip to content

Commit

Permalink
Merge pull request #213 from neilsb/collections
Browse files Browse the repository at this point in the history
Fix Collections for Movies, Episodes & Series
  • Loading branch information
anthonylavado authored Jun 18, 2020
2 parents e0df9f9 + 43bdf50 commit 146e00b
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 128 deletions.
186 changes: 91 additions & 95 deletions components/collections/CollectionDetail.brs
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
34 changes: 5 additions & 29 deletions components/collections/CollectionDetail.xml
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>
7 changes: 7 additions & 0 deletions components/data/AlbumData.brs
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

9 changes: 9 additions & 0 deletions components/data/AlbumData.xml
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>
1 change: 1 addition & 0 deletions components/data/CollectionData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<field id="favorite" type="boolean" />
<field id="watched" type="boolean" />
<field id="type" type="string" value="boxsets" />
<field id="overview" type="string" value="boxsets" />
<field id="json" type="associativearray" onChange="setFields" />
</interface>
<script type="text/brightscript" uri="CollectionData.brs" />
Expand Down
27 changes: 27 additions & 0 deletions components/data/HomeData.brs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ sub setData()
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
end if

else if datum.type = "Video" then
imgParams = { AddPlayedIndicator: datum.UserData.Played }

if datum.UserData.PlayedPercentage <> invalid then
imgParams.Append({ "PercentPlayed": datum.UserData.PlayedPercentage })
end if

imgParams.Append({ "maxHeight": 261 })
imgParams.Append({ "maxWidth": 175 })

if datum.ImageTags.Primary <> invalid then
param = { "Tag" : datum.ImageTags.Primary }
imgParams.Append(param)
end if

m.top.posterURL = ImageURL(datum.id, "Primary", imgParams)

' For wide image, use backdrop
imgParams["maxWidth"] = 464

if datum.ImageTags <> invalid and datum.imageTags.Thumb <> invalid then
imgParams["Tag"] = datum.imageTags.Thumb
m.top.thumbnailUrl = ImageURL(datum.Id, "Thumb", imgParams)
else if datum.BackdropImageTags[0] <> invalid then
imgParams["Tag"] = datum.BackdropImageTags[0]
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
end if
else if datum.type = "MusicAlbum" then
params = { "Tag" : datum.ImageTags.Primary, "maxHeight" : 261, "maxWidth" : 261 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
Expand Down
16 changes: 16 additions & 0 deletions components/data/VideoData.brs
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
11 changes: 11 additions & 0 deletions components/data/VideoData.xml
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>
16 changes: 15 additions & 1 deletion components/home/HomeItem.brs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,26 @@ sub itemContentChanged()
return
end if

if itemData.type = "Video" then
m.itemText.text = itemData.name

if imageWidth = 180
itemPoster.uri = itemData.posterURL
else
itemPoster.uri = itemData.thumbnailURL
end if
return
end if
if itemData.type = "Series" then

m.itemText.text = itemData.name

if usePoster = true then
itemPoster.uri = itemData.widePosterURL
if imageWidth = 180 then
itemPoster.uri = itemData.posterURL
else
itemPoster.uri = itemData.widePosterURL
end if
else
itemPoster.uri = itemData.thumbnailURL
end if
Expand Down
2 changes: 1 addition & 1 deletion components/home/HomeItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<component name="HomeItem" extends="Group">
<children>
<Rectangle id="backdrop" width="464" height="261" translation="[8,5]" />
<Poster id="itemPoster" width="464" height="261" translation="[8,5]" />
<Poster id="itemPoster" width="464" height="261" translation="[8,5]" loadDisplayMode="scaleToZoom" />
<ScrollingLabel id="itemText" horizAlign="center" vertAlign="center" font="font:SmallBoldSystemFont" height="64" maxWidth="456" translation="[8,267]" repeatCount="0" />
<Label id="itemTextExtra" horizAlign="left" vertAlign="center" font="font:SmallBoldSystemFont" height="32" width="456" translation="[8,300]" visible="false" color="#777777FF" />
</children>
Expand Down
Loading

0 comments on commit 146e00b

Please sign in to comment.