Make rudimentary search work

This commit is contained in:
Nick Bisby 2019-03-14 17:50:20 -05:00
parent 7bc6d969fa
commit c5a4ba85a5
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
7 changed files with 204 additions and 3 deletions

View File

@ -12,6 +12,7 @@
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged"/>
<field id="itemWidth" type="integer" />
<!-- mediatype -->
</interface>
<script type="text/brightscript">

View File

@ -9,7 +9,6 @@
<field id="watched" type="boolean" />
<field id="seasons" type="associativearray" />
<field id="full_data" type="associativearray" onChange="setFields" />
<function name="favorite_toggle" />
</interface>
<script type="text/brightscript">
<![CDATA[

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="SearchData" extends="ContentNode">
<interface>
<field id="title" type="string" />
<field id="posterUrl" type="string" />
<field id="mediaType" type="string" />
<field id="mediaID" type="string" />
<field id="full_data" type="associativearray" onChange="setFields" />
</interface>
<script type="text/brightscript">
<![CDATA[
sub setFields()
datum = m.top.full_data
m.top.title = datum.name
m.top.mediaID = datum.id
m.top.mediaType = datum.MediaType
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
else
m.top.posterURL = ""
end if
end sub
]]>
</script>
</component>

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="SearchRow" extends="RowList">
<interface>
<field id="rowSize" type="int" />
<field id="itemData" type="associativeArray" onChange="setData" />
<field id="query" type="string" />
<field id="itemSelected" type="int" />
</interface>
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.itemComponentName = "ListPoster"
m.top.content = getData()
m.top.rowFocusAnimationStyle = "floatingFocus"
updateSize()
m.top.setFocus(true)
end sub
sub updateSize()
m.top.numRows = 1
m.top.rowSize = 5
dimensions = m.top.getScene().currentDesignResolution
border = 75
m.top.translation = [border, border + 115]
textHeight = 50
itemWidth = (dimensions["width"] - border * 2) / m.top.rowSize
itemHeight = itemWidth * 1.5 + textHeight
m.top.itemSize = [dimensions["width"] - border*2, itemHeight]
m.top.itemSpacing = [0, 10]
m.top.rowItemSize = [ itemWidth, itemHeight ]
m.top.rowItemSpacing = [0, 0]
end sub
sub setData()
itemData = m.top.itemData
rowSize = m.top.rowSize
n = itemData.SearchHints.count()
if int(n/rowSize) = n/rowSize then
m.top.numRows = n/rowSize
else
m.top.numRows = n/rowSize + 1
end if
m.top.content = getData()
end sub
function getData()
if m.top.itemData = invalid then
data = CreateObject("roSGNode", "ContentNode")
return data
end if
itemData = m.top.itemData
rowSize = m.top.rowSize
' todo - Or get the old data? I can't remember...
data = CreateObject("roSGNode", "ContentNode")
for rownum=1 to m.top.numRows
row = data.CreateChild("ContentNode")
for i=1 to rowSize
index = (rowNum - 1) * rowSize + i
if index > itemData.SearchHints.count() then exit for
datum = itemData.SearchHints[index-1]
item = row.CreateChild("SearchData")
item.full_Data = datum
end for
end for
return data
end function
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
if key = "down" and (m.top.itemFocused + 1) = m.top.content.getChildCount()
m.top.getScene().findNode("pager").setFocus(true)
m.top.getScene().findNode("pager").getChild(0).setFocus(true)
return true
end if
return false
end function
]]>
</script>
</component>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="SearchResults" extends="Scene">
<children>
<SearchRow
id="SearchSelect"
visible="true"
/>
<Overhang
id="overhang"
title="Search"
/>
<Rectangle id="footerBackdrop" />
<Pager id="pager" />
</children>
</component>

View File

@ -182,7 +182,15 @@ end function
' Returns: { SearchHints, TotalRecordCount }
function SearchMedia(query as String)
resp = APIRequest("Search/Hints", {"searchTerm": query})
return getJson(resp)
data = getJson(resp)
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)
end if
end for
return data
end function
' List items from within a Library

View File

@ -104,7 +104,8 @@ sub ShowLibrarySelect()
else if nodeEventQ(msg, "escape") and msg.getNode() = "search"
library.setFocus(true)
else if nodeEventQ(msg, "search_value")
print "Searching for: " + msg.getRoSGNode().search_value
query = msg.getRoSGNode().search_value
ShowSearchOptions(query)
else if nodeEventQ(msg, "itemSelected")
target = getMsgRowTarget(msg)
if target.libraryType = "movies"
@ -326,6 +327,64 @@ sub ShowTVShowDetails(show_id)
end while
end sub
sub ShowSearchOptions(query)
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
scene = screen.CreateScene("SearchResults")
screen.show()
themeScene(scene)
options = scene.findNode("SearchSelect")
page_num = 1
page_size = 30
sort_order = get_user_setting("search_sort_order", "Descending")
sort_field = get_user_setting("search_sort_field", "DateCreated,SortName")
results = SearchMedia(query)
options.itemData = results
options.query = query
options.observeField("itemSelected", port)
pager = scene.findNode("pager")
pager.currentPage = page_num
pager.maxPages = results.TotalRecordCount / page_size
if pager.maxPages = 0 then pager.maxPages = 1
pager.observeField("escape", port)
pager.observeField("pageSelected", port)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed() then
return
else if nodeEventQ(msg, "escape") and msg.getNode() = "pager"
options.setFocus(true)
else if nodeEventQ(msg, "pageSelected") and pager.pageSelected <> invalid
pager.pageSelected = invalid
page_num = int(val(msg.getData().id))
pager.currentPage = page_num
results = SearchMedia(query)
options.itemData = results
options.setFocus(true)
else if nodeEventQ(msg, "itemSelected")
target = getMsgRowTarget(msg)
' TODO - swap this based on target.mediatype
' types: [ Episode, Movie, Audio, Person, Studio, MusicArtist ]
ShowMovieDetails(target.mediaID)
else
print msg
print msg.getField()
print msg.getData()
end if
end while
end sub
sub showVideoPlayer(id)
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")