Update Home Screen to Respect User Preferences (#553)

This commit is contained in:
Nick Wallace 2022-05-24 11:23:42 -05:00 committed by GitHub
parent 047f884b35
commit 26d9360fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 954 additions and 296 deletions

View File

@ -3,13 +3,13 @@
<children>
<poster id="backdrop"
loadDisplayMode="scaleToFill"
loadDisplayMode="scaleToFit"
width="1920"
height="1080"
opacity="0.25"
/>
<poster id="backdropTransition"
loadDisplayMode="scaleToFill"
loadDisplayMode="scaleToFit"
width="1920"
height="1080"
opacity="0.25"
@ -39,6 +39,7 @@
<field id="quickPlayNode" type="node" alwaysNotify="true" />
<field id="imageDisplayMode" type="string" value="scaleToZoom" />
<field id="AlphaSelected" type="string" alias="AlphaMenu.itemAlphaSelected" alwaysNotify="true" onChange="onItemAlphaSelected" />
<field id="imageDisplayMode" type="string" value="scaleToFit" />
</interface>
<script type="text/brightscript" uri="pkg:/source/utils/misc.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />

View File

@ -37,7 +37,7 @@ sub setData()
imgParams.Append({ "maxHeight": 261 })
imgParams.Append({ "maxWidth": 464 })
m.top.thumbnailURL = ImageURL(datum.id, "Primary", imgParams)
m.top.thumbnailURL = ImageURL(datum.SeriesId, "Primary", imgParams)
' Add Wide Poster (Series Backdrop)
if datum.ParentThumbImageTag <> invalid
@ -45,7 +45,7 @@ sub setData()
else if datum.ParentBackdropImageTags <> invalid
m.top.widePosterUrl = ImageURL(datum.ParentBackdropItemId, "Backdrop", imgParams)
else if datum.ImageTags.Primary <> invalid
m.top.widePosterUrl = ImageURL(datum.id, "Primary", imgParams)
m.top.posterUrl = ImageURL(datum.SeriesId, "Primary", imgParams)
end if
else if datum.type = "Series"
@ -82,7 +82,7 @@ sub setData()
if datum.ImageTags <> invalid and datum.imageTags.Thumb <> invalid
m.top.thumbnailUrl = ImageURL(datum.Id, "Thumb", imgParams)
else if datum.BackdropImageTags[0] <> invalid
else if datum.BackdropImageTags <> invalid and datum.BackdropImageTags[0] <> invalid
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
end if
@ -106,7 +106,7 @@ sub setData()
else if datum.BackdropImageTags[0] <> invalid
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
end if
else if datum.type = "MusicAlbum"
else if datum.type = "MusicAlbum" or datum.type = "Audio" or datum.type = "Book"
params = { "maxHeight": 261, "maxWidth": 261 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL

View File

@ -12,6 +12,8 @@
<field id="collectionType" type="string" />
<field id="imageWidth" type="integer" value="464" />
<field id="usePoster" type="bool" value="false" />
<field id="stretch" type="bool" value="false" />
<field id="isSmall" type="bool" value="false" />
</interface>
<script type="text/brightscript" uri="pkg:/source/api/baserequest.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />

View File

@ -4,7 +4,7 @@ sub init()
end sub
sub refresh()
m.top.findNode("homeRows").callFunc("updateHomeRows")
m.top.findNode("homeRows").callFunc("loadLibraries")
end sub
sub loadLibraries()

View File

@ -18,8 +18,6 @@ sub itemContentChanged()
itemData = m.top.itemContent
if itemData = invalid then return
itemData.Title = itemData.name ' Temporarily required while we move from "HomeItem" to "JFContentItem"
m.itemPoster.width = itemData.imageWidth
m.itemText.maxWidth = itemData.imageWidth
m.itemTextExtra.width = itemData.imageWidth
@ -32,18 +30,32 @@ sub itemContentChanged()
m.itemIcon.uri = itemData.iconUrl
end if
if itemData.stretch = true
m.itemPoster.loadDisplayMode = "scaleToZoom"
end if
' Format the Data based on the type of Home Data
if itemData.type = "CollectionFolder" or itemData.type = "UserView" or itemData.type = "Channel"
m.itemText.text = itemData.name
m.itemPoster.uri = itemData.widePosterURL
if itemData.isSmall = true
m.backdrop.height = "100"
m.itemText.translation = [0, 20]
itemData.usePoster = false
end if
if itemData.usePoster = true
m.itemPoster.uri = itemData.widePosterURL
end if
return
end if
if itemData.type = "UserView"
if itemData.type = "UserView" and itemData.usePoster = true
m.itemPoster.width = "96"
m.itemPoster.height = "96"
m.itemPoster.translation = "[192, 88]"
m.itemText.text = itemData.name
if itemData.isSmall = true
m.itemText.translation = [8, 10]
end if
m.itemPoster.uri = itemData.widePosterURL
return
end if
@ -52,8 +64,7 @@ sub itemContentChanged()
m.itemText.height = 34
m.itemText.font.size = 25
m.itemText.horizAlign = "left"
m.itemText.vertAlign = "bottom"
m.itemTextExtra.visible = true
' m.itemText.vertAlign = "bottom"
m.itemTextExtra.font.size = 22
' "Program" is from clicking on an "On Now" item on the Home Screen
@ -75,9 +86,12 @@ sub itemContentChanged()
m.itemText.text = itemData.json.SeriesName
if itemData.usePoster = true
m.itemPoster.uri = itemData.widePosterURL
m.itemPoster.uri = itemData.posterURL
else
m.itemPoster.uri = itemData.thumbnailURL
m.itemPoster.uri = itemData.widePosterURL
end if
if itemData.json.ImageURL <> invalid
m.itemPoster.uri = itemData.json.ImageURL
end if
' Set Series and Episode Number for Extra Text
@ -105,6 +119,9 @@ sub itemContentChanged()
else
m.itemPoster.uri = itemData.thumbnailURL
end if
if itemData.json.ImageURL <> invalid
m.itemPoster.uri = itemData.json.ImageURL
end if
' Set Release Year and Age Rating for Extra Text
textExtra = ""
@ -131,22 +148,17 @@ sub itemContentChanged()
else
m.itemPoster.uri = itemData.thumbnailURL
end if
if itemData.json.ImageURL <> invalid
m.itemPoster.uri = itemData.json.ImageURL
end if
return
end if
if itemData.type = "Series"
m.itemText.text = itemData.name
if itemData.usePoster = true
if itemData.imageWidth = 180
m.itemPoster.uri = itemData.posterURL
else
m.itemPoster.uri = itemData.widePosterURL
end if
else
m.itemPoster.uri = itemData.thumbnailURL
m.itemPoster.uri = itemData.posterURL
if itemData.json.ImageURL <> invalid
m.itemPoster.uri = itemData.json.ImageURL
end if
textExtra = ""
if itemData.json.ProductionYear <> invalid
textExtra = StrI(itemData.json.ProductionYear).trim()
@ -163,10 +175,25 @@ sub itemContentChanged()
return
end if
if itemData.type = "MusicAlbum"
if itemData.type = "MusicAlbum" or itemData.type = "Audio" or itemData.type = "Book" or itemData.type = "AudioBook"
m.itemText.text = itemData.name
m.itemTextExtra.text = itemData.json.AlbumArtist
m.itemPoster.uri = itemData.posterURL
if itemData.usePoster = true
if itemData.posterURL <> ""
m.itemPoster.uri = itemData.posterURL
else
m.itemPoster.uri = itemData.json.ImageURL
end if
end if
return
end if
if itemData.type = "Photo" or itemData.type = "PhotoAlbum"
if itemData.usePoster = true
if itemData.json.ImageURL <> invalid
m.itemPoster.uri = itemData.json.ImageURL
end if
end if
return
end if
@ -188,11 +215,13 @@ end sub
'Hide backdrop and icon when poster loaded
sub onPosterLoadStatusChanged()
if m.itemPoster.loadStatus = "ready" and m.itemPoster.uri <> ""
m.backdrop.visible = false
m.itemIcon.visible = false
else
m.backdrop.visible = true
m.itemIcon.visible = true
if m.itemPoster <> invalid
if m.itemPoster.loadStatus = "ready" and m.itemPoster.uri <> ""
m.backdrop.visible = false
m.itemIcon.visible = false
else
m.backdrop.visible = true
m.itemIcon.visible = true
end if
end if
end sub

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="HomeItem" extends="Group">
<children>
<Rectangle id="backdrop" width="464" height="261" translation="[8,5]" />
<Rectangle id="backdrop" width="464" height="270" translation="[8,0]" />
<Poster id="itemIcon" width="100" height="100" translation="[190,85]" loadDisplayMode="scaleToFit" />
<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" />
<Poster id="itemPoster" width="464" height="270" translation="[0,0]" loadDisplayMode="scaleToZoom" />
<ScrollingLabel id="itemText" horizAlign="center" vertAlign="center" font="font:SmallBoldSystemFont" height="64" maxWidth="456" translation="[8,280]" repeatCount="0" />
<Label id="itemTextExtra" horizAlign="left" vertAlign="center" font="font:SmallBoldSystemFont" height="32" width="456" translation="[8,319]" visible="true" color="#777777FF" />
</children>
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged" />

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="HomeRow" extends="ContentNode">
<interface>
<field id="imageWidth" type="integer" value="464" />
<field id="imageWidth" type="integer" value="200" />
<field id="stretch" type="bool" value="false" />
<field id="usePoster" type="bool" value="false" />
</interface>
</component>

File diff suppressed because it is too large Load Diff

View File

@ -7,5 +7,6 @@
<function name="updateHomeRows" />
<function name="loadLibraries" />
</interface>
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
<script type="text/brightscript" uri="HomeRows.brs"/>
</component>

View File

@ -13,12 +13,9 @@ sub loadItems()
resp = APIRequest(url)
data = getJson(resp)
for each item in data.Items
' Skip Books for now as we don't support it (issue #525)
if item.CollectionType <> "books"
tmp = CreateObject("roSGNode", "HomeData")
tmp.json = item
results.push(tmp)
end if
tmp = CreateObject("roSGNode", "HomeData")
tmp.json = item
results.push(tmp)
end for
' Load Latest Additions to Libraries
@ -30,17 +27,20 @@ sub loadItems()
params["ParentId"] = m.top.itemId
params["EnableImageTypes"] = "Primary,Backdrop,Thumb"
params["ImageTypeLimit"] = 1
params["fields"] = "PrimaryImageAspectRatio,BasicSyncInfo,Path"
params["MaxWidth"] = 416
params["MaxHeight"] = 416
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data
' Skip Books for now as we don't support it (issue #525)
if item.Type <> "Book"
tmp = CreateObject("roSGNode", "HomeData")
tmp.json = item
results.push(tmp)
tmp = CreateObject("roSGNode", "HomeData")
item.ImageURL = ImageURL(item.Id, "Primary", params)
if item.type = "Episode"
item.ImageURL = ImageURL(item.SeriesId)
end if
tmp.json = item
results.push(tmp)
end for
' Load Next Up
@ -48,6 +48,7 @@ sub loadItems()
url = "Shows/NextUp"
params = {}
params["Limit"] = 30
params["recursive"] = true
params["SortBy"] = "DatePlayed"
params["SortOrder"] = "Descending"
@ -58,38 +59,96 @@ sub loadItems()
data = getJson(resp)
for each item in data.Items
tmp = CreateObject("roSGNode", "HomeData")
if item.type = "Episode"
item.ImageURL = ImageURL(item.SeriesId, "Backdrop")
else
item.ImageURL = ImageURL(item.Id, "Backdrop")
end if
item.stretch = true
tmp.json = item
results.push(tmp)
end for
' Load Continue Watching
else if m.top.itemsToLoad = "continue"
else if m.top.itemsToLoad = "continueVideo"
url = Substitute("Users/{0}/Items/Resume", get_setting("active_user"))
params = {}
params["Limit"] = 30
params["recursive"] = true
params["SortBy"] = "DatePlayed"
params["SortOrder"] = "Descending"
params["Filters"] = "IsResumable"
params["MediaTypes"] = "Video"
params["EnableImageTypes"] = "Primary,Backdrop,Thumb"
params["ImageTypeLimit"] = 1
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
' Skip Books for now as we don't support it (issue #558)
if item.Type <> "Book"
tmp = CreateObject("roSGNode", "HomeData")
tmp.json = item
results.push(tmp)
tmp = CreateObject("roSGNode", "HomeData")
if item.type = "Episode"
item.ImageURL = ImageURL(item.SeriesId, "Backdrop")
else
item.ImageURL = ImageURL(item.Id, "Backdrop")
end if
item.stretch = true
tmp.json = item
results.push(tmp)
end for
else if m.top.itemsToLoad = "continueAudio"
url = Substitute("Users/{0}/Items/Resume", get_setting("active_user"))
params = {}
params["Limit"] = 30
params["recursive"] = true
params["SortBy"] = "DatePlayed"
params["SortOrder"] = "Descending"
params["Filters"] = "IsResumable"
params["MediaTypes"] = "Audio"
params["EnableImageTypes"] = "Primary,Backdrop,Thumb"
params["ImageTypeLimit"] = 1
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
tmp = CreateObject("roSGNode", "HomeData")
item.ImageURL = ImageURL(item.Id, "Backdrop")
tmp.json = item
results.push(tmp)
end for
else if m.top.itemsToLoad = "continueBook"
url = Substitute("Users/{0}/Items/Resume", get_setting("active_user"))
params = {}
params["Limit"] = 30
params["recursive"] = true
params["SortBy"] = "DatePlayed"
params["SortOrder"] = "Descending"
params["Filters"] = "IsResumable"
params["MediaTypes"] = "Book"
params["EnableImageTypes"] = "Primary,Backdrop,Thumb"
resp = APIRequest(url, params)
data = getJson(resp)
for each item in data.Items
tmp = CreateObject("roSGNode", "HomeData")
item.ImageURL = ImageURL(item.Id, "Backdrop")
tmp.json = item
results.push(tmp)
end for
else if m.top.itemsToLoad = "onNow"
url = "LiveTv/Programs/Recommended"
params = {}
params["Limit"] = 30
params["userId"] = get_setting("active_user")
params["isAiring"] = true
params["limit"] = 16 ' 16 to be consistent with "Latest In"
params["imageTypeLimit"] = 1
params["enableImageTypes"] = "Primary,Thumb,Backdrop"
params["enableTotalRecordCount"] = false

View File

@ -4,6 +4,7 @@
<interface>
<field id="itemsToLoad" type="string" value="libraries" />
<field id="itemId" type="string" />
<field id="nodeNumber" type="integer" />
<field id="metadata" type="assocarray" />
<field id="peopleList" type="array" />
<field id="content" type="array" />

View File

@ -156,7 +156,7 @@ sub Main (args as dynamic) as void
' Nothing to do here, handled in ItemGrid
else
' TODO - switch on more node types
message_dialog("This type is not yet supported: " + selectedItem.type + ".")
message_dialog(Substitute(tr("{0} support is coming soon!"), selectedItem.type))
end if
else if isNodeEvent(msg, "movieSelected")
' If you select a movie from ANYWHERE, follow this flow

View File

@ -38,15 +38,15 @@ end function
function ImageURL(id, version = "Primary", params = {})
' set defaults
if params.maxHeight = invalid
param = { "maxHeight": "384" }
param = { "fillHeight": "331" }
params.append(param)
end if
if params.maxWidth = invalid
param = { "maxWidth": "196" }
param = { "fillWidth": "464" }
params.append(param)
end if
if params.quality = invalid
param = { "quality": "90" }
param = { "quality": "96" }
params.append(param)
end if
url = Substitute("Items/{0}/Images/{1}", id, version)
@ -63,7 +63,7 @@ function UserImageURL(id, params = {})
params.append({ "maxWidth": "300" })
end if
if params.quality = invalid
params.append({ "quality": "90" })
params.append({ "quality": "96" })
end if
url = Substitute("Users/{0}/Images/Primary", id)

View File

@ -141,11 +141,52 @@ sub LoadUserPreferences()
resp = APIRequest(url)
jsonResponse = getJson(resp)
if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid and jsonResponse.CustomPrefs["landing-livetv"] <> invalid
set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"])
if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid
if jsonResponse.CustomPrefs["landing-livetv"] <> invalid
set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"])
end if
' Take into account nones, if nones are in the middle then resort them to the end to be removed later in HomeRows
nones = 0
for i = 0 to 6
if jsonResponse.CustomPrefs["homesection" + i.ToStr()] <> invalid
if jsonResponse.CustomPrefs["homesection" + i.ToStr()] = "none"
nones += 1
else
if nones > 0
j = i - nones
set_user_setting("display.homesection" + i.ToStr(), "none")
set_user_setting("display.homesection" + j.ToStr(), jsonResponse.CustomPrefs["homesection" + i.ToStr()])
else
set_user_setting("display.homesection" + i.ToStr(), jsonResponse.CustomPrefs["homesection" + i.ToStr()])
end if
end if
end if
end for
if jsonResponse.CustomPrefs["homesection0"] = invalid
setHomeScreenDefaults()
end if
else
unset_user_setting("display.livetv.landing")
setHomeScreenDefaults()
end if
' Actual user settings for getting ordered views
url = Substitute("Users/{0}", id)
resp = APIRequest(url)
jsonResponse = getJson(resp)
if jsonResponse <> invalid
set_user_setting("display.userConfig", FormatJson(jsonResponse))
end if
end sub
sub setHomeScreenDefaults()
set_user_setting("display.homesection0", "smalllibrarytiles")
set_user_setting("display.homesection1", "resume")
set_user_setting("display.homesection2", "resumeaudio")
set_user_setting("display.homesection3", "resumebook")
set_user_setting("display.homesection4", "livetv")
set_user_setting("display.homesection5", "nextup")
set_user_setting("display.homesection6", "latestmedia")
end sub
sub LoadUserAbilities(user)