Skip to content

Commit

Permalink
Bookmarks v1
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Oct 3, 2023
1 parent 0a3092e commit c99c33a
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 107 deletions.
12 changes: 7 additions & 5 deletions playlet-lib/src/components/ChannelView/ChannelView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ 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
}
items: [{
apiType: "Invidious",
endpoint: endpoint,
pathParams: {
ucid: ucid
}
}]
}
end function
83 changes: 81 additions & 2 deletions playlet-lib/src/components/ContextMenu/ContextMenu.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,87 @@ import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

' TODO:P0 test animation (fade in)
' TODO:P1 animation (fade out)
' TODO:P0 Context menu
' TODO:P0 Web app support
' TODO:P0 Web apis and open api spec updates
'
' From the main screen:
' When a video is selected:
' - "Play" - DONE
' - "Queue" - DONE
' - "Open Channel" - DONE
' - "Add to "Videos" bookmark" - DONE
' - If video is already in a bookmark, "Remove from Bookmarks" - DONE
'
' When a channel is selected:
' - "Open" - DONE
' - "Add to "Channels" bookmark" - DONE
' - "Add to <ChannelName> bookmark" - DONE
' - If channel is already in a bookmark, "Remove from Bookmarks" - DONE
' - PlaylistId starting with "IV" cannot be added to a bookmark - DONE
'
' When a playlist is selected:
' - "Play" - DONE
' - "Queue" - DONE
' - "Open" - DONE
' - "Add to "Playlists" bookmark" - DONE
' - "Add to <PlaylistName> bookmark" - DONE
' - If playlist is already in a bookmark, "Remove from Bookmarks" - DONE
' When any:
' - "Reload feed"
'
' From Playlist view:
' When a video is selected:
' - "Play"
' - "Queue"
' - "Play video"
' - "Queue video"
' - "Open Channel"
' - "Add to "Playlists" bookmark"
' - "Add to <PlaylistName> bookmark"
' - "Add to "Videos" bookmark"
'
' From Channel view:
' When a video is selected:
' - "Play"
' - "Queue"
' - "Add to "Channels" bookmark"
' - "Add to <ChannelName> - <feed> bookmark" feed being latest videos, live, shorts, etc
' - "Add to "Videos" bookmark"
'
' When a playlist is selected:
' - "Play"
' - "Queue"
' - "Open"
' - "Add to "Channels" bookmark"
' - "Add to <ChannelName> - <feed> bookmark" feed being latest videos, live, shorts, etc
' - "Add to "Playlists" bookmark"
' - "Add to <PlaylistName> bookmark"
'
' From search view:
' When a video/channel/playlist is selected:
' - Inherit options
' - "Add to "Search - ${q}" bookmark" - this includes the search filters used
'
' From bookmarks view:
' When a video/channel/playlist is selected:
' - Inherit options
' - "Remove item from Bookmarks"
' - "Remove group from Bookmarks"
' - "Reload bookmarks"
'
' TODO:P1 Playlist item seletected from the bookmarks need to play as a playlist, not as a single video
' TODO:P1 Context menu might need to be scrollable (both horizontally and vertically)
' TODO:P1 Context menu might need sections. Example:
' In a Channel view, while selecting a playlist:
' - Channel
' - Add to "Channels" bookmark
' - Other "Channels" related context menu items
' - Playlist
' - Add to "Playlists" bookmark
' - "Play/Queue"
' - Other "Playlists" related context menu items

function Init()
m.buttonGroup = m.top.findNode("buttonGroup")
m.showAnimation = m.top.findNode("showAnimation")
Expand Down
1 change: 0 additions & 1 deletion playlet-lib/src/components/PlaylistView/PlaylistView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

' TODO:P0 context menu (play/queue/bookmarks)
function Init()
m.background = m.top.findNode("background")
m.backgroundSmall = m.top.findNode("backgroundSmall")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ function Init()
m.noBookmarks = m.top.findNode("noBookmarks")
m.yesBookmarks = m.top.findNode("yesBookmarks")
m.rowList = m.top.FindNode("rowList")
m.isDirty = true

m.top.ObserveField("visible", FuncName(OnVisibleChange))
end function

function OnNodeReady()
Expand All @@ -15,7 +18,7 @@ function OnNodeReady()
m.rowList@.BindNode(invalid)

OnBookmarksChange()
m.bookmarks.content.ObserveField("change", FuncName(OnBookmarksChange))
m.bookmarks.ObserveField("contentChange", FuncName(OnBookmarksChange))
end function

function OnFocusChange() as void
Expand All @@ -30,25 +33,98 @@ function OnFocusChange() as void
end if
end function

' TODO:P0 handle visiblity: only refresh bookmarks if screen visible.
' Else mark as dirty and refresh when visible
function OnBookmarksChange()
function OnVisibleChange()
if m.top.visible and m.isDirty
m.isDirty = false
OnBookmarksChange()
end if
end function

function OnBookmarksChange() as void
if not m.top.visible
m.isDirty = true
return
end if
hasBookmarks = m.bookmarks.content.getChildCount() > 0
m.noBookmarks.visible = not hasBookmarks
m.yesBookmarks.visible = hasBookmarks
m.top.focusable = hasBookmarks

if hasBookmarks
SetRowListContent()
SetRowListContent(m.bookmarks.content)
else
if m.rowList.hasFocus()
NodeSetFocus(m.navBar, true)
end if
end if
end function

function SetRowListContent()
function SetRowListContent(bookmarksContent as object)
bookmarks = bookmarksContent.getChildren(-1, 0)

contentData = []
for each bookmarkGroup in bookmarks
items = bookmarkGroup.getChildren(-1, 0)
rowData = {
title: bookmarkGroup.title,
items: []
}

for each item in items
if item.type = "video"
rowItemData = {
apiType: "Invidious",
endpoint: "video_info",
pathParams: {
id: item.itemId
}
}
rowData.items.push(rowItemData)
else if item.type = "playlist"
rowItemData = {
apiType: "Invidious",
endpoint: "playlist_info",
pathParams: {
plid: item.itemId
}
}
rowData.items.push(rowItemData)
if items.Count() = 1
rowItemData = {
apiType: "Invidious",
endpoint: "playlist",
pathParams: {
plid: item.itemId
}
}
rowData.items.push(rowItemData)
end if
else if item.type = "channel"
rowItemData = {
apiType: "Invidious",
endpoint: "channel_info",
pathParams: {
ucid: item.itemId
}
}
rowData.items.push(rowItemData)
if items.Count() = 1
rowItemData = {
apiType: "Invidious",
endpoint: "channel_videos",
pathParams: {
ucid: item.itemId
}
}
rowData.items.push(rowItemData)
end if
end if
end for

contentData.push(rowData)
end for

m.rowList.contentData = contentData
end function

function OnkeyEvent(key as string, press as boolean) as boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<component name="BookmarksScreen" extends="Group" includes="AutoBind,Focus">
<interface>
<field id="navBar" type="node" bind="/NavBar" />
<field id="applicationInfo" type="node" bind="/ApplicationInfo" />
<field id="bookmarks" type="node" bind="/Bookmarks" />
</interface>
Expand Down
12 changes: 7 additions & 5 deletions playlet-lib/src/components/Screens/SearchScreen/SearchScreen.bs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ function Search(text as string)
m.rowlist.ObserveFieldScoped("someContentReady", FuncName(OnSearchContentReady))
ShowLoadingScreen()

requestData = {
title: `Search - ${text}`,
requestDataItem = {
apiType: "Invidious",
endpoint: "search",
queryParams: {
Expand All @@ -214,18 +213,21 @@ function Search(text as string)
for each filter in filters
value = filters[filter]
if IsString(value) and value.len() > 0
requestData.queryParams[filter] = value
requestDataItem.queryParams[filter] = value
else if IsArray(value) and value.Count() > 0
' TODO:P1 this is http client implementation details leaking
' We need a declarative way to set array types
requestData.queryParams[filter] = {
requestDataItem.queryParams[filter] = {
value: value,
__arrayType: HttpClient.QueryParamArrayType.CommaSeparated
}
end if
end for

m.rowList.contentData = [requestData]
m.rowList.contentData = [{
title: `Search - ${text}`,
items: [requestDataItem]
}]
end function

function OnSearchContentReady() as void
Expand Down
28 changes: 5 additions & 23 deletions playlet-lib/src/components/Services/Bookmarks/Bookmarks.bs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Init()
m.top.content = m.top.findNode("content")
m.bookmarksString = ""
Load()
m.top.content.ObserveField("change", FuncName(OnChange))
m.top.ObserveField("contentChange", FuncName(OnContentChange))
end function

function Load() as void
Expand Down Expand Up @@ -94,6 +94,7 @@ function AddBookmark(bookmarkType as string, id as string, groupName as string)
})
groupNode.insertChild(node, 0)
LogInfo("Added bookmark:", id)
m.top.contentChange = true
end function

function RemoveBookmark(id as string) as void
Expand All @@ -110,14 +111,10 @@ function RemoveBookmark(id as string) as void
m.top.content.removeChild(group)
LogInfo("Removed bookmark group:", group.title)
end if
m.top.contentChange = true
end function

function OnChange(event as object) as void
change = event.getData()
if change.Operation = "none"
return
end if

function OnContentChange(event as object) as void
Save()
end function

Expand Down Expand Up @@ -149,7 +146,7 @@ end function

function GetMenuForPlaylist(playlistNode as object) as object
playlistId = playlistNode.playlistId
if StringUtils.IsNullOrEmpty(playlistId)
if StringUtils.IsNullOrEmpty(playlistId) or playlistId.StartsWith("IV")
return []
end if

Expand Down Expand Up @@ -212,18 +209,3 @@ function GetMenuForChannel(channelNode as object) as object
end if
return menu
end function

' TODO:P0
' When a video is selected:
' - Add to "Videos" bookmark - DONE
' - Add to bookmarks...

' When a channel is selected:
' - Add to "Channels" bookmark - DONE
' - Add to <ChannelName> bookmark - DONE
' - Add to bookmarks...

' When a playlist is selected:
' - Add to "Playlists" bookmark - DONE
' - Add to <PlaylistName> bookmark - DONE
' - Add to bookmarks...
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<interface>
<field id="__version" type="integer" value="1" />
<field id="content" type="node" />
<field id="contentChange" type="boolean" alwaysNotify="true" />
<function name="AddBookmark" />
<function name="RemoveBookmark" />
<function name="GetMenuForVideo" />
Expand Down
Loading

0 comments on commit c99c33a

Please sign in to comment.