Bookmarks (#153)

* Empty bookmarks screen

* Bookmarks object

* Long press support

* Lint fix

* Context menu v1

* A working context menu

* Basic bookmarks in context menu

* Use a root content node for bookmarks

* context menu animation

* small tweak

* move logger around, adjust animation

* Lint fix

* Restore logger fix

* Cache channel info

* Bookmarks v1

* Added comment

* Adjust "popular" feed error handling

* Progress with bookmarks

* Add todo

* add todo

* handle roDateTime logging

* logger adjustment

* Use yaml for api and layout

* rename requestData to feedSource

* Restructure things

* Lint fix

* remove comment

* introduce feedSource id

* small cleanup

* playlist context menu

* Context menu for the channel view

* changelog

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-10-19 19:16:27 -04:00
1 parent 620a8a6e2b
commit c740d5e0a0
63 files changed
+1889 -510

No files matched your search

@@ -1,5 +1,7 @@
import "pkg:/components/ChannelView/ChannelUtils.bs"
import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/LongPress.bs"
import "pkg:/components/PlaylistView/PlaylistUtils.bs"
import "pkg:/components/VideoFeed/VideoRowListContentTask.bs"
import "pkg:/components/VideoFeed/VideoRowListRowContentTask.bs"
@@ -18,11 +20,11 @@ end function
function OnNodeReady()
m.top.ObserveField("itemFocused", FuncName(OnItemFocused))
m.top.ObserveField("rowItemFocused", FuncName(OnRowItemFocused))
m.top.ObserveField("rowItemSelected", FuncName(OnRowItemSelected))
m.top.observeField("focusedChild", FuncName(OnFocusedChildChange))
m.top.ObserveField("visible", FuncName(OnVisibilityChange))
m.invidious.ObserveFieldScoped("authToken", FuncName(OnAuthTokenChange))
InitializeLongPressTimer()
end function
function OnFocusedChildChange() as void
@@ -37,7 +39,7 @@ function OnVisibilityChange()
end if
end function
function OnContentData() as void
function OnFeedsChange() as void
InitContent()
end function
@@ -47,6 +49,11 @@ end function
function OnRowItemFocused(event as object) as void
index = event.GetData()
if index = invalid or index.count() <> 2
LogWarn("Invalid index:", index)
return
end if
rowIndex = index[0]
rowItemIndex = index[1]
@@ -60,12 +67,30 @@ function OnRowItemFocused(event as object) as void
end if
end function
function OnRowItemSelected(event as object)
index = event.GetData()
function OnRowItemSelected(index as object) as void
content = m.top.content
if content = invalid
return
end if
if index = invalid or index.count() <> 2
LogWarn("Invalid index:", index)
return
end if
rowIndex = index[0]
rowItemIndex = index[1]
row = m.top.content.GetChild(rowIndex)
if rowIndex < 0 or rowIndex >= content.GetChildCount()
LogWarn("Invalid row index:", rowIndex)
return
end if
row = content.GetChild(rowIndex)
if rowItemIndex < 0 or rowItemIndex >= row.GetChildCount()
LogWarn("Invalid row item index:", rowItemIndex)
return
end if
rowItem = row.GetChild(rowItemIndex)
if rowItem.type = "video"
@@ -75,11 +100,11 @@ function OnRowItemSelected(event as object)
else if rowItem.type = "playlist"
playlistId = rowItem.playlistId
LogInfo("Open playlist: " + playlistId)
PlaylistUtils.Open(rowItem)
OpenPlaylist(rowItem)
else if rowItem.type = "channel"
authorId = rowItem.authorId
LogInfo("Open channel: " + authorId)
ChannelUtils.Open(rowItem)
OpenChannel(rowItem)
else if rowItem.type = "action"
if rowItem.action = "LoginDialog"
dialog = CreateObject("roSGNode", "LoginDialog")
@@ -89,6 +114,82 @@ function OnRowItemSelected(event as object)
end if
end function
function OnRowItemLongPressed(index as object) as void
content = m.top.content
if content = invalid
return
end if
rowIndex = index[0]
rowItemIndex = index[1]
if rowIndex < 0 or rowIndex >= content.GetChildCount()
LogWarn("Invalid row index:", rowIndex)
return
end if
row = content.GetChild(rowIndex)
if rowItemIndex < 0 or rowItemIndex >= row.GetChildCount()
LogWarn("Invalid row item index:", rowItemIndex)
return
end if
rowItem = row.GetChild(rowItemIndex)
contextMenuProviders = [m.top, m.bookmarks, m.top.screen]
ContextMenuUtils.Open(contextMenuProviders, m.appController, rowItem)
end function
function GetContextMenuOptionsForItem(rowItem as object) as object
options = []
playAction = ContextMenuUtils.CreateOption("Play", m.playQueue, "Play", [rowItem, -1])
queueAction = ContextMenuUtils.CreateOption("Queue", m.playQueue, "AddToQueue", [rowItem])
if rowItem.type = "video"
options.push(playAction)
options.push(queueAction)
item = ContextMenuUtils.CreateOption("Open channel", m.top, "OpenVideoChannel", [rowItem])
options.push(item)
else if rowItem.type = "playlist"
options.push(playAction)
options.push(queueAction)
item = ContextMenuUtils.CreateOption("Open", m.top, "OpenPlaylist", [rowItem])
options.push(item)
else if rowItem.type = "channel"
item = ContextMenuUtils.CreateOption("Open", m.top, "OpenChannel", [rowItem])
options.push(item)
else
LogWarn("Unknown long pressed item type:", rowItem.type)
return []
end if
return options
end function
function OpenPlaylist(playlist as object)
PlaylistUtils.Open(playlist)
end function
function OpenChannel(channel as object)
ChannelUtils.Open(channel)
end function
function OpenVideoChannel(video as object) as void
authorId = video.authorId
if StringUtils.IsNullOrEmpty(authorId)
LogWarn("Invalid authorId:", authorId)
return
end if
channel = InvidiousContent.ToChannelContentNode(invalid, { authorId: authorId }, invalid)
ChannelUtils.Open(channel)
end function
function Refresh(unsued as dynamic)
InitContent()
end function
function OnAuthTokenChange()
' TODO:P2: Reload only content that is authenticated
' Should not reload if the page is not visible. Instead, capture state and reload when the page becomes visible
@@ -99,14 +200,14 @@ function InitContent() as void
CancelCurrentTasks()
m.top.someContentReady = false
if m.top.contentData = invalid
if m.top.feeds = invalid
m.top.content = invalid
return
end if
task = StartAsyncTask(VideoRowListContentTask, {
node: m.top,
contentData: m.top.contentData
feeds: m.top.feeds
}, OnVideoRowListContentTaskResult)
m.pendingLoadTasks[task.id] = task
end function
@@ -178,8 +279,8 @@ function LoadRowContent(contentNode as object)
contentNode.loadState = FeedLoadState.Loading
task = StartAsyncTask(VideoRowListRowContentTask, {
node: m.top,
contentNode: contentNode,
rowList: m.top,
feedContentNode: contentNode,
invidious: m.invidious
}, OnVideoRowListRowContentTaskResult)
m.pendingLoadTasks[task.id] = task
@@ -191,19 +292,22 @@ function OnVideoRowListRowContentTaskResult(output as object) as void
return
end if
if not output.success or not output.result.success
' output.error for unhandled exception
error = output.error
if error = invalid
' output.result.error for network errors
error = output.result.error
end if
error = ErrorUtils.Format(error)
LogError(error)
m.top.onError = error
message = `Failed to load feed\n${error}`
DialogUtils.ShowDialog(message, "Feed load fail", true)
end if
LoadRowsIfNeeded()
end function
function OnkeyEvent(key as string, press as boolean) as boolean
if LongPressHandler(key, press)
return true
end if
if key = LONG_PRESS_KEY and press
OnRowItemLongPressed(m.top.rowItemFocused)
return true
end if
if key = "OK" and not press
OnRowItemSelected(m.top.rowItemFocused)
return true
end if
return false
end function