156 lines
4.0 KiB
Plaintext
156 lines
4.0 KiB
Plaintext
import "pkg:/components/Navigation/Navigation.bs"
|
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
|
import "pkg:/source/utils/DisposableObserve.bs"
|
|
import "pkg:/source/utils/FocusManagement.bs"
|
|
import "pkg:/source/utils/Locale.bs"
|
|
import "pkg:/source/utils/Logging.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
function Init()
|
|
m.queueList = m.top.findNode("queueList")
|
|
m.queueLabel = m.top.findNode("queueLabel")
|
|
m.clearButton = m.top.findNode("clearButton")
|
|
m.showAnimation = m.top.findNode("showAnimation")
|
|
|
|
DisposableObserveField(m.clearButton, "buttonSelected", FuncName(OnClearButtonSelected))
|
|
DisposableObserveField(m.queueList, "itemSelected", FuncName(OnItemSelected))
|
|
|
|
SetNavigation(m.queueList, "up", m.clearButton)
|
|
SetNavigation(m.clearButton, "down", m.queueList)
|
|
|
|
m.videosDetailsToLoad = []
|
|
end function
|
|
|
|
function Show(_unused as dynamic)
|
|
m.showAnimation.control = "start"
|
|
end function
|
|
|
|
function OnFocusChange() as void
|
|
if not m.top.focus
|
|
return
|
|
end if
|
|
NodeSetFocus(m.queueList, true)
|
|
end function
|
|
|
|
function OnContentSet() as void
|
|
content = m.top.content
|
|
if content = invalid
|
|
if m.loadDetailsTask <> invalid
|
|
m.loadDetailsTask.cancel = true
|
|
m.loadDetailsTask = invalid
|
|
end if
|
|
return
|
|
end if
|
|
|
|
if not content.isSameNode(m.queueList.content)
|
|
m.queueList.content = content
|
|
end if
|
|
|
|
index = content.index
|
|
if IsInt(index) and index <> -1
|
|
m.queueLabel.text = Tr(Locale.VideoQueue.Queue) + ` (${index + 1}/${content.getChildCount()})`
|
|
else
|
|
m.queueLabel.text = Tr(Locale.VideoQueue.Queue) + ` (${content.getChildCount()})`
|
|
end if
|
|
|
|
LoadVideoDetailsIfNeeded()
|
|
end function
|
|
|
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
|
if NavigationKeyHandler(key, press).handled
|
|
return true
|
|
end if
|
|
|
|
if press = false
|
|
return false
|
|
end if
|
|
|
|
if key = "back"
|
|
Close()
|
|
return true
|
|
end if
|
|
return false
|
|
end function
|
|
|
|
function Close()
|
|
m.top.appController@.PopScreen()
|
|
m.top.dispose = true
|
|
end function
|
|
|
|
function OnClearButtonSelected()
|
|
m.top.videoQueue.clearQueue = true
|
|
end function
|
|
|
|
function OnItemSelected() as void
|
|
content = m.queueList.content
|
|
if content = invalid
|
|
return
|
|
end if
|
|
|
|
index = m.queueList.itemSelected
|
|
if index < 0 or index >= content.getChildCount()
|
|
return
|
|
end if
|
|
|
|
videoQueue = m.top.videoQueue
|
|
videoQueue.index = index
|
|
videoQueue.play = true
|
|
end function
|
|
|
|
function LoadVideoDetailsIfNeeded() as void
|
|
content = m.queueList.content
|
|
if content = invalid
|
|
return
|
|
end if
|
|
|
|
videoNodes = content.getChildren(-1, 0)
|
|
|
|
index = m.top.videoQueue.index
|
|
indexInLoadingArray = -1
|
|
|
|
m.videosDetailsToLoad.Clear()
|
|
for i = 0 to videoNodes.Count() - 1
|
|
videoNode = videoNodes[i]
|
|
' If the title is empty, it is likely that the details have not been loaded yet
|
|
if videoNode.title = ""
|
|
m.videosDetailsToLoad.Push(videoNode)
|
|
end if
|
|
|
|
if index = i
|
|
indexInLoadingArray = m.videosDetailsToLoad.Count() - 1
|
|
end if
|
|
end for
|
|
|
|
for each videoNode in videoNodes
|
|
if videoNode.title = ""
|
|
m.videosDetailsToLoad.Push(videoNode)
|
|
end if
|
|
end for
|
|
|
|
if m.videosDetailsToLoad.Count() = 0
|
|
return
|
|
end if
|
|
|
|
LogInfo("Loading video details for", m.videosDetailsToLoad.Count(), "videos")
|
|
|
|
if m.loadDetailsTask <> invalid
|
|
m.loadDetailsTask.cancel = true
|
|
end if
|
|
|
|
m.loadDetailsTask = AsyncTask.Start(Tasks.VideoQueueViewContentTask, {
|
|
videoNodes: m.videosDetailsToLoad
|
|
invidious: m.top.invidious
|
|
index: indexInLoadingArray
|
|
})
|
|
end function
|
|
|
|
function OnDispose()
|
|
m.queueList.content = invalid
|
|
DisposeObservers()
|
|
if m.loadDetailsTask <> invalid
|
|
m.loadDetailsTask.cancel = true
|
|
m.loadDetailsTask = invalid
|
|
end if
|
|
end function
|