Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TV Season view data when user goes back to page from Video Player #1749

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/tvshows/TVEpisodes.bs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sub init()
m.unplayedEpisodeCount = m.top.findNode("unplayedEpisodeCount")

m.rows.observeField("doneLoading", "updateSeason")

m.isFirstRun = true
end sub

sub setSeasonLoading()
Expand All @@ -36,6 +38,8 @@ sub updateSeason()
if m.top.seasonData.UserData.UnplayedItemCount > 0
m.unplayedCount.visible = true
m.unplayedEpisodeCount.text = m.top.seasonData.UserData.UnplayedItemCount
else
m.unplayedCount.visible = false
end if
end if
end if
Expand Down Expand Up @@ -66,6 +70,18 @@ function getFocusedItem() as dynamic
return invalid
end function

' OnScreenShown: Callback function when view is presented on screen
'
sub OnScreenShown()
1hitsong marked this conversation as resolved.
Show resolved Hide resolved
if m.isFirstRun
m.isFirstRun = false
return
end if

m.tvEpisodeRow.setFocus(true)
m.top.refreshSeasonDetailsData = not m.top.refreshSeasonDetailsData
cewert marked this conversation as resolved.
Show resolved Hide resolved
end sub

' Handle navigation input from the remote and act on it
function onKeyEvent(key as string, press as boolean) as boolean
if key = "left" and m.tvEpisodeRow.hasFocus()
Expand Down
4 changes: 3 additions & 1 deletion components/tvshows/TVEpisodes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="TVEpisodes" extends="JFGroup">
<component name="TVEpisodes" extends="JFScreen">
<children>
<Poster id="seasonPoster" width="300" height="450" translation="[95,175]">
<Rectangle id="unplayedCount" visible="false" width="90" height="60" color="#00a4dcFF" translation="[210, 0]">
Expand All @@ -12,11 +12,13 @@
</children>
<interface>
<field id="episodeSelected" alias="picker.itemSelected" />
<field id="refreshSeasonDetailsData" type="bool" alwaysNotify="true" />
<field id="selectedItem" type="node" alwaysNotify="true" />
<field id="quickPlayNode" type="node" />
<field id="seasonData" type="assocarray" onChange="setSeasonLoading" />
<field id="objects" alias="picker.objects" />
<field id="episodeObjects" type="assocarray" />
<field id="extrasObjects" type="assocarray" onChange="setExtraButtonVisibility" />
<function name="updateSeason" />
</interface>
</component>
5 changes: 5 additions & 0 deletions components/tvshows/TVListDetails.bs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ sub itemContentChanged()
' Add checkmark in corner (if applicable)
if isValid(itemData.UserData) and isValid(itemData.UserData.Played) and itemData.UserData.Played = true
m.playedIndicator.visible = true
else
m.playedIndicator.visible = false
end if

' Add progress bar on bottom (if applicable)
Expand All @@ -90,6 +92,9 @@ sub itemContentChanged()
progressWidthInPixels = int(m.progressBackground.width * itemData.UserData.PlayedPercentage / 100)
m.progressBar.width = progressWidthInPixels
m.progressBar.visible = true
else
m.progressBackground.visible = false
m.progressBar.visible = false
end if

' Display current video_codec and check if there is more than one video to choose from...
Expand Down
21 changes: 21 additions & 0 deletions source/Main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ sub Main (args as dynamic) as void
end if
elapsed = timeSpan.TotalMilliseconds() / 1000
print "Quick Play finished loading in " + elapsed.toStr() + " seconds."
else if isNodeEvent(msg, "refreshSeasonDetailsData")
startLoadingSpinner()

currentEpisode = m.global.queueManager.callFunc("getCurrentItem")
currentScene = m.global.sceneManager.callFunc("getActiveScene")

' Find the object in the scene's data and update its json data
for i = 0 to currentScene.objects.Items.count() - 1
if LCase(currentScene.objects.Items[i].id) = LCase(currentEpisode.id)
currentScene.objects.Items[i].json = api.users.GetItem(m.global.session.user.id, currentEpisode.id)
m.global.queueManager.callFunc("setTopStartingPoint", currentScene.objects.Items[i].json.UserData.PlaybackPositionTicks)
exit for
end if
end for

seasonMetaData = ItemMetaData(currentScene.seasonData.id)
currentScene.seasonData = seasonMetaData.json
currentScene.episodeObjects = currentScene.objects
currentScene.callFunc("updateSeason")
stopLoadingSpinner()

else if isNodeEvent(msg, "selectedItem")
' If you select a library from ANYWHERE, follow this flow
selectedItem = msg.getData()
Expand Down
2 changes: 2 additions & 0 deletions source/ShowScenes.bs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ function CreateSeasonDetailsGroup(series as object, season as object) as dynamic
group.episodeObjects = group.objects
group.extrasObjects = TVSeasonExtras(season.id)

group.observeField("refreshSeasonDetailsData", m.port)

' watch for button presses
group.observeField("selectedItem", m.port)
group.observeField("quickPlayNode", m.port)
Expand Down
Loading