Files
playlet-piped/playlet-lib/src/components/ChannelView/ChannelView.bs
T
Brahim Hadriche dab6dc5bc4 Feature/channel view content (#150)
* ChannelView feeds

* Fixes for web app

* Add request id to error message
2023-09-22 17:52:53 -04:00

144 lines
4.1 KiB
Plaintext

import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Types.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init()
m.container = m.top.findNode("container")
m.scrollAnimation = m.top.findNode("scrollAnimation")
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
m.banner = m.top.findNode("banner")
m.thumbnail = m.top.findNode("thumbnail")
m.authorLabel = m.top.findNode("authorLabel")
m.rowList = m.top.FindNode("rowList")
m.banner.ObserveField("loadStatus", FuncName(OnBannerLoadStatus))
m.authorId = ""
InitializeTabs()
end function
function OnNodeready()
m.rowList@.BindNode(invalid)
end function
function OnFocusChange() as void
if not m.top.focus
return
end if
NodeSetFocus(m.rowList, true)
end function
function OnContentSet() as void
content = m.top.content
if content = invalid
return
end if
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.authorLabel.text = content._author
' TODO:P1 handle case where there's no banner - a big portion of the screen is blank
m.banner.uri = content.banner
if StringUtils.IsNullOrEmpty(content.thumbnail)
m.thumbnail.uri = ""
else
if m.thumbnail.uri <> content.thumbnail or m.thumbnail.loadStatus = "failed"
m.thumbnail.loadingBitmapUri = m.thumbnail.uri
m.thumbnail.uri = content.thumbnail
end if
end if
content@.LoadChannel(m.invidious)
authorId = ValidString(content.authorId)
if authorId <> m.authorId and IsArray(content.tabs)
m.authorId = authorId
m.rowList.contentData = CreateChannelFeeds(m.authorId, content.tabs)
end if
end function
function CreateChannelFeeds(authorId as string, tabs as object) as object
if authorId = ""
return invalid
end if
feeds = []
for i = 0 to tabs.count() - 1
tabName = tabs[i]
if m.tabs.DoesExist(tabName)
feeds.Push(m.tabs[tabName](authorId))
end if
end for
return feeds
end function
function OnkeyEvent(key as string, press as boolean) as boolean
if press = false
return false
end if
if key = "back"
Close()
return true
end if
return false
end function
function Close()
m.appController@.PopScreen(invalid)
end function
function OnBannerLoadStatus() as void
status = m.banner.loadStatus
if status <> "ready"
return
end if
aspect = m.banner.bitmapWidth / m.banner.bitmapHeight
m.banner.height = m.banner.width / aspect
m.banner.translation = [0, -m.banner.height]
m.banner.visible = true
startPos = [0, 0]
endPos = [0, m.banner.height]
midPos = [0, m.banner.height / 2]
m.scrollAnimationInterpolator.keyValue = [startPos, midPos, endPos]
m.scrollAnimation.control = "start"
end function
function InitializeTabs()
m.tabs = {
videos: function(authorId as string) as object
return CreateChannelFeed("Latest videos", "channel_videos", authorId)
end function,
shorts: function(authorId as string) as object
return CreateChannelFeed("Shorts", "channel_shorts", authorId)
end function,
streams: function(authorId as string) as object
return CreateChannelFeed("Live", "channel_streams", authorId)
end function,
podcasts: function(authorId as string) as object
return CreateChannelFeed("Podcasts", "channel_podcasts", authorId)
end function,
playlists: function(authorId as string) as object
return CreateChannelFeed("Playlists", "channel_playlists", authorId)
end function,
channels: function(authorId as string) as object
return CreateChannelFeed("Channels", "channel_channels", authorId)
end function
}
end function
function CreateChannelFeed(title as string, endpoint as string, ucid as string) as object
return {
title: title,
apiType: "Invidious",
endpoint: endpoint,
pathParams: {
ucid: ucid
}
}
end function