HMS

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

commit 00966fe22de633e2c1410548ede1bb70c32e5744
parent f3f8ba9f15482119f953b0e22604fa7d47f9ac2c
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sun, 12 Jun 2022 15:50:42 -0700

Add Jump To Letters to top row

This adds support to jump to the first category starting with the
selected letter. The images are in .icons/a.jpg, b.jpg, ...

Diffstat:
MHMS/source/appMediaServer.brs | 271+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 155 insertions(+), 116 deletions(-)

diff --git a/HMS/source/appMediaServer.brs b/HMS/source/appMediaServer.brs @@ -4,116 +4,6 @@ '******************************************************************** '****************************************************** -'** Display a scrolling grid of everything on the server -'****************************************************** -Function roPosterMediaServer( url As String, has_keystore As Boolean ) As Object - print "url: ";url - print "has_keystore: "; has_keystore - - port = CreateObject("roMessagePort") - screen = CreateObject("roPosterScreen") - screen.SetMessagePort(port) - screen.SetListStyle("arced-portrait") - screen.setListDisplayMode("scale-to-fit") - - ' Build list of Category Names from the top level directories - listing = getDirectoryListing(url) - if listing = invalid then - print "Failed to get directory listing for ";url - return invalid - end if - categories = displayFiles(listing, {}, true) - Sort(categories, function(k) - return LCase(k[0]) - end function) - titles = catTitles(categories) - screen.SetListNames(titles) - max_titles = titles.Count()-1 - - screen.SetFocusToFilterBanner(true) - last_title = getFocusedItem(url, has_keystore, "filter_pos", max_titles) - screen.SetFocusedList(last_title) - showTimeBreadcrumb(screen, true) - screen.Show() - - cache = CreateObject("roAssociativeArray") - - ' Load the selected title - metadata = getCategoryMetadata(url, categories[last_title][0]) - if metadata.Count() > 0 then - cache.AddReplace(tostr(last_title), metadata) - screen.SetContentList(metadata) - screen.SetFocusedListItem(getFocusedItem(url, has_keystore, titles[last_title], metadata.Count())) - end if - - play_focus = -1 - setup_selected = false - while true - msg = wait(30000, port) - if type(msg) = "roPosterScreenEvent" then - if msg.isRemoteKeyPressed() and msg.getIndex() = 13 then - wasPlayPressed = true - else - wasPlayPressed = false - end if - if msg.isScreenClosed() then - return -1 - elseif msg.isListSelected() then - if msg.GetIndex() = max_titles then - screen.SetContentList(getSetupRow(url)) - setup_selected = true - else - setup_selected = false - last_title = msg.GetIndex() - print "selected "; titles[last_title] - - ' Save this as the last selected filter position - if has_keystore = true then - setKeyValue(url, "filter_pos", tostr(msg.GetIndex())) - end if - screen.SetContentList([]) - - ' Is this cached? If not, clear it and look it up - if not cache.DoesExist(tostr(last_title)) then - metadata = getCategoryMetadata(url, categories[last_title][0]) - cache.AddReplace(tostr(last_title), metadata) - else - metadata = cache.Lookup(tostr(last_title)) - end if - screen.SetContentList(metadata) - screen.SetFocusedListItem(getFocusedItem(url, has_keystore, titles[last_title], metadata.Count())) - end if - elseif msg.isListItemSelected() and setup_selected = true then - checkServerUrl(true) - screen.SetFocusToFilterBanner(true) - elseif msg.isListItemFocused() then - play_focus = msg.getIndex() - elseif msg.isListItemSelected() or wasPlayPressed then - print "Focus is on"; play_focus - if has_keystore = true then - setKeyValue(url, titles[last_title], tostr(play_focus)) - end if - movies = screen.GetContentList() - print movies[play_focus] - result = playMovie(movies[play_focus], url, has_keystore) - if result = true and play_focus < movies.Count() then - ' Advance to the next video and save it - screen.SetFocusedListItem(play_focus+1) - if has_keystore = true then - if play_focus < movies.Count() then - setKeyValue(url, titles[last_title], tostr(play_focus+1)) - end if - end if - end if - showTimeBreadcrumb(screen, true) - end if - else if msg = invalid then - showTimeBreadcrumb(screen, true) - endif - end while -End Function - -'****************************************************** '** Display a roGridScreen of the available media '****************************************************** Function roGridMediaServer( url As String, has_keystore As Boolean ) As Object @@ -159,10 +49,20 @@ Function roGridMediaServer( url As String, has_keystore As Boolean ) As Object msg = wait(idle_timeout, port) if type(msg) = "roGridScreenEvent" then idle_timeout = 30000 - if msg.isRemoteKeyPressed() and msg.getIndex() = 13 then - wasPlayPressed = true - else - wasPlayPressed = false + + ' Only Play to start a video works, none of the others return true + wasPlayPressed = false + backPressed = false + downPressed = false + if msg.isRemoteKeyPressed() then + print "key = "; msg.GetIndex() + if msg.getIndex() = 13 then + wasPlayPressed = true + elseif msg.getIndex() = 0 then + backPressed = true + elseif msg.getIndex() = 3 then + downPressed = true + end if end if if msg.isScreenClosed() then @@ -193,6 +93,19 @@ Function roGridMediaServer( url As String, has_keystore As Boolean ) As Object elseif msg.isListItemSelected() or wasPlayPressed then if focus_row = 0 and focus_col = 0 then checkServerUrl(true) + elseif focus_row = 0 then + ' Select row to jump to A-Z (1-26) + print "col = "; focus_col + search_chr = Chr(64+focus_col) + ' Find the first category that starts with this letter (case-insensitive) + for i = 1 to categories.Count()-1 + first = UCase(Left(categories[i], 1)) + if first >= search_chr then + last_col = getFocusedItem(url, has_keystore, categories[i], metadata.Count()) + grid.SetFocusedListitem(i, focus_col) + exit for + end if + end for else print "row, col = "; focus_row, focus_col if has_keystore = true then @@ -207,6 +120,12 @@ Function roGridMediaServer( url As String, has_keystore As Boolean ) As Object end if end if end if + elseif wasDownPressed then + print "down row = "; focus_row + print "last row = "; categories.Count() + if focus_row = categories.Count() then + print "need to wrap back to top" + end if else print msg endif @@ -237,6 +156,116 @@ Function roGridMediaServer( url As String, has_keystore As Boolean ) As Object end while End Function +'****************************************************** +'** Display a scrolling grid of everything on the server +'****************************************************** +Function roPosterMediaServer( url As String, has_keystore As Boolean ) As Object + print "url: ";url + print "has_keystore: "; has_keystore + + port = CreateObject("roMessagePort") + screen = CreateObject("roPosterScreen") + screen.SetMessagePort(port) + screen.SetListStyle("arced-portrait") + screen.setListDisplayMode("scale-to-fit") + + ' Build list of Category Names from the top level directories + listing = getDirectoryListing(url) + if listing = invalid then + print "Failed to get directory listing for ";url + return invalid + end if + categories = displayFiles(listing, {}, true) + Sort(categories, function(k) + return LCase(k[0]) + end function) + titles = catTitles(categories) + screen.SetListNames(titles) + max_titles = titles.Count()-1 + + screen.SetFocusToFilterBanner(true) + last_title = getFocusedItem(url, has_keystore, "filter_pos", max_titles) + screen.SetFocusedList(last_title) + showTimeBreadcrumb(screen, true) + screen.Show() + + cache = CreateObject("roAssociativeArray") + + ' Load the selected title + metadata = getCategoryMetadata(url, categories[last_title][0]) + if metadata.Count() > 0 then + cache.AddReplace(tostr(last_title), metadata) + screen.SetContentList(metadata) + screen.SetFocusedListItem(getFocusedItem(url, has_keystore, titles[last_title], metadata.Count())) + end if + + play_focus = -1 + setup_selected = false + while true + msg = wait(30000, port) + if type(msg) = "roPosterScreenEvent" then + if msg.isRemoteKeyPressed() and msg.getIndex() = 13 then + wasPlayPressed = true + else + wasPlayPressed = false + end if + if msg.isScreenClosed() then + return -1 + elseif msg.isListSelected() then + if msg.GetIndex() = max_titles then + screen.SetContentList(getSetupRow(url)) + setup_selected = true + else + setup_selected = false + last_title = msg.GetIndex() + print "selected "; titles[last_title] + + ' Save this as the last selected filter position + if has_keystore = true then + setKeyValue(url, "filter_pos", tostr(msg.GetIndex())) + end if + screen.SetContentList([]) + + ' Is this cached? If not, clear it and look it up + if not cache.DoesExist(tostr(last_title)) then + metadata = getCategoryMetadata(url, categories[last_title][0]) + cache.AddReplace(tostr(last_title), metadata) + else + metadata = cache.Lookup(tostr(last_title)) + end if + screen.SetContentList(metadata) + screen.SetFocusedListItem(getFocusedItem(url, has_keystore, titles[last_title], metadata.Count())) + end if + elseif msg.isListItemSelected() and setup_selected = true then + checkServerUrl(true) + screen.SetFocusToFilterBanner(true) + elseif msg.isListItemFocused() then + play_focus = msg.getIndex() + elseif msg.isListItemSelected() or wasPlayPressed then + print "Focus is on"; play_focus + if has_keystore = true then + setKeyValue(url, titles[last_title], tostr(play_focus)) + end if + movies = screen.GetContentList() + print movies[play_focus] + result = playMovie(movies[play_focus], url, has_keystore) + if result = true and play_focus < movies.Count() then + ' Advance to the next video and save it + screen.SetFocusedListItem(play_focus+1) + if has_keystore = true then + if play_focus < movies.Count() then + setKeyValue(url, titles[last_title], tostr(play_focus+1)) + end if + end if + end if + showTimeBreadcrumb(screen, true) + end if + else if msg = invalid then + showTimeBreadcrumb(screen, true) + endif + end while +End Function + '************************************* '** Get the utility row (Setup, Search) '************************************* @@ -266,13 +295,23 @@ End Function '************************************* Function getSetupRow(url As String) As Object ' Setup the Search - setup = CreateObject("roArray", 1, true) + setup = CreateObject("roArray", 27, true) o = CreateObject("roAssociativeArray") o.ContentType = "episode" o.Title = "Setup" o.SDPosterUrl = url+"/Setup-SD.png" o.HDPosterUrl = url+"/Setup-HD.png" setup.Push(o) + + ' Add the A-Z posters + for i = 0 to 25 + o = CreateObject("roAssociativeArray") + o.ContentType = "episode" + o.Title = Chr(Asc("A") + i) + o.SDPosterUrl = url+"/.icons/" + Chr(Asc("a") + i) + ".jpg" + o.HDPosterUrl = url+"/.icons/" + Chr(Asc("a") + i) + ".jpg" + setup.Push(o) + end for return setup End Function @@ -490,7 +529,7 @@ End Function '****************************************************** Function catTitles(categories As Object) As Object titles = CreateObject("roArray", categories.Count()+1, false) - titles.Push("Setup") + titles.Push("Jump To") for i = 0 to categories.Count()-1 titles.Push(getLastElement(categories[i][0])) end for