Skip to content

Commit

Permalink
Implement navigation from swimlane to micropage (PLAYRTS-5527) (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
mutaben authored May 17, 2024
1 parent 8b7b4e4 commit 0911252
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ name: srgappearance-apple, nameSpecified: SRGAppearance, owner: SRGSSR, version:

name: srgcontentprotection-apple, nameSpecified: SRGContentProtection, owner: SRGSSR, version: 3.1.0, source: https://github.com/SRGSSR/srgcontentprotection-apple

name: srgdataprovider-apple, nameSpecified: SRGDataProvider, owner: SRGSSR, version: 19.0.2, source: https://github.com/SRGSSR/srgdataprovider-apple
name: srgdataprovider-apple, nameSpecified: SRGDataProvider, owner: SRGSSR, version: 19.0.3, source: https://github.com/SRGSSR/srgdataprovider-apple

name: srgdiagnostics-apple, nameSpecified: SRGDiagnostics, owner: SRGSSR, version: 3.1.0, source: https://github.com/SRGSSR/srgdiagnostics-apple

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
<key>File</key>
<string>com.mono0926.LicensePlist/srgdataprovider-apple</string>
<key>Title</key>
<string>SRGDataProvider (19.0.2)</string>
<string>SRGDataProvider (19.0.3)</string>
<key>Type</key>
<string>PSChildPaneSpecifier</string>
</dict>
Expand Down
25 changes: 25 additions & 0 deletions Application/Sources/Application/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,38 @@ func navigateToPage(_ page: SRGContentPage, animated: Bool = true) {
}

func navigateToSection(_ section: Content.Section, filter: SectionFiltering?, animated: Bool = true) {
if let microPageId = section.properties.openContentPageId {
openContentPage(id: microPageId, animated: animated)
} else {
openSectionPage(section: section, filter: filter, animated: animated)
}
}

private func openSectionPage(section: Content.Section, filter: SectionFiltering?, animated: Bool) {
guard !isPresenting, let topViewController = UIApplication.shared.mainTopViewController else { return }
isPresenting = true
topViewController.navigateToSection(section, filter: filter, animated: animated) {
isPresenting = false
}
}

private func openContentPage(id: String, animated: Bool) {
guard !isPresenting, let topViewController = UIApplication.shared.mainTopViewController else { return }
isPresenting = true

SRGDataProvider.current!.contentPage(for: ApplicationConfiguration.shared.vendor, uid: id)
.receive(on: DispatchQueue.main)
.sink { _ in
// No error banners displayed on tvOS yet
isPresenting = false
} receiveValue: { contentPage in
topViewController.navigateToPage(contentPage, animated: animated) {
isPresenting = false
}
}
.store(in: &cancellables)
}

func navigateToTopic(_ topic: SRGTopic, animated: Bool = true) {
guard !isPresenting, let topViewController = UIApplication.shared.mainTopViewController else { return }
isPresenting = true
Expand Down
13 changes: 13 additions & 0 deletions Application/Sources/Content/Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protocol SectionProperties {
var rowHighlight: Highlight? { get }
var placeholderRowItems: [Content.Item] { get }
var displaysRowHeader: Bool { get }
var openContentPageId: String? { get }

/// Publisher providing content for the section. A single result must be delivered upon subscription. Further
/// results can be retrieved (if any) using a paginator, one page at a time.
Expand Down Expand Up @@ -391,6 +392,14 @@ private extension Content {
return contentSection.presentation.type != .highlight && contentSection.presentation.type != .showPromotion
}

var openContentPageId: String? {
guard let link = contentSection.presentation.contentLink, link.type == .microPage, let id = link.target else {
return nil
}

return id
}

func publisher(pageSize: UInt, paginatedBy paginator: Trigger.Signal?, filter: SectionFiltering?) -> AnyPublisher<[Content.Item], Error> {
let dataProvider = SRGDataProvider.current!

Expand Down Expand Up @@ -818,6 +827,10 @@ private extension Content {
return true
}

var openContentPageId: String? {
nil
}

func publisher(pageSize: UInt, paginatedBy paginator: Trigger.Signal?, filter: SectionFiltering?) -> AnyPublisher<[Content.Item], Error> {
let dataProvider = SRGDataProvider.current!

Expand Down
34 changes: 30 additions & 4 deletions Application/Sources/Content/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,37 @@ extension PageViewController: ShowAccessCellActions {

extension PageViewController: SectionHeaderViewAction {
fileprivate func openSection(sender: Any?, event: OpenSectionEvent?) {
if let event, let navigationController {
let sectionViewController = SectionViewController(section: event.section.wrappedValue, filter: model.id)
navigationController.pushViewController(sectionViewController, animated: true)
if let event {
if let microPageId = event.section.wrappedValue.properties.openContentPageId {
openContentPage(id: microPageId)
} else {
openSectionPage(section: event.section, filter: model.id)
}
}
}

private func openSectionPage(section: PageViewModel.Section, filter: PageViewModel.Id) {
guard let navigationController else { return }

let sectionViewController = SectionViewController(section: section.wrappedValue, filter: filter)
navigationController.pushViewController(sectionViewController, animated: true)
}

private func openContentPage(id: String) {
guard let navigationController else { return }

SRGDataProvider.current!.contentPage(for: ApplicationConfiguration.shared.vendor, uid: id)
.receive(on: DispatchQueue.main)
.sink { error in
if case .failure(let failure) = error {
Banner.showError(failure as NSError)
}
} receiveValue: { contentPage in
let pageViewController = PageViewController.pageViewController(for: contentPage)
navigationController.pushViewController(pageViewController, animated: true)
}
.store(in: &cancellables)
}
}

extension PageViewController: TabBarActionable {
Expand Down Expand Up @@ -1045,7 +1071,7 @@ private extension PageViewController {
}

private var hasDetailDisclosure: Bool {
return section.viewModelProperties.canOpenDetailPage || isSectionWideSupportEnabled
return section.viewModelProperties.canOpenPage || isSectionWideSupportEnabled
}

var accessibilityLabel: String? {
Expand Down
14 changes: 9 additions & 5 deletions Application/Sources/Content/PageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ private extension PageViewModel {
var rowItems = items.map { Item(.item($0), in: section) }
#if os(tvOS)
if !rowItems.isEmpty
&& (section.viewModelProperties.canOpenDetailPage || ApplicationSettingSectionWideSupportEnabled())
&& (section.viewModelProperties.canOpenPage || ApplicationSettingSectionWideSupportEnabled())
&& section.viewModelProperties.hasMoreRowItem {
rowItems.append(Item(.more, in: section))
}
Expand All @@ -625,7 +625,7 @@ private extension PageViewModel {

protocol PageViewModelProperties {
var layout: PageViewModel.SectionLayout { get }
var canOpenDetailPage: Bool { get }
var canOpenPage: Bool { get }
}

extension PageViewModelProperties {
Expand Down Expand Up @@ -695,12 +695,16 @@ private extension PageViewModel {
}
}

var canOpenDetailPage: Bool {
var canOpenPage: Bool {
switch presentation.type {
case .favoriteShows, .myProgram, .continueWatching, .topicSelector, .watchLater:
return true
default:
return presentation.hasDetailPage
if presentation.contentLink != nil {
return true
} else {
return false
}
}
}
}
Expand Down Expand Up @@ -738,7 +742,7 @@ private extension PageViewModel {
}
}

var canOpenDetailPage: Bool {
var canOpenPage: Bool {
return layout == .mediaSwimlane || layout == .showSwimlane
}
}
Expand Down
2 changes: 1 addition & 1 deletion PlaySRG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19353,7 +19353,7 @@
repositoryURL = "https://github.com/SRGSSR/srgdataprovider-apple.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 19.0.2;
minimumVersion = 19.0.3;
};
};
6F7269A72836CFE90072BA0B /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
Expand Down
4 changes: 2 additions & 2 deletions PlaySRG.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SRGSSR/srgdataprovider-apple.git",
"state" : {
"revision" : "b29c4e796d0c1dbe4bb05b1f79834f4560ee6347",
"version" : "19.0.2"
"revision" : "a447e5fa50cd7e4eed1b26e65e45c8e386e9151b",
"version" : "19.0.3"
}
},
{
Expand Down

0 comments on commit 0911252

Please sign in to comment.