Skip to content

Commit

Permalink
Quick load 20 live tv channels, then load the rest in groups of 100
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Nov 28, 2024
1 parent 9b2227e commit 51513d9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
6 changes: 5 additions & 1 deletion components/liveTv/LoadChannelsTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ end sub

sub loadChannels()

m.top.totalRecordCount = 0
results = []

sort_field = m.top.sortField
Expand All @@ -22,7 +23,9 @@ sub loadChannels()
SortBy: sort_field,
SortOrder: sort_order,
recursive: m.top.recursive,
UserId: m.global.session.user.id
UserId: m.global.session.user.id,
limit: m.top.limit,
startIndex: m.top.startIndex
}

' Handle special case when getting names starting with numeral
Expand Down Expand Up @@ -53,6 +56,7 @@ sub loadChannels()
return
end if

m.top.totalRecordCount = data.TotalRecordCount

for each item in data.Items
channel = createObject("roSGNode", "ChannelData")
Expand Down
3 changes: 2 additions & 1 deletion components/liveTv/LoadChannelsTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<component name="LoadChannelsTask" extends="Task">
<interface>
<field id="limit" type="integer" value="" />
<field id="limit" type="integer" value="100" />
<field id="startIndex" type="integer" value="0" />
<field id="totalRecordCount" type="integer" value="0" />
<field id="filter" type="string" value="All" />
<field id="searchTerm" type="string" value="" />
<field id="sortField" type="string" value="SortName" />
Expand Down
94 changes: 56 additions & 38 deletions components/liveTv/schedule.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import "pkg:/source/enums/ColorPalette.bs"
import "pkg:/source/utils/misc.bs"

sub init()
m.loadedChannelCount = 0
m.channelFirstLoadLimit = 20
m.channelLaterLoadLimit = 100
m.EPGLaunchCompleteSignaled = false
m.scheduleGrid = m.top.findNode("scheduleGrid")
m.detailsPane = m.top.findNode("detailsPane")

m.gridData = createObject("roSGNode", "ContentNode")
m.scheduleGrid.content = m.gridData

m.detailsPane.observeField("watchSelectedChannel", "onWatchChannelSelected")
m.detailsPane.observeField("recordSelectedChannel", "onRecordChannelSelected")
m.detailsPane.observeField("recordSeriesSelectedChannel", "onRecordSeriesChannelSelected")
Expand All @@ -29,20 +35,28 @@ sub init()

m.LoadChannelsTask = createObject("roSGNode", "LoadChannelsTask")
m.LoadChannelsTask.observeField("channels", "onChannelsLoaded")
m.LoadChannelsTask.control = "RUN"
loadChannels(m.channelFirstLoadLimit)

m.top.lastFocus = m.scheduleGrid

m.channelIndex = {}
end sub

sub loadChannels(limit as integer)
m.LoadChannelsTask.limit = limit
m.LoadChannelsTask.startIndex = m.loadedChannelCount
m.LoadChannelsTask.control = "RUN"
end sub

sub channelFilterSet()
m.scheduleGrid.jumpToChannel = 0
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"
m.gridData.removeChildren(m.gridData.getChildren(-1, 0))
m.loadedChannelCount = 0
loadChannels(m.channelFirstLoadLimit)
end if

end sub
Expand All @@ -54,58 +68,50 @@ sub channelsearchTermSet()
if LCase(m.top.searchTerm) = LCase(tr("all")) or m.LoadChannelsTask.searchTerm = LCase(tr("all"))
m.top.searchTerm = " "
m.LoadChannelsTask.searchTerm = " "
startLoadingSpinner()
m.LoadChannelsTask.control = "RUN"
'filter if the searterm is not invalid
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
startLoadingSpinner()
m.LoadChannelsTask.control = "RUN"
end if


startLoadingSpinner()
m.gridData.removeChildren(m.gridData.getChildren(-1, 0))
m.loadedChannelCount = 0
loadChannels(m.channelFirstLoadLimit)
end sub

' Initial list of channels loaded
sub onChannelsLoaded()
gridData = createObject("roSGNode", "ContentNode")

counter = 0
counter = m.loadedChannelCount
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"
if m.LoadChannelsTask.channels.count() = 0 then return

m.LoadProgramDetailsTask = createObject("roSGNode", "LoadProgramDetailsTask")
m.LoadProgramDetailsTask.observeField("programDetails", "onProgramDetailsLoaded")
for each item in m.LoadChannelsTask.channels
m.gridData.appendChild(item)
m.channelIndex[item.Id] = counter
counter = counter + 1
channelIdList = channelIdList + item.Id + ","
end for

m.scheduleGrid.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.scheduleGrid
if m.EPGLaunchCompleteSignaled = false
m.top.signalBeacon("EPGLaunchComplete") ' Required Roku Performance monitoring
m.EPGLaunchCompleteSignaled = true
end if
m.LoadChannelsTask.channels = []
m.LoadScheduleTask = createObject("roSGNode", "LoadScheduleTask")
m.LoadScheduleTask.observeField("schedule", "onScheduleLoaded")

end if
m.LoadScheduleTask.startTime = m.gridStartDate.ToISOString()
m.LoadScheduleTask.endTime = m.gridEndDate.ToISOString()
m.LoadScheduleTask.channelIds = channelIdList
m.LoadScheduleTask.control = "RUN"

m.LoadProgramDetailsTask = createObject("roSGNode", "LoadProgramDetailsTask")
m.LoadProgramDetailsTask.observeField("programDetails", "onProgramDetailsLoaded")

if m.EPGLaunchCompleteSignaled = false
m.top.signalBeacon("EPGLaunchComplete") ' Required Roku Performance monitoring
m.EPGLaunchCompleteSignaled = true
end if
m.LoadChannelsTask.channels = []
end sub

' When LoadScheduleTask completes (initial or more data) and we have a schedule to display
Expand All @@ -119,6 +125,7 @@ sub onScheduleLoaded()
for each item in m.LoadScheduleTask.schedule

channel = m.scheduleGrid.content.GetChild(m.channelIndex[item.ChannelId])
if not isValid(channel) then continue for

if channel.PosterUrl <> ""
item.channelLogoUri = channel.PosterUrl
Expand All @@ -132,11 +139,22 @@ sub onScheduleLoaded()
end for

m.scheduleGrid.showLoadingDataFeedback = false
m.scheduleGrid.setFocus(true)

' Only set focus the first time
if m.loadedChannelCount = 0
m.scheduleGrid.setFocus(true)
end if

group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.scheduleGrid
m.LoadScheduleTask.schedule = []
stopLoadingSpinner()

' Load next group of channels
m.loadedChannelCount += m.LoadChannelsTask.limit
if m.LoadChannelsTask.totalRecordCount > m.loadedChannelCount
loadChannels(m.channelLaterLoadLimit)
end if
end sub

sub onProgramFocused()
Expand Down
4 changes: 4 additions & 0 deletions source/static/whatsNew/1.1.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"description": "Add live TV programs to search results",
"author": "jimdogx"
},
{
"description": "Make live TV schedule responsive faster",
"author": "1hitsong"
},
{
"description": "Fix TV episode watched button text not changing when clicked",
"author": "1hitsong"
Expand Down

0 comments on commit 51513d9

Please sign in to comment.