Create Component Library (#43)
* Move src under playlet-lib * Update configuration * Update script * Update script * Working version * Vs code config WIP * Package lock sync * Lint fix * Fix images * Reuse config files * Kind of a working setup * Lock node version * Rename scripts to tools * Fix build scripts, lib url system * Lint fix * rale * Fix args and web server * Load fallbacks and build script cleanups * Remove unused method * no message * no message * Remove generic message field * Lint fix * no message * Use loading indicator on main app * Add playlet lib version to settings --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
90df81df4b
commit
9d8a3d1cea
156 files changed
+3341
-213
No files matched your search
@@ -0,0 +1,99 @@
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.FindNode("titleLabel").text = content.title
|
||||
m.top.FindNode("authorLabel").text = content.author
|
||||
|
||||
if IsVideoUpcoming(content)
|
||||
m.top.FindNode("viewCountDateLabel").text = `Premeres in ${TimeUtils.GetFormattedTimeLeft(content.premiereTimestamp)}`
|
||||
else
|
||||
publishedText = validstr(content.publishedText)
|
||||
viewCount = FormatViewCount(content.viewCount)
|
||||
if publishedText = "" and viewCount = ""
|
||||
m.top.FindNode("viewCountDateLabel").text = ""
|
||||
else
|
||||
m.top.FindNode("viewCountDateLabel").text = `${publishedText} • ${viewCount}`
|
||||
end if
|
||||
end if
|
||||
|
||||
m.thumbnail = m.top.FindNode("thumbnail")
|
||||
m.thumbnail.observeField("loadStatus", "OnThumbnailLoadFailed")
|
||||
m.thumbnail.uri = GetThumbnailUrl(content.videoThumbnails)
|
||||
m.thumbnail.id = `thumbnail-${content.videoId}`
|
||||
|
||||
if IsVideoLive(content)
|
||||
m.top.FindNode("liveRect").visible = true
|
||||
m.top.FindNode("durationRect").visible = false
|
||||
else
|
||||
m.top.FindNode("liveRect").visible = false
|
||||
if content.lengthSeconds <> invalid and content.lengthSeconds <> 0
|
||||
m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.lengthSeconds)
|
||||
m.top.FindNode("durationRect").visible = true
|
||||
else
|
||||
m.top.FindNode("durationRect").visible = false
|
||||
end if
|
||||
end if
|
||||
|
||||
end function
|
||||
|
||||
function OnThumbnailLoadFailed() as void
|
||||
if m.thumbnail.loadStatus <> "failed"
|
||||
return
|
||||
end if
|
||||
m.thumbnail.uri = "pkg:/images/thumbnail-missing.jpg"
|
||||
end function
|
||||
|
||||
function GetThumbnailUrl(videoThumbnails as object, quality = "medium" as string) as string
|
||||
if videoThumbnails.Count() = 0
|
||||
return ""
|
||||
end if
|
||||
for each thumbnail in videoThumbnails
|
||||
if thumbnail.quality = quality
|
||||
return thumbnail.url
|
||||
end if
|
||||
end for
|
||||
return videoThumbnails[0].url
|
||||
end function
|
||||
|
||||
function IsVideoUpcoming(metadata as object) as boolean
|
||||
return metadata.isUpcoming = true
|
||||
end function
|
||||
|
||||
function IsVideoLive(metadata as object) as boolean
|
||||
if metadata.liveNow = true
|
||||
return true
|
||||
end if
|
||||
' TODO: metadata.liveNow is returning false for live videos...
|
||||
return metadata.lengthSeconds = 0 and metadata.viewCount = 0
|
||||
end function
|
||||
|
||||
function FormatViewCount(viewCount as dynamic) as string
|
||||
if viewCount = invalid
|
||||
return ""
|
||||
end if
|
||||
if viewCount < 1000
|
||||
return `${FormatFloat(viewCount)} views`
|
||||
end if
|
||||
|
||||
viewCount = viewCount / 1000
|
||||
if viewCount < 1000
|
||||
return `${FormatFloat(viewCount)}K views`
|
||||
end if
|
||||
|
||||
viewCount = viewCount / 1000
|
||||
return `${FormatFloat(viewCount)}M views`
|
||||
end function
|
||||
|
||||
function FormatFloat(X as integer) as integer
|
||||
X = X * 10
|
||||
X = X + 0.5
|
||||
X = Fix(X)
|
||||
X = X / 10
|
||||
return X
|
||||
end function
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="VideoRowCell" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<LayoutGroup
|
||||
itemSpacings="[24,5,5]"
|
||||
>
|
||||
<Poster
|
||||
id="thumbnail"
|
||||
loadDisplayMode="scaleToZoom"
|
||||
width="350"
|
||||
height="196"
|
||||
>
|
||||
<Rectangle
|
||||
id="durationRect"
|
||||
width="60"
|
||||
height="25"
|
||||
color="0x000000"
|
||||
opacity="0.8"
|
||||
translation="[290, 162]"
|
||||
>
|
||||
<Label
|
||||
width="60"
|
||||
height="25"
|
||||
id="durationLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestSystemFont"
|
||||
/>
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
id="liveRect"
|
||||
width="60"
|
||||
height="25"
|
||||
color="0xFF0000"
|
||||
translation="[290, 162]"
|
||||
>
|
||||
<Label
|
||||
width="60"
|
||||
height="25"
|
||||
id="liveLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
text="LIVE"
|
||||
/>
|
||||
</Rectangle>
|
||||
</Poster>
|
||||
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="350"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
maxLines="2"
|
||||
wrap="true"
|
||||
/>
|
||||
<Label
|
||||
id="authorLabel"
|
||||
width="350"
|
||||
height="25"
|
||||
font="font:SmallestSystemFont"
|
||||
/>
|
||||
<Label
|
||||
id="viewCountDateLabel"
|
||||
width="350"
|
||||
height="25"
|
||||
font="font:SmallestSystemFont"
|
||||
/>
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
</component>
|
||||
Reference in new issue
Block a user