(Re)Enable the play button on the season page
Resurrecting some of the previously-commented code to enable the play button on the season page. Which plays the next unplayed episode in that season. Note that we no longer bail out on the `BaseItemDto.missing` flag because sometimes it shows false negatives even on legit season items. Instead, we rely on results returning from the API call.
This commit is contained in:
parent
a372e0163a
commit
bfe413c06a
|
@ -30,6 +30,7 @@ final class SeasonItemViewModel: ItemViewModel, EpisodesRowManager {
|
||||||
getSeriesItem()
|
getSeriesItem()
|
||||||
selectedSeason = item
|
selectedSeason = item
|
||||||
retrieveSeasons()
|
retrieveSeasons()
|
||||||
|
requestEpisodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func playButtonText() -> String {
|
override func playButtonText() -> String {
|
||||||
|
@ -38,56 +39,51 @@ final class SeasonItemViewModel: ItemViewModel, EpisodesRowManager {
|
||||||
return L10n.unaired
|
return L10n.unaired
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.missing {
|
|
||||||
return L10n.missing
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let playButtonItem = playButtonItem, let episodeLocator = playButtonItem.getEpisodeLocator() else { return L10n.play }
|
guard let playButtonItem = playButtonItem, let episodeLocator = playButtonItem.getEpisodeLocator() else { return L10n.play }
|
||||||
return episodeLocator
|
return episodeLocator
|
||||||
}
|
}
|
||||||
|
|
||||||
// private func requestEpisodes() {
|
private func requestEpisodes() {
|
||||||
// LogManager.shared.log
|
LogManager.shared.log
|
||||||
// .debug("Getting episodes in season \(item.id!) (\(item.name!)) of show \(item.seriesId!) (\(item.seriesName!))")
|
.debug("Getting episodes in season \(item.id!) (\(item.name!)) of show \(item.seriesId!) (\(item.seriesName!))")
|
||||||
// TvShowsAPI.getEpisodes(seriesId: item.seriesId ?? "", userId: SessionManager.main.currentLogin.user.id,
|
TvShowsAPI.getEpisodes(seriesId: item.seriesId ?? "", userId: SessionManager.main.currentLogin.user.id,
|
||||||
// fields: [.primaryImageAspectRatio, .seriesPrimaryImage, .seasonUserData, .overview, .genres, .people],
|
fields: [.primaryImageAspectRatio, .seriesPrimaryImage, .seasonUserData, .overview, .genres, .people],
|
||||||
// seasonId: item.id ?? "")
|
seasonId: item.id ?? "")
|
||||||
// .trackActivity(loading)
|
.trackActivity(loading)
|
||||||
// .sink(receiveCompletion: { [weak self] completion in
|
.sink(receiveCompletion: { [weak self] completion in
|
||||||
// self?.handleAPIRequestError(completion: completion)
|
self?.handleAPIRequestError(completion: completion)
|
||||||
// }, receiveValue: { [weak self] response in
|
}, receiveValue: { [weak self] response in
|
||||||
// self?.episodes = response.items ?? []
|
self?.episodes = response.items ?? []
|
||||||
// LogManager.shared.log.debug("Retrieved \(String(self?.episodes.count ?? 0)) episodes")
|
LogManager.shared.log.debug("Retrieved \(String(self?.episodes.count ?? 0)) episodes")
|
||||||
//
|
|
||||||
// self?.setNextUpInSeason()
|
self?.setNextUpInSeason()
|
||||||
// })
|
})
|
||||||
// .store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Sets the play button item to the "Next up" in the season based upon
|
// Sets the play button item to the "Next up" in the season based upon
|
||||||
// the watched status of episodes in the season.
|
// the watched status of episodes in the season.
|
||||||
// Default to the first episode of the season if all have been watched.
|
// Default to the first episode of the season if all have been watched.
|
||||||
// private func setNextUpInSeason() {
|
private func setNextUpInSeason() {
|
||||||
// guard !item.missing else { return }
|
guard !episodes.isEmpty else { return }
|
||||||
// guard !episodes.isEmpty else { return }
|
|
||||||
//
|
var firstUnwatchedSearch: BaseItemDto?
|
||||||
// var firstUnwatchedSearch: BaseItemDto?
|
|
||||||
//
|
for episode in episodes {
|
||||||
// for episode in episodes {
|
guard let played = episode.userData?.played else { continue }
|
||||||
// guard let played = episode.userData?.played else { continue }
|
if !played {
|
||||||
// if !played {
|
firstUnwatchedSearch = episode
|
||||||
// firstUnwatchedSearch = episode
|
break
|
||||||
// break
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
if let firstUnwatched = firstUnwatchedSearch {
|
||||||
// if let firstUnwatched = firstUnwatchedSearch {
|
playButtonItem = firstUnwatched
|
||||||
// playButtonItem = firstUnwatched
|
} else {
|
||||||
// } else {
|
guard let firstEpisode = episodes.first else { return }
|
||||||
// guard let firstEpisode = episodes.first else { return }
|
playButtonItem = firstEpisode
|
||||||
// playButtonItem = firstEpisode
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
private func getSeriesItem() {
|
private func getSeriesItem() {
|
||||||
guard let seriesID = item.seriesId else { return }
|
guard let seriesID = item.seriesId else { return }
|
||||||
|
|
Loading…
Reference in New Issue