HMS

Home Media Server for Roku Players
git clone https://www.brianlane.com/git/HMS
Log | Files | Refs | README | LICENSE

commit e31566ca8aa85e7000ed33a1d0f914a60ed3ac7a
parent ac02a3adb6595f93b6f3b42308cd2fd771a4bf00
Author: Brian C. Lane <bcl@ibrianlane.com>
Date:   Mon, 27 May 2013 11:45:22 -0700

Add search screen and row update

Diffstat:
MHMS/source/appDisplayDirectory.brs | 59+++++++++++++++++++++++++++++++++++++----------------------
AHMS/source/searchScreen.brs | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 22 deletions(-)

diff --git a/HMS/source/appDisplayDirectory.brs b/HMS/source/appDisplayDirectory.brs @@ -38,27 +38,13 @@ Function displayDirectory( url As String ) As Object ' Hold all the movie objects screen = CreateObject("roArray", categories.Count(), false) - ' Setup the Search/Setup entries for first row - search = CreateObject("roArray", 2, true) - o = CreateObject("roAssociativeArray") - o.ContentType = "episode" - o.Title = "Setup" - o.SDPosterUrl = url+"/Setup-SD.png" - o.HDPosterUrl = url+"/Setup-HD.png" - search.Push(o) - - o = CreateObject("roAssociativeArray") - o.ContentType = "episode" - o.Title = "Search" - o.SDPosterUrl = url+"/Search-SD.png" - o.HDPosterUrl = url+"/Search-HD.png" - search.Push(o) - ' Add as first row - grid.SetContentList(0, search) + ' Add as utility row + grid.SetContentList(0, getUtilRow(url)) screen.Push(search) ' run the grid showTimeBreadcrumb(grid) + grid.SetFocusedListitem(0, 1) grid.Show() ' Setup each category's list @@ -104,14 +90,20 @@ Function displayDirectory( url As String ) As Object print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex(); print " col: ";msg.GetData() - ' Is this the Search option? - - ' Is this the Setup option? if msg.GetIndex() = 0 and msg.GetData() = 0 then checkServerUrl(true) else if msg.GetIndex() = 0 and msg.GetData() = 1 then -' searchScreen(screen) - print "Search Selected" + ' search returns a roArray of MovieObjects + results = searchScreen(screen) + + ' Make a new search rot + searchRow = getUtilRow(url) + searchRow.Append(results) + ' Remove the old one and add the new one, selecting first result + screen.Shift() + screen.Unshift(searchRow) + grid.SetContentList(0, searchRow) + grid.SetFocusedListitem(0, 2) else playMovie(screen[msg.GetIndex()][msg.GetData()]) end if @@ -122,6 +114,29 @@ Function displayDirectory( url As String ) As Object end while End Function + +' Get the utility row (Search, Setup) +Function getUtilRow(url As String) As Object + ' Setup the Search/Setup entries for first row + search = CreateObject("roArray", 2, true) + o = CreateObject("roAssociativeArray") + o.ContentType = "episode" + o.Title = "Setup" + o.SDPosterUrl = url+"/Setup-SD.png" + o.HDPosterUrl = url+"/Setup-HD.png" + search.Push(o) + + o = CreateObject("roAssociativeArray") + o.ContentType = "episode" + o.Title = "Search" + o.SDPosterUrl = url+"/Search-SD.png" + o.HDPosterUrl = url+"/Search-HD.png" + search.Push(o) + + return search +End Function + + ' Put this into utils Function getLastElement(url As String) As String ' Get last element of URL diff --git a/HMS/source/searchScreen.brs b/HMS/source/searchScreen.brs @@ -0,0 +1,72 @@ +'******************************************************************** +'** Home Media Server Application - Main +'** Copyright (c) 2010-2013 Brian C. Lane All Rights Reserved. +'******************************************************************** + +'******************************************************************** +' Display search string +'******************************************************************** +Function searchScreen(screenItems As Object) As Object +' screenItems is the double roArray of the screen objects. First row is the +' search row, so ignore it. + + port = CreateObject("roMessagePort") + screen = CreateObject("roSearchScreen") + screen.SetMessagePort(port) + screen.SetSearchTermHeaderText("Suggestions:") + screen.SetSearchButtonText("search") + screen.SetClearButtonEnabled(false) + + screen.Show() + + suggestions = invalid + while true + msg = wait(0, screen.GetMessagePort()) + if type(msg) = "roSearchScreenEvent" then + if msg.isScreenClosed() + return invalid + else if msg.isPartialResult() then + print "partial search: "; msg.GetMessage() + suggestions = getSuggestions(screenItems, msg.GetMessage()) + terms = getTitles(suggestions) + screen.SetSearchTerms(terms) + else if msg.isFullResult() + print "full search: "; msg.GetMessage() + return suggestions + else + print "Unknown event: "; msg.GetType(); " msg: ";sg.GetMessage() + end if + end if + end while +End Function + +'******************************************************************** +' Return an array of suggested movies objects +'******************************************************************** +Function getSuggestions(items As Object, needle As String) As Object + suggestions = CreateObject("roArray", 10, true) + ' iterate the whole list, gathering matches on Title + For i = 1 to items.Count()-1 + For Each movie In items[i] + if Instr(1, LCase(movie.Title), needle) <> 0 then + suggestions.Push(movie) + end if + End For + End For + Sort(suggestions, function(k) + return LCase(k.Title) + end function) + return suggestions +End Function + +'******************************************************************** +' Return an array of titles +'******************************************************************** +Function getTitles(movies As Object) As Object + titles = CreateObject("roArray", 10, true) + For Each movie In movies + titles.Push(movie.Title) + End For + return titles +End Function +