From 5531c912ea5f80b4b42e4da4377d2d1b27ffd665 Mon Sep 17 00:00:00 2001 From: jhays Date: Sun, 24 Apr 2022 19:44:56 -0500 Subject: [PATCH] LiveTV iOS route to playback --- Shared/Coordinators/LiveTVCoordinator.swift | 10 ++++----- .../Views/LiveTVChannelItemWideElement.swift | 22 ++++++++++++------- Swiftfin/Views/LiveTVChannelsView.swift | 17 +++++++------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Shared/Coordinators/LiveTVCoordinator.swift b/Shared/Coordinators/LiveTVCoordinator.swift index 09eb9e05..77d21362 100644 --- a/Shared/Coordinators/LiveTVCoordinator.swift +++ b/Shared/Coordinators/LiveTVCoordinator.swift @@ -16,15 +16,15 @@ final class LiveTVCoordinator: NavigationCoordinatable { @Root var start = makeStart -// @Route(.push) -// var search = makeSearch + @Route(.fullScreen) + var videoPlayer = makeVideoPlayer @ViewBuilder func makeStart() -> some View { LiveTVChannelsView() } -// func makeSearch(viewModel: LibrarySearchViewModel) -> SearchCoordinator { -// SearchCoordinator(viewModel: viewModel) -// } + func makeVideoPlayer(viewModel: VideoPlayerViewModel) -> NavigationViewCoordinator { + NavigationViewCoordinator(LiveTVVideoPlayerCoordinator(viewModel: viewModel)) + } } diff --git a/Swiftfin/Views/LiveTVChannelItemWideElement.swift b/Swiftfin/Views/LiveTVChannelItemWideElement.swift index 6dba9684..fdf9ffd0 100644 --- a/Swiftfin/Views/LiveTVChannelItemWideElement.swift +++ b/Swiftfin/Views/LiveTVChannelItemWideElement.swift @@ -63,11 +63,11 @@ struct LiveTVChannelItemWideElement: View { var body: some View { ZStack { HStack { - ZStack(alignment: .bottomLeading) { + ZStack(alignment: .center) { ImageView(channel.getPrimaryImage(maxWidth: 128)) .aspectRatio(contentMode: .fit) .padding(.init(top: 0, leading: 0, bottom: 8, trailing: 0)) - VStack { + VStack(alignment: .center) { Spacer() .frame(maxHeight: .infinity) GeometryReader { gp in @@ -81,8 +81,13 @@ struct LiveTVChannelItemWideElement: View { .frame(width: CGFloat(progressPercent * gp.size.width), height: 6) } } - .frame(height: 6, alignment: .bottomLeading) - .padding(.init(top: 0, leading: 0, bottom: 0, trailing: 8)) + .frame(height: 6, alignment: .center) + .padding(.init(top: 0, leading: 4, bottom: 0, trailing: 4)) + } + if loading { + + ProgressView() + } } .aspectRatio(1.0, contentMode: .fit) @@ -139,14 +144,15 @@ struct LiveTVChannelItemWideElement: View { .frame(alignment: .leading) .padding() .opacity(loading ? 0.5 : 1.0) - - if loading { - ProgressView() - } } .background( RoundedRectangle(cornerRadius: 16, style: .continuous).fill(Color("BackgroundColor")) ) .frame(height: 128) + .onTapGesture { + onSelect { loadingState in + loading = loadingState + } + } } } diff --git a/Swiftfin/Views/LiveTVChannelsView.swift b/Swiftfin/Views/LiveTVChannelsView.swift index c6102e42..318a819d 100644 --- a/Swiftfin/Views/LiveTVChannelsView.swift +++ b/Swiftfin/Views/LiveTVChannelsView.swift @@ -15,7 +15,7 @@ typealias LiveTVChannelViewProgram = (timeDisplay: String, title: String) struct LiveTVChannelsView: View { @EnvironmentObject - var router: LiveTVChannelsCoordinator.Router + var router: LiveTVCoordinator.Router @StateObject var viewModel = LiveTVChannelsViewModel() @State private var isPortrait = false @@ -75,12 +75,12 @@ struct LiveTVChannelsView: View { currentProgramText: currentProgramDisplayText, nextProgramsText: nextProgramsDisplayText(nextItems: nextItems, timeFormatter: viewModel.timeFormatter), onSelect: { loadingAction in - loadingAction(true) - self.viewModel.fetchVideoPlayerViewModel(item: channel) { playerViewModel in - // self.router.route(to: \.videoPlayer, playerViewModel) - // DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - // loadingAction(false) - // } + loadingAction(true) + self.viewModel.fetchVideoPlayerViewModel(item: channel) { playerViewModel in + self.router.route(to: \.videoPlayer, playerViewModel) + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + loadingAction(false) + } } }) } @@ -165,8 +165,7 @@ struct LiveTVChannelsView: View { let scenes = UIApplication.shared.connectedScenes let windowScene = scenes.first as? UIWindowScene guard let scene = windowScene else { return } - self.isPortrait = scene.interfaceOrientation.isPortrait - print("orientationDidChange: isPortrait? \(self.isPortrait)") + self.isPortrait = scene.interfaceOrientation.isPortrait } private func nextProgramsDisplayText(nextItems: [BaseItemDto], timeFormatter: DateFormatter) -> [LiveTVChannelViewProgram] {