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:
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
|
||||
@@ -1,10 +1,16 @@
|
||||
<component name="VideoRowList" extends="RowList" includes="AutoBind">
|
||||
<component name="VideoRowList" extends="RowList" includes="AutoBind,ContextMenuProvider">
|
||||
<interface>
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="playQueue" type="node" bind="/PlayQueue" />
|
||||
<field id="contentData" type="array" onChange="OnContentData" />
|
||||
<field id="bookmarks" type="node" bind="/Bookmarks" />
|
||||
<field id="screen" type="node" />
|
||||
<field id="feeds" type="array" onChange="OnFeedsChange" />
|
||||
<field id="someContentReady" type="bool" />
|
||||
<field id="onError" type="string" alwaysNotify="true" />
|
||||
<function name="OpenPlaylist" />
|
||||
<function name="OpenChannel" />
|
||||
<function name="OpenVideoChannel" />
|
||||
<function name="Refresh" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -1,17 +1,25 @@
|
||||
import "FeedLoadState.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoRowListContentTask(input as object)
|
||||
contentData = input.contentData
|
||||
feeds = input.feeds
|
||||
rowList = input.node
|
||||
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
for each feed in contentData
|
||||
for each feed in feeds
|
||||
feedContentNode = CreateObject("roSGNode", "FeedContentNode")
|
||||
feedContentNode.feed = feed
|
||||
feedContentNode.loadState = FeedLoadState.None
|
||||
feedContentNode.title = feed.title
|
||||
feedContentNode.feedSourcesIndex = 0
|
||||
feedContentNode.loadState = FeedLoadState.None
|
||||
feedSources = feed.feedSources
|
||||
for i = 0 to feedSources.count() - 1
|
||||
feedSources[i].state = {
|
||||
loadState: FeedLoadState.None
|
||||
}
|
||||
end for
|
||||
feedContentNode.feedSources = feedSources
|
||||
|
||||
for i = 1 to 4
|
||||
feedContentNode.createChild("LoadingContentNode")
|
||||
|
||||
@@ -1,93 +1,156 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoRowListRowContentTask(input as object) as object
|
||||
rowList = input.node
|
||||
contentNode = input.contentNode
|
||||
invidiousNode = input.invidious
|
||||
try
|
||||
rowList = input.rowList
|
||||
feedContentNode = input.feedContentNode
|
||||
invidiousNode = input.invidious
|
||||
|
||||
if m.top.cancel
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
end if
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
instance = service.GetInstance()
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
totalfetchedItems = 0
|
||||
|
||||
service.MarkFeedPagination(contentNode)
|
||||
response = service.MakeRequest(contentNode.feed, m.top.cancellation)
|
||||
while true
|
||||
if m.top.cancel
|
||||
feedContentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
end if
|
||||
|
||||
if m.top.cancel
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
end if
|
||||
feedSources = feedContentNode.feedSources
|
||||
feedSourcesIndex = feedContentNode.feedSourcesIndex
|
||||
|
||||
if not response.success
|
||||
if response.error = Invidious.ERROR_NOT_AUTHENTICATED
|
||||
RemovePlaceHolderItems(contentNode)
|
||||
actionNode = CreateObject("roSGNode", "ActionContentNode")
|
||||
actionNode.title = `Login to view ${contentNode.title}`
|
||||
actionNode.action = "LoginDialog"
|
||||
if feedSourcesIndex >= feedSources.Count()
|
||||
feedContentNode.loadState = FeedLoadState.Loaded
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end if
|
||||
|
||||
contentNode.appendChild(actionNode)
|
||||
contentNode.loadState = FeedLoadState.Loaded
|
||||
feedSource = feedSources[feedSourcesIndex]
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end if
|
||||
if feedSource.state.loadState = FeedLoadState.Loaded or feedSource.state.loadState = FeedLoadState.Error
|
||||
feedSourcesIndex += 1
|
||||
if feedSourcesIndex >= feedSources.Count()
|
||||
feedContentNode.loadState = FeedLoadState.Loaded
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end if
|
||||
feedContentNode.feedSourcesIndex = feedSourcesIndex
|
||||
continue while
|
||||
end if
|
||||
|
||||
' Invidious returns 500 and "{"error":"Closed stream"}" when the Popular feed is disabled
|
||||
' TODO:P2 check the endpoint.name instead of contentNode.title to avoid conflict with other feeds
|
||||
if contentNode.title = "Popular" and response.error.instr("Closed stream") > 0
|
||||
LogWarn("Deleting feed", contentNode.title, "-", response.error)
|
||||
parent = contentNode.getParent()
|
||||
parent.removeChild(contentNode)
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end if
|
||||
feedSource = service.MarkFeedPagination(feedContentNode)
|
||||
|
||||
contentNode.loadState = FeedLoadState.Error
|
||||
contentNode.title += " (Failed to load)"
|
||||
return response
|
||||
end if
|
||||
response = service.MakeRequest(feedSource, feedSource.state.queryParams, m.top.cancellation)
|
||||
|
||||
instance = service.GetInstance()
|
||||
itemNodes = []
|
||||
for each item in response.result.items
|
||||
itemNode = InvidiousContent.ToRowCellContentNode(item, instance)
|
||||
if itemNode <> invalid
|
||||
itemNodes.Push(itemNode)
|
||||
end if
|
||||
end for
|
||||
if not response.success
|
||||
if response.error = Invidious.ERROR_NOT_AUTHENTICATED
|
||||
RemovePlaceHolderItems(feedContentNode)
|
||||
actionNode = CreateObject("roSGNode", "ActionContentNode")
|
||||
actionNode.title = `Login to view ${feedSource.title}`
|
||||
actionNode.action = "LoginDialog"
|
||||
|
||||
RemovePlaceHolderItems(contentNode)
|
||||
contentNode.appendChildren(itemNodes)
|
||||
feedSource.state.loadState = FeedLoadState.Loaded
|
||||
feedSources[feedSourcesIndex] = feedSource
|
||||
feedContentNode.feedSources = feedSources
|
||||
|
||||
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
|
||||
if hasContinuation
|
||||
contentNode.continuation = response.result.continuation
|
||||
end if
|
||||
feedContentNode.appendChild(actionNode)
|
||||
feedContentNode.loadState = FeedLoadState.Loaded
|
||||
|
||||
if response.result.items.Count() > 0
|
||||
pageType = contentNode.paginationType
|
||||
if pageType = PaginationType.Continuation and hasContinuation
|
||||
contentNode.loadState = FeedLoadState.LoadedPage
|
||||
else if pageType = PaginationType.Pages
|
||||
contentNode.loadState = FeedLoadState.LoadedPage
|
||||
else
|
||||
contentNode.loadState = FeedLoadState.Loaded
|
||||
end if
|
||||
else
|
||||
contentNode.loadState = FeedLoadState.Loaded
|
||||
end if
|
||||
continue while
|
||||
end if
|
||||
|
||||
if itemNodes.Count() > 0
|
||||
rowList.someContentReady = true
|
||||
end if
|
||||
' Invidious returns 500 and "{"error":"Closed stream"}" when the Popular feed is disabled
|
||||
if feedSource.endpoint = "popular" and response.error.instr("Closed stream") > -1
|
||||
LogWarn("Popular feedSource not available:", response.error)
|
||||
if feedSources.Count() = 1
|
||||
parent = feedContentNode.getParent()
|
||||
parent.removeChild(feedContentNode)
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end if
|
||||
|
||||
return response
|
||||
continue while
|
||||
end if
|
||||
|
||||
feedSource.state.loadState = FeedLoadState.Error
|
||||
feedSources[feedSourcesIndex] = feedSource
|
||||
feedContentNode.feedSources = feedSources
|
||||
|
||||
if feedContentNode.title.instr(" (Failed to load)") = -1
|
||||
feedContentNode.title += " (Failed to load)"
|
||||
end if
|
||||
|
||||
HandleFeedLoadErrorDialog(response.error, rowList)
|
||||
continue while
|
||||
end if
|
||||
|
||||
itemNodes = []
|
||||
for each item in response.result.items
|
||||
itemNode = InvidiousContent.ToRowCellContentNode(item, instance)
|
||||
if itemNode <> invalid
|
||||
itemNode.feedSourcesIndex = feedSourcesIndex
|
||||
itemNodes.Push(itemNode)
|
||||
end if
|
||||
end for
|
||||
|
||||
RemovePlaceHolderItems(feedContentNode)
|
||||
feedContentNode.appendChildren(itemNodes)
|
||||
|
||||
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
|
||||
if hasContinuation
|
||||
feedSource.state.continuation = response.result.continuation
|
||||
end if
|
||||
|
||||
if response.result.items.Count() > 0
|
||||
pageType = feedSource.state.paginationType
|
||||
if pageType = PaginationType.Continuation and hasContinuation
|
||||
feedSource.state.loadState = FeedLoadState.LoadedPage
|
||||
else if pageType = PaginationType.Pages
|
||||
feedSource.state.loadState = FeedLoadState.LoadedPage
|
||||
else
|
||||
feedSource.state.loadState = FeedLoadState.Loaded
|
||||
end if
|
||||
else
|
||||
feedSource.state.loadState = FeedLoadState.Loaded
|
||||
end if
|
||||
|
||||
feedSources[feedSourcesIndex] = feedSource
|
||||
feedContentNode.feedSources = feedSources
|
||||
|
||||
if feedSource.state.loadState = FeedLoadState.Loaded and feedSourcesIndex = feedSources.Count() - 1
|
||||
feedContentNode.loadState = FeedLoadState.Loaded
|
||||
else
|
||||
feedContentNode.loadState = FeedLoadState.LoadedPage
|
||||
end if
|
||||
|
||||
if itemNodes.Count() > 0
|
||||
rowList.someContentReady = true
|
||||
end if
|
||||
|
||||
totalfetchedItems += response.result.items.Count()
|
||||
if totalfetchedItems > 3
|
||||
exit while
|
||||
end if
|
||||
end while
|
||||
|
||||
catch error
|
||||
HandleFeedLoadErrorDialog(error, rowList)
|
||||
return {
|
||||
success: false,
|
||||
error: error
|
||||
}
|
||||
end try
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
|
||||
function RemovePlaceHolderItems(contentNode as object)
|
||||
@@ -101,3 +164,10 @@ function RemovePlaceHolderItems(contentNode as object)
|
||||
end if
|
||||
end while
|
||||
end function
|
||||
|
||||
function HandleFeedLoadErrorDialog(error as object, rowList as object)
|
||||
error = ErrorUtils.Format(error)
|
||||
LogError(error)
|
||||
rowList.onError = error
|
||||
DialogUtils.ShowDialog(error, "Failed to load feed", true)
|
||||
end function
|
||||
Reference in new issue
Block a user