Add pagination to the movie list

This commit is contained in:
Nick Bisby 2019-03-11 22:49:17 -05:00
parent 786b66eb3e
commit 449d787d37
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
5 changed files with 169 additions and 6 deletions

View File

@ -87,6 +87,18 @@
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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="Movies" extends="Scene">
<children>
<Pager id="pager" />
<MovieRow
id="MovieSelect"
visible="true"

124
components/Pager.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="Pager" extends="LayoutGroup" >
<interface>
<field id="currentPage" type="integer" onChange="recountPages" />
<field id="maxPages" type="integer" onChange="recountPages" />
<field id="pageFocused" type="node" />
<field id="pageSelected" type="node" />
<field id="escape" type="boolean" alwaysNotify="true" />
</interface>
<script type="text/brightscript">
<![CDATA[
sub init()
m.top.currentPage = 0
m.top.maxPages = 0
m.top.layoutDirection = "horiz"
end sub
sub recountPages()
if m.top.currentPage = 0 or m.top.maxPages = 0
return
end if
while m.top.getChildCount() > 0
m.top.removeChildIndex(0)
end while
currentPage = m.top.currentPage
maxPages = m.top.maxPages
minShown = 1
maxShown = maxPages
if currentPage > 1
addPage("<")
minShown = currentPage - 3
end if
if minShown <= 0 then minShown = 1
if currentPage < maxPages then maxShown = currentPage + 3
if maxShown >= maxPages then maxShown = maxPages
for i=minShown to maxShown step 1
addPage(i)
end for
if currentPage <> maxPages
addPage(">")
end if
m.top.pageFocused = m.top.findNode(stri(currentPage).trim())
m.top.pageFocused.color = "#00ff00ff"
updateLayout()
end sub
sub updateLayout()
dimensions = m.top.getScene().currentDesignResolution
width = m.top.getChildCount() * 50
m.top.translation = [(dimensions.width - width) / 2, dimensions.height - 200]
end sub
sub addPage(i)
p = CreateObject("roSGNode", "Label")
p.height = 50
p.width = 50
p.color = "#a1a1a1FF"
if type(i) = "roInt"
i = stri(i).trim()
end if
p.id = i
p.text = i
m.top.appendChild(p)
end sub
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
if key = "OK"
m.top.pageSelected = m.top.focusedChild
return true
else if key = "left"
focusPrev()
return true
else if key = "right"
focusNext()
return true
else if key = "up"
m.top.escape = true
return true
end if
return false
end function
sub focusNext()
i = getFocusIndex()
if (i + 1) = m.top.getChildCount() then return
m.top.pageFocused.color = "#a1a1a1FF"
m.top.pageFocused = m.top.getChild(i + 1)
m.top.pageFocused.color = "#00ff00ff"
m.top.pageFocused.setFocus(true)
end sub
sub focusPrev()
i = getFocusIndex()
if i = 0 then return
m.top.pageFocused.color = "#a1a1a1FF"
m.top.pageFocused = m.top.getChild(i - 1)
m.top.pageFocused.color = "#00ff00ff"
m.top.pageFocused.setFocus(true)
end sub
function getFocusIndex()
for i=0 to m.top.getChildCount() step 1
if m.top.getChild(i).id = m.top.pageFocused.id then return i
end for
return invalid
end function
]]>
</script>
</component>

View File

@ -99,6 +99,10 @@ function get_token(user as String, password as String)
return invalid
end if
if resp.getString() = ""
return invalid
end if
json = ParseJson(resp.GetString())
set_setting("active_user", json.User.id)

View File

@ -121,25 +121,47 @@ sub ShowMovieOptions(library_id)
themeScene(scene)
options = scene.findNode("MovieSelect")
options_list = ItemList(library_id, {"limit": 30,
"page": 1,
page_size = 30
page_num = 1
options_list = ItemList(library_id, {"limit": page_size,
"StartIndex": page_size * (page_num - 1),
"SortBy": "DateCreated,SortName",
"SortOrder": "Descending" })
options.movieData = options_list
options.observeField("itemFocused", port)
options.observeField("itemSelected", port)
pager = scene.findNode("pager")
pager.currentPage = page_num
pager.maxPages = options_list.TotalRecordCount / page_num
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"
print "STILL LISTENING"
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
options_list = ItemList(library_id, {"limit": page_size,
"StartIndex": page_size * (page_num - 1),
"SortBy": "DateCreated,SortName",
"SortOrder": "Descending" })
options.movieData = options_list
options.setFocus(true)
else if nodeEventQ(msg, "itemSelected")
target = getMsgRowTarget(msg)
ShowMovieDetails(target.movieID)
'showVideoPlayer(target.movieID)
else if nodeEventQ(msg, "itemFocused")
'print "Selected " + msg.getNode()
else
print msg
print msg.getField()
print msg.getData()
end if
end while
end sub