Skip to content

Commit

Permalink
Add ability to remove item from My List
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Dec 22, 2024
1 parent e19b398 commit 0c083c4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
30 changes: 28 additions & 2 deletions components/Libraries/VisualLibraryScene.bs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ sub init()

m.view = "presentation"

m.loadItemsTask1 = createObject("roSGNode", "LoadItemsTask")
m.loadItemsTask1.observeField("content", "onMyListLoaded")
m.loadItemsTask1.itemsToLoad = "isInMyList"

m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2")
m.loadLogoTask = createObject("roSGNode", "LoadItemsTask2")
m.getFiltersTask = createObject("roSGNode", "GetFiltersTask")
Expand Down Expand Up @@ -1477,13 +1481,35 @@ function onKeyEvent(key as string, press as boolean) as boolean
focusedItem = getItemFocused()
if not isValid(focusedItem) then return false

resumeData = [tr("Add To My List")]
m.global.sceneManager.callFunc("optionDialog", "libraryitem", tr("Options"), [], resumeData, focusedItem.LookupCI("id"))
m.loadItemsTask1.itemId = focusedItem.LookupCI("id")
m.loadItemsTask1.control = TaskControl.RUN
return true
end if

return false
end function

sub onMyListLoaded()
isInMyListData = m.loadItemsTask1.content
m.loadItemsTask1.content = []

if not isValidAndNotEmpty(isInMyListData) then return

focusedItem = getItemFocused()
if not isValid(focusedItem) then return

' Item is already in My List
if isInMyListData[0]
dialogData = [tr("Remove From My List")]
m.global.sceneManager.callFunc("optionDialog", "libraryitem", tr("Options"), [], dialogData, focusedItem.LookupCI("id"))
return
end if

' Item is not in My List
dialogData = [tr("Add To My List")]
m.global.sceneManager.callFunc("optionDialog", "libraryitem", tr("Options"), [], dialogData, focusedItem.LookupCI("id"))
end sub

sub reclaimResources()
m.loadItemsTask.control = TaskControl.STOP
m.loadItemsTask.content = []
Expand Down
20 changes: 20 additions & 0 deletions components/home/LoadItemsTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,21 @@ function loadFavorites() as object
return results
end function

function loadIsInMyList() as object
results = [false]

listData = loadMyList()

for each item in listData
if isStringEqual(m.top.itemId, item.LookupCI("id"))
results = [true]
exit for
end if
end for

return results
end function

function loadMyList() as object
results = []

Expand Down Expand Up @@ -645,6 +660,11 @@ sub loadItems()
return
end if

if isStringEqual(m.top.itemsToLoad, "isInMyList")
m.top.content = loadIsInMyList()
return
end if

if isStringEqual(m.top.itemsToLoad, "backdropImage")
m.top.content = [BackdropImage(m.top.itemId)]
return
Expand Down
37 changes: 33 additions & 4 deletions source/MainEventHandlers.bs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ sub onLibrarySelection(selectedItem)
end sub

sub onRefreshSeasonDetailsDataEvent()
print "onRefreshSeasonDetailsDataEvent", onRefreshSeasonDetailsDataEvent
startLoadingSpinner()

currentScene = m.global.sceneManager.callFunc("getActiveScene")
Expand Down Expand Up @@ -1241,6 +1240,7 @@ sub onDataReturnedEvent(msg)
selectedPopupID = chainLookup(popupNode, "returndata.id")
itemID = chainLookup(popupNode, "returndata.itemID")
selectedPopupAction = chainLookup(popupNode, "returndata.indexselected")
selectedPopupButton = chainLookup(popupNode, "returndata.buttonselected")

if isStringEqual(selectedPopupID, "playback")
selectedItem = m.global.queueManager.callFunc("getHold")
Expand All @@ -1254,7 +1254,7 @@ sub onDataReturnedEvent(msg)

if isStringEqual(selectedPopupID, "libraryitem")
if not isValid(itemID) then return
processLibraryItemPopup(selectedPopupAction, itemID)
processLibraryItemPopup(selectedPopupButton, itemID)
return
end if
end sub
Expand Down Expand Up @@ -1301,9 +1301,9 @@ sub processPlaybackPopup(selectedPopupAction as integer, selectedItem as object)
end if
end sub

sub processLibraryItemPopup(selectedPopupAction as integer, itemID as string)
sub processLibraryItemPopup(selectedPopupButton as string, itemID as string)
' Add item to user's list
if selectedPopupAction = 0
if isStringEqual(selectedPopupButton, "Add To My List")
data = api.GetUserViews({ "userId": m.global.session.user.id })
if not isChainValid(data, "items") then return

Expand Down Expand Up @@ -1344,5 +1344,34 @@ sub processLibraryItemPopup(selectedPopupAction as integer, itemID as string)
],
ispublic: false
})
return
end if

if isStringEqual(selectedPopupButton, "Remove From My List")
data = api.GetUserViews({ "userId": m.global.session.user.id })
if not isChainValid(data, "items") then return

myListPlaylist = invalid

for each item in data.LookupCI("items")
if isStringEqual(item.LookupCI("CollectionType"), "playlists")
myListPlaylist = api.items.Get({
"userid": m.global.session.user.id,
"includeItemTypes": "Playlist",
"nameStartsWith": "[ROKU] My List",
"parentId": item.LookupCI("id")
})
exit for
end if
end for

' My list playlist exists. Remove item from it
if isValid(myListPlaylist) and isValidAndNotEmpty(myListPlaylist.items)
api.playlists.Remove(myListPlaylist.items[0].LookupCI("id"), {
entryIds: itemID
})
end if

return
end if
end sub

0 comments on commit 0c083c4

Please sign in to comment.