jf-roku/components/tvshows/TVEpisodes.brs

108 lines
3.3 KiB
Plaintext
Raw Normal View History

import "pkg:/source/api/Image.brs"
import "pkg:/source/api/baserequest.brs"
import "pkg:/source/utils/config.brs"
import "pkg:/source/utils/misc.brs"
2020-02-23 04:47:00 +00:00
sub init()
2021-07-09 20:08:32 +00:00
m.top.optionsAvailable = false
m.rows = m.top.findNode("picker")
2022-06-09 20:51:04 +00:00
m.poster = m.top.findNode("seasonPoster")
m.Shuffle = m.top.findNode("Shuffle")
2022-06-09 20:51:04 +00:00
m.Random = m.top.findNode("Random")
m.tvEpisodeRow = m.top.findNode("tvEpisodeRow")
2022-12-10 22:09:08 +00:00
m.unplayedCount = m.top.findNode("unplayedCount")
m.unplayedEpisodeCount = m.top.findNode("unplayedEpisodeCount")
2022-06-09 20:51:04 +00:00
m.rows.observeField("doneLoading", "updateSeason")
end sub
sub setSeasonLoading()
m.top.overhangTitle = tr("Loading...")
2020-02-23 04:47:00 +00:00
end sub
sub updateSeason()
if m.global.session.user.settings["ui.tvshows.disableUnwatchedEpisodeCount"] = false
if isValid(m.top.seasonData) and isValid(m.top.seasonData.UserData) and isValid(m.top.seasonData.UserData.UnplayedItemCount)
if m.top.seasonData.UserData.UnplayedItemCount > 0
m.unplayedCount.visible = true
m.unplayedEpisodeCount.text = m.top.seasonData.UserData.UnplayedItemCount
end if
2022-12-10 22:41:22 +00:00
end if
2022-12-10 22:09:08 +00:00
end if
2022-06-09 20:51:04 +00:00
imgParams = { "maxHeight": 450, "maxWidth": 300 }
m.poster.uri = ImageURL(m.top.seasonData.Id, "Primary", imgParams)
m.Random.visible = true
m.Shuffle.visible = true
2021-07-09 20:08:32 +00:00
m.top.overhangTitle = m.top.seasonData.SeriesName + " - " + m.top.seasonData.name
2020-02-23 04:47:00 +00:00
end sub
function onKeyEvent(key as string, press as boolean) as boolean
2021-07-09 20:08:32 +00:00
handled = false
2023-05-21 03:24:52 +00:00
if key = "left" and m.tvEpisodeRow.hasFocus()
m.Shuffle.setFocus(true)
return true
end if
if key = "down" and m.Shuffle.hasFocus()
2022-06-09 20:51:04 +00:00
m.Random.setFocus(true)
return true
end if
if key = "up" and m.Random.hasFocus()
m.Shuffle.setFocus(true)
return true
end if
2023-05-21 03:24:52 +00:00
if key = "right" and (m.Random.hasFocus() or m.Shuffle.hasFocus())
2022-06-09 20:51:04 +00:00
m.tvEpisodeRow.setFocus(true)
return true
end if
if key = "OK" or key = "play"
if m.Random.hasFocus()
randomEpisode = Rnd(m.rows.getChild(0).objects.items.count()) - 1
m.top.quickPlayNode = m.rows.getChild(0).objects.items[randomEpisode]
return true
end if
if m.Shuffle.hasFocus()
episodeList = m.rows.getChild(0).objects.items
for i = 0 to episodeList.count() - 1
j = Rnd(episodeList.count() - 1)
temp = episodeList[i]
episodeList[i] = episodeList[j]
episodeList[j] = temp
end for
m.global.queueManager.callFunc("set", episodeList)
m.global.queueManager.callFunc("playQueue")
return true
end if
2022-06-09 20:51:04 +00:00
end if
focusedChild = m.top.focusedChild.focusedChild
if focusedChild.content = invalid then return handled
' OK needs to be handled on release...
proceed = false
if key = "OK"
proceed = true
end if
if press and key = "play" or proceed = true
m.top.lastFocus = focusedChild
itemToPlay = focusedChild.content.getChild(focusedChild.rowItemFocused[0]).getChild(0)
if isValid(itemToPlay) and isValid(itemToPlay.id) and itemToPlay.id <> ""
2022-12-20 22:39:06 +00:00
itemToPlay.type = "Episode"
m.top.quickPlayNode = itemToPlay
2021-07-09 20:08:32 +00:00
end if
handled = true
end if
2021-07-09 20:08:32 +00:00
return handled
end function