Pass actual image objects back, to make ListPoster more flexible

This commit is contained in:
Nick Bisby 2019-05-09 23:24:19 -05:00
parent 7010c2a3aa
commit aa09a138f0
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
22 changed files with 114 additions and 69 deletions

View File

@ -1,6 +1,10 @@
sub init()
m.title = m.top.findNode("title")
m.title.translation = [2, 0]
m.poster = m.top.findNode("poster")
m.poster.translation = [2, 0]
m.backdrop = m.top.findNode("backdrop")
m.backdrop.color = "#404040FF"
@ -13,25 +17,49 @@ sub updateSize()
m.poster = m.top.findNode("poster")
m.backdrop = m.top.findNode("backdrop")
image = invalid
if m.top.itemContent <> invalid and m.top.itemContent.image <> invalid
image = m.top.itemContent.image
end if
if image = invalid
m.backdrop.visible = true
else
m.backdrop.visible = false
end if
' TODO - abstract this in case the parent doesnt have itemSize
maxSize = m.top.getParent().itemSize
' Always reserve the bottom for the Poster Title
m.title.wrap = true
m.title.maxLines = 2
m.title.width = m.poster.width
m.title.height = 80
m.title.translation = [0, int(maxSize[1]) - m.title.height]
ratio = 1.5
if image <> invalid
ratio = image.height / image.width
end if
m.poster.width = int(maxSize[0]) - 4
m.poster.height = m.poster.width * 1.5
m.poster.height = m.poster.width * ratio
posterVertSpace = int(maxSize[1]) - m.title.height
if m.poster.height > posterVertSpace
' Do a thing to shrink the image if it is too tall
end if
m.poster.translation = [2, (posterVertSpace - m.poster.height) / 2]
m.backdrop.width = m.poster.width
m.backdrop.height = m.poster.height
m.title.wrap = true
m.title.maxLines = 2
m.title.width = m.poster.width
m.title.height = int(maxSize[1]) - m.poster.height
m.title.translation = [0, m.poster.height]
end sub
function itemContentChanged() as void
updateSize()
m.title = m.top.findNode("title")
m.poster = m.top.findNode("poster")
@ -40,8 +68,5 @@ function itemContentChanged() as void
m.title.text = itemData.title
m.poster.uri = itemData.posterUrl
if itemData.mediaType = "Episode"
m.poster.height = m.poster.width * 9/16
m.poster.translation = [2, m.poster.width / 2]
end if
updateSize()
end function

View File

@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="ListPoster" extends="Group">
<children>
<Rectangle id="backdrop"
translation="[2, 0]"
/>
<Poster id="poster"
translation="[2, 0]"
/>
<Rectangle id="backdrop" />
<Poster id="poster" />
<Label id="title"
horizAlign="center"
font="font:SmallSystemFont"

View File

@ -21,7 +21,7 @@ sub updateSize()
border = 75
m.top.translation = [border, border + 115]
textHeight = 50
textHeight = 80
' Do we decide width by rowSize, or rowSize by width...
itemWidth = (dimensions["width"] - border*2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -7,9 +7,11 @@ sub setFields()
m.top.favorite = datum.UserData.isFavorite
m.top.watched = datum.UserData.played
end sub
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if

View File

@ -3,6 +3,7 @@
<interface>
<field id="id" type="string" />
<field id="title" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterUrl" type="string" />
<field id="collectionID" type="string" />
<field id="description" type="string" />

View File

@ -12,10 +12,8 @@ sub setFields()
end sub
sub setPoster()
json = m.top.json
if json.posterURL <> invalid
m.top.posterURL = json.posterURL
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if

View File

@ -2,6 +2,7 @@
<component name="MovieData" extends="ContentNode">
<interface>
<field id="title" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterUrl" type="string" />
<field id="movieID" type="string" />
<field id="description" type="string" />

View File

@ -4,9 +4,11 @@ sub setFields()
m.top.id = datum.id
m.top.title = datum.name
m.top.type = datum.Type
end sub
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if

View File

@ -4,7 +4,8 @@
<field id="id" type="string" />
<field id="type" type="string" />
<field id="title" type="string" />
<field id="posterUrl" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="json" type="associativearray" onChange="setFields" />
</interface>
<script type="text/brightscript" uri="search-result.brs" />

View File

@ -4,12 +4,16 @@ sub setFields()
m.top.title = datum.name
m.top.overview = datum.overview
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
else
m.top.posterURL = ""
end if
setPoster()
'm.top.seasons = TVSeasons(datum.id)
'm.top.nextup = TVNext(datum.id)
end sub
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if
end sub

View File

@ -6,6 +6,7 @@
<field id="description" type="string" />
<field id="seasons" type="associativearray" />
<field id="nextup" type="associativearray" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="json" type="associativearray" onChange="setFields" />
<function name="loadSeasons" />

View File

@ -6,9 +6,11 @@ sub setFields()
m.top.showID = datum.SeriesID
m.top.seasonID = datum.SeasonID
m.top.overview = datum.overview
end sub
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if

View File

@ -3,6 +3,7 @@
<interface>
<field id="id" type="string" />
<field id="title" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="showID" type="string" />
<field id="seasonID" type="string" />

View File

@ -5,9 +5,14 @@ sub setFields()
m.top.title = datum.name
m.top.overview = datum.overview
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
setPoster()
end sub
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if
end sub

View File

@ -3,7 +3,8 @@
<interface>
<field id="id" type="string" />
<field id="title" type="string" />
<field id="posterUrl" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="description" type="string" />
<field id="json" type="associativearray" onChange="setFields" />
<function name="getPoster" />

View File

@ -21,7 +21,7 @@ sub updateSize()
border = 75
m.top.translation = [border, border + 115]
textHeight = 75
textHeight = 80
' Do we decide width by rowSize, or rowSize by width...
itemWidth = (dimensions["width"] - border*2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -23,7 +23,7 @@ sub updateSize()
border = 75
m.top.translation = [border, border + 115]
textHeight = 50
textHeight = 80
itemWidth = (dimensions["width"] - border * 2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -17,7 +17,7 @@ sub updateSize()
border = 75
m.top.translation = [border, border + 115]
textHeight = 75
textHeight = 80
itemWidth = (dimensions["width"] - border*2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -22,7 +22,7 @@ sub updateSize()
border = 50
m.top.translation = [border, border]
textHeight = 75
textHeight = 80
' Do we decide width by rowSize, or rowSize by width...
itemWidth = (dimensions["width"] - border*2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -22,7 +22,7 @@ sub updateSize()
border = 75
m.top.translation = [border, border + 115]
textHeight = 75
textHeight = 80
' Do we decide width by rowSize, or rowSize by width...
itemWidth = (dimensions["width"] - border*2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight

View File

@ -13,6 +13,25 @@ function ItemImages(id="" as String)
end function
function PosterImage(id)
images = ItemImages(id)
primary_image = invalid
for each image in images
if image.imagetype = "Primary"
primary_image = image
else if image.imagetype = "Logo" and primary_image = invalid
primary_image = image
else if image.imagetype = "Thumb" and primary_image = invalid
primary_image = image
' maybe find more fallback images
end if
end for
return primary_image
end function
function ImageURL(id, version="Primary", params={})
if params.count() = 0
params = {"maxHeight": "384", "maxWidth": "196", "quality": "90"}

View File

@ -46,15 +46,8 @@ function SearchMedia(query as String)
data = getJson(resp)
results = []
for each item in data.SearchHints
if item.type = "Movie"
item.posterURL = ImageURL(item.id)
else if item.type = "Person"
item.posterURL = ImageURL(item.id)
else if item.type = "Episode"
item.posterURL = ImageURL(item.id)
end if
tmp = CreateObject("roSGNode", "SearchData")
tmp.image = PosterImage(item.itemid)
tmp.json = item
results.push(tmp)
end for
@ -76,29 +69,19 @@ function ItemList(library_id=invalid as String, params={})
data = getJson(resp)
results = []
for each item in data.Items
' TODO - actually check item for available images
if item.imagetags.primary <> invalid
item.posterURL = ImageURL(item.id, "Primary")
' item.posterAspect = item.PrimaryImageAspectRatio
else if item.imagetags.logo <> invalid
item.posterURL = ImageURL(item.id, "Logo")
else if item.imagetags.thumb <> invalid
item.posterURL = ImageURL(item.id, "Thumb")
else
' Maybe find more fallback images!
end if
if item.type = "Movie"
tmp = CreateObject("roSGNode", "MovieData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
else if item.type = "Series"
tmp = CreateObject("roSGNode", "SeriesData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
else if item.type = "BoxSet"
tmp = CreateObject("roSGNode", "CollectionData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
else
@ -116,21 +99,24 @@ function ItemMetaData(id as String)
url = Substitute("Users/{0}/Items/{1}", get_setting("active_user"), id)
resp = APIRequest(url)
data = getJson(resp)
data.posterURL = ImageURL(data.id)
if data.type = "Movie"
tmp = CreateObject("roSGNode", "MovieData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else if data.type = "Series"
tmp = CreateObject("roSGNode", "SeriesData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else if data.type = "Episode"
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else if data.type = "BoxSet"
tmp = CreateObject("roSGNode", "CollectionData")
tmp.image = PosterImage(data.id)
tmp.json = item
return tmp
else
@ -149,8 +135,8 @@ function TVSeasons(id as String)
data = getJson(resp)
results = []
for each item in data.Items
item.posterURL = ImageURL(item.id)
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
end for
@ -165,8 +151,8 @@ function TVEpisodes(show_id as String, season_id as String)
data = getJson(resp)
results = []
for each item in data.Items
item.posterURL = ImageURL(item.id)
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
end for
@ -181,7 +167,7 @@ function TVNext(id as String)
data = getJson(resp)
for each item in data.Items
item.posterURL = ImageURL(item.id)
item.image = PosterImage(item.id)
end for
return data
end function