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,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