jf-roku/components/liveTv/schedule.bs

306 lines
11 KiB
Plaintext
Raw Normal View History

2020-11-23 17:13:57 +00:00
sub init()
m.EPGLaunchCompleteSignaled = false
2020-11-23 17:13:57 +00:00
m.scheduleGrid = m.top.findNode("scheduleGrid")
m.detailsPane = m.top.findNode("detailsPane")
m.detailsPane.observeField("watchSelectedChannel", "onWatchChannelSelected")
2022-01-05 03:50:45 +00:00
m.detailsPane.observeField("recordSelectedChannel", "onRecordChannelSelected")
m.detailsPane.observeField("recordSeriesSelectedChannel", "onRecordSeriesChannelSelected")
2020-11-23 17:13:57 +00:00
m.gridStartDate = CreateObject("roDateTime")
m.scheduleGrid.contentStartTime = m.gridStartDate.AsSeconds() - 1800
m.gridEndDate = createObject("roDateTime")
m.gridEndDate.FromSeconds(m.gridStartDate.AsSeconds() + (24 * 60 * 60))
m.scheduleGrid.observeField("programFocused", "onProgramFocused")
m.scheduleGrid.observeField("programSelected", "onProgramSelected")
m.scheduleGrid.observeField("leftEdgeTargetTime", "onGridScrolled")
m.scheduleGrid.channelInfoWidth = 350
m.gridMoveAnimation = m.top.findNode("gridMoveAnimation")
m.gridMoveAnimationPosition = m.top.findNode("gridMoveAnimationPosition")
m.LoadChannelsTask = createObject("roSGNode", "LoadChannelsTask")
m.LoadChannelsTask.observeField("channels", "onChannelsLoaded")
m.LoadChannelsTask.control = "RUN"
m.top.lastFocus = m.scheduleGrid
m.channelIndex = {}
m.spinner = m.top.findNode("spinner")
2020-11-23 17:13:57 +00:00
end sub
2021-08-01 08:49:08 +00:00
sub channelFilterSet()
m.scheduleGrid.jumpToChannel = 0
2021-08-01 08:49:08 +00:00
if m.top.filter <> invalid and m.LoadChannelsTask.filter <> m.top.filter
if m.LoadChannelsTask.state = "run" then m.LoadChannelsTask.control = "stop"
m.LoadChannelsTask.filter = m.top.filter
m.LoadChannelsTask.control = "RUN"
end if
end sub
'Voice Search set
sub channelsearchTermSet()
m.scheduleGrid.jumpToChannel = 0
'Reset filter if user says all
2022-12-06 20:14:12 +00:00
if LCase(m.top.searchTerm) = LCase(tr("all")) or m.LoadChannelsTask.searchTerm = LCase(tr("all"))
m.top.searchTerm = " "
m.LoadChannelsTask.searchTerm = " "
m.spinner.visible = true
m.LoadChannelsTask.control = "RUN"
'filter if the searterm is not invalid
2022-12-06 20:14:12 +00:00
else if m.top.searchTerm <> invalid and LCase(m.LoadChannelsTask.searchTerm) <> LCase(m.top.searchTerm)
if m.LoadChannelsTask.state = "run" then m.LoadChannelsTask.control = "stop"
m.LoadChannelsTask.searchTerm = m.top.searchTerm
m.spinner.visible = true
m.LoadChannelsTask.control = "RUN"
end if
end sub
2020-11-23 17:13:57 +00:00
' Initial list of channels loaded
sub onChannelsLoaded()
gridData = createObject("roSGNode", "ContentNode")
counter = 0
channelIdList = ""
'if search returns channels
if m.LoadChannelsTask.channels.count() > 0
for each item in m.LoadChannelsTask.channels
gridData.appendChild(item)
m.channelIndex[item.Id] = counter
counter = counter + 1
channelIdList = channelIdList + item.Id + ","
end for
m.scheduleGrid.content = gridData
m.LoadScheduleTask = createObject("roSGNode", "LoadScheduleTask")
m.LoadScheduleTask.observeField("schedule", "onScheduleLoaded")
m.LoadScheduleTask.startTime = m.gridStartDate.ToISOString()
m.LoadScheduleTask.endTime = m.gridEndDate.ToISOString()
m.LoadScheduleTask.channelIds = channelIdList
m.LoadScheduleTask.control = "RUN"
2020-11-23 17:13:57 +00:00
m.LoadProgramDetailsTask = createObject("roSGNode", "LoadProgramDetailsTask")
m.LoadProgramDetailsTask.observeField("programDetails", "onProgramDetailsLoaded")
2020-11-23 17:13:57 +00:00
m.scheduleGrid.setFocus(true)
if m.EPGLaunchCompleteSignaled = false
m.top.signalBeacon("EPGLaunchComplete") ' Required Roku Performance monitoring
m.EPGLaunchCompleteSignaled = true
end if
m.LoadChannelsTask.channels = []
2020-11-23 17:13:57 +00:00
end if
2020-11-23 17:13:57 +00:00
end sub
' When LoadScheduleTask completes (initial or more data) and we have a schedule to display
sub onScheduleLoaded()
2022-08-25 03:36:52 +00:00
' make sure we actually have a schedule (i.e. filter by favorites, but no channels have been favorited)
if m.scheduleGrid.content.GetChildCount() <= 0
return
end if
2020-11-23 17:13:57 +00:00
for each item in m.LoadScheduleTask.schedule
channel = m.scheduleGrid.content.GetChild(m.channelIndex[item.ChannelId])
2021-07-09 20:08:32 +00:00
if channel.PosterUrl <> ""
2020-11-23 17:13:57 +00:00
item.channelLogoUri = channel.PosterUrl
end if
2021-07-09 20:08:32 +00:00
if channel.Title <> ""
2020-11-23 17:13:57 +00:00
item.channelName = channel.Title
end if
channel.appendChild(item)
end for
m.scheduleGrid.showLoadingDataFeedback = false
2021-02-09 22:20:57 +00:00
m.scheduleGrid.setFocus(true)
m.LoadScheduleTask.schedule = []
m.spinner.visible = false
2020-11-23 17:13:57 +00:00
end sub
sub onProgramFocused()
m.top.watchChannel = invalid
2022-08-25 03:42:09 +00:00
' Make sure we have channels (i.e. filter set to favorite yet there are none)
2022-08-25 03:36:52 +00:00
if m.scheduleGrid.content.getChildCount() <= 0
channel = invalid
else
channel = m.scheduleGrid.content.GetChild(m.scheduleGrid.programFocusedDetails.focusChannelIndex)
end if
2022-08-25 03:42:09 +00:00
m.detailsPane.channel = channel
2022-05-14 10:13:28 +00:00
m.top.focusedChannel = channel
2020-11-23 17:13:57 +00:00
' Exit if Channels not yet loaded
2022-08-25 03:36:52 +00:00
if channel = invalid or channel.getChildCount() = 0
2020-11-23 17:13:57 +00:00
m.detailsPane.programDetails = invalid
return
end if
prog = channel.GetChild(m.scheduleGrid.programFocusedDetails.focusIndex)
if prog <> invalid and prog.fullyLoaded = false
2020-11-23 17:13:57 +00:00
m.LoadProgramDetailsTask.programId = prog.Id
m.LoadProgramDetailsTask.channelIndex = m.scheduleGrid.programFocusedDetails.focusChannelIndex
m.LoadProgramDetailsTask.programIndex = m.scheduleGrid.programFocusedDetails.focusIndex
m.LoadProgramDetailsTask.control = "RUN"
end if
m.detailsPane.programDetails = prog
end sub
' Update the Program Details with full information
sub onProgramDetailsLoaded()
2021-07-09 20:08:32 +00:00
if m.LoadProgramDetailsTask.programDetails = invalid then return
2020-11-23 17:13:57 +00:00
channel = m.scheduleGrid.content.GetChild(m.LoadProgramDetailsTask.programDetails.channelIndex)
' If TV Show does not have its own image, use the channel logo
if m.LoadProgramDetailsTask.programDetails.PosterUrl = invalid or m.LoadProgramDetailsTask.programDetails.PosterUrl = ""
m.LoadProgramDetailsTask.programDetails.PosterUrl = channel.PosterUrl
end if
2020-11-23 17:13:57 +00:00
channel.ReplaceChild(m.LoadProgramDetailsTask.programDetails, m.LoadProgramDetailsTask.programDetails.programIndex)
m.LoadProgramDetailsTask.programDetails = invalid
m.scheduleGrid.showLoadingDataFeedback = false
2020-11-23 17:13:57 +00:00
end sub
sub onProgramSelected()
' If there is no program data - view the channel
if m.detailsPane.programDetails = invalid
2020-11-23 17:13:57 +00:00
m.top.watchChannel = m.scheduleGrid.content.GetChild(m.scheduleGrid.programFocusedDetails.focusChannelIndex)
return
end if
' Move Grid Down
focusProgramDetails(true)
end sub
' Move the TV Guide Grid down or up depending whether details are selected
2021-07-09 20:08:32 +00:00
sub focusProgramDetails(setFocused)
2020-11-23 17:13:57 +00:00
h = m.detailsPane.height
if h < 400 then h = 400
h = h + 160 + 80
if setFocused = true
2021-07-09 20:08:32 +00:00
m.gridMoveAnimationPosition.keyValue = [[0, 600], [0, h]]
2020-11-23 17:13:57 +00:00
m.detailsPane.setFocus(true)
m.detailsPane.hasFocus = true
m.top.lastFocus = m.detailsPane
else
m.detailsPane.hasFocus = false
2021-07-09 20:08:32 +00:00
m.gridMoveAnimationPosition.keyValue = [[0, h], [0, 600]]
2020-11-23 17:13:57 +00:00
m.scheduleGrid.setFocus(true)
m.top.lastFocus = m.scheduleGrid
end if
m.gridMoveAnimation.control = "start"
end sub
' Handle user selecting "Watch Channel" from Program Details
sub onWatchChannelSelected()
if m.detailsPane.watchSelectedChannel = false then return
' Set focus back to grid before showing channel, to ensure grid has focus when we return
2021-07-09 20:08:32 +00:00
focusProgramDetails(false)
2020-11-23 17:13:57 +00:00
m.top.watchChannel = m.detailsPane.channel
2020-11-23 17:13:57 +00:00
end sub
' As user scrolls grid, check if more data requries to be loaded
sub onGridScrolled()
' If we're within 12 hours of end of grid, load next 24hrs of data
if m.scheduleGrid.leftEdgeTargetTime + (12 * 60 * 60) > m.gridEndDate.AsSeconds()
' Ensure the task is not already (still) running,
if m.LoadScheduleTask.state <> "run"
m.LoadScheduleTask.startTime = m.gridEndDate.ToISOString()
m.gridEndDate.FromSeconds(m.gridEndDate.AsSeconds() + (24 * 60 * 60))
m.LoadScheduleTask.endTime = m.gridEndDate.ToISOString()
m.LoadScheduleTask.control = "RUN"
end if
end if
end sub
2022-01-05 03:50:45 +00:00
' Handle user selecting "Record Channel" from Program Details
sub onRecordChannelSelected()
if m.detailsPane.recordSelectedChannel = false then return
' Set focus back to grid before showing channel, to ensure grid has focus when we return
focusProgramDetails(false)
m.scheduleGrid.showLoadingDataFeedback = true
2022-01-09 05:50:53 +00:00
m.RecordProgramTask = createObject("roSGNode", "RecordProgramTask")
m.RecordProgramTask.programDetails = m.detailsPane.programDetails
m.RecordProgramTask.recordSeries = false
2022-01-09 05:43:17 +00:00
m.RecordProgramTask.observeField("recordOperationDone", "onRecordOperationDone")
m.RecordProgramTask.control = "RUN"
end sub
' Handle user selecting "Record Series" from Program Details
sub onRecordSeriesChannelSelected()
if m.detailsPane.recordSeriesSelectedChannel = false then return
' Set focus back to grid before showing channel, to ensure grid has focus when we return
focusProgramDetails(false)
m.scheduleGrid.showLoadingDataFeedback = true
2022-01-09 05:50:53 +00:00
m.RecordProgramTask = createObject("roSGNode", "RecordProgramTask")
m.RecordProgramTask.programDetails = m.detailsPane.programDetails
m.RecordProgramTask.recordSeries = true
2022-01-09 05:43:17 +00:00
m.RecordProgramTask.observeField("recordOperationDone", "onRecordOperationDone")
m.RecordProgramTask.control = "RUN"
end sub
2022-01-09 05:43:17 +00:00
sub onRecordOperationDone()
if m.RecordProgramTask.recordSeries = true and m.LoadScheduleTask.state <> "run"
2022-01-09 14:56:10 +00:00
m.LoadScheduleTask.control = "RUN"
else
' This reloads just the details for the currently selected program, so that we don't have to
' reload the entire grid...
channel = m.scheduleGrid.content.GetChild(m.scheduleGrid.programFocusedDetails.focusChannelIndex)
prog = channel.GetChild(m.scheduleGrid.programFocusedDetails.focusIndex)
m.LoadProgramDetailsTask.programId = prog.Id
m.LoadProgramDetailsTask.channelIndex = m.scheduleGrid.programFocusedDetails.focusChannelIndex
m.LoadProgramDetailsTask.programIndex = m.scheduleGrid.programFocusedDetails.focusIndex
m.LoadProgramDetailsTask.control = "RUN"
2022-01-09 14:56:10 +00:00
end if
2022-01-05 03:50:45 +00:00
end sub
2020-11-23 17:13:57 +00:00
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
detailsGrp = m.top.findNode("detailsPane")
gridGrp = m.top.findNode("scheduleGrid")
2020-11-23 17:13:57 +00:00
if key = "back" and detailsGrp.isInFocusChain()
2020-11-23 17:13:57 +00:00
focusProgramDetails(false)
detailsGrp.setFocus(false)
gridGrp.setFocus(true)
return true
else if key = "back"
2022-10-20 00:31:38 +00:00
m.LoadChannelsTask.control = "stop"
m.global.sceneManager.callFunc("popScene")
2020-11-23 17:13:57 +00:00
return true
end if
return false
end function