From a16d70ab11a99e0e1281fe6f66f6aaade5fc84e8 Mon Sep 17 00:00:00 2001 From: PangMo5 Date: Wed, 25 Aug 2021 18:03:04 +0900 Subject: [PATCH] Respond to main branch --- .../Coordinators/HomeCoordinator.swift | 2 +- .../Coordinators/SettingsCoordinator.swift | 11 +- JellyfinPlayer/SettingsView.swift | 193 ++++++++---------- JellyfinPlayer/VideoPlayer.swift | 1 - 4 files changed, 94 insertions(+), 113 deletions(-) diff --git a/JellyfinPlayer/Coordinators/HomeCoordinator.swift b/JellyfinPlayer/Coordinators/HomeCoordinator.swift index ac152866..e4369b06 100644 --- a/JellyfinPlayer/Coordinators/HomeCoordinator.swift +++ b/JellyfinPlayer/Coordinators/HomeCoordinator.swift @@ -23,7 +23,7 @@ final class HomeCoordinator: NavigationCoordinatable { func resolveRoute(route: Route) -> Transition { switch route { case .settings: - return .modal(SettingsCoordinator().eraseToAnyCoordinatable()) + return .modal(NavigationViewCoordinator(SettingsCoordinator()).eraseToAnyCoordinatable()) case let .library(viewModel, title): return .push(LibraryCoordinator(viewModel: viewModel, title: title).eraseToAnyCoordinatable()) case let .item(viewModel): diff --git a/JellyfinPlayer/Coordinators/SettingsCoordinator.swift b/JellyfinPlayer/Coordinators/SettingsCoordinator.swift index 07c23532..15e05678 100644 --- a/JellyfinPlayer/Coordinators/SettingsCoordinator.swift +++ b/JellyfinPlayer/Coordinators/SettingsCoordinator.swift @@ -14,9 +14,16 @@ import SwiftUI final class SettingsCoordinator: NavigationCoordinatable { var navigationStack = NavigationStack() - enum Route: NavigationRoute {} + enum Route: NavigationRoute { + case serverDetail + } - func resolveRoute(route: Route) -> Transition {} + func resolveRoute(route: Route) -> Transition { + switch route { + case .serverDetail: + return .push(ServerDetailView().eraseToAnyView()) + } + } @ViewBuilder func start() -> some View { diff --git a/JellyfinPlayer/SettingsView.swift b/JellyfinPlayer/SettingsView.swift index c78cc886..769f2615 100644 --- a/JellyfinPlayer/SettingsView.swift +++ b/JellyfinPlayer/SettingsView.swift @@ -11,7 +11,7 @@ import Stinsen import SwiftUI struct SettingsView: View { - @EnvironmentObject var mainRouter: ViewRouter + @RouterObject var mainRouter: ViewRouter? @EnvironmentObject var settingsRouter: NavigationRouter @Environment(\.managedObjectContext) private var viewContext @@ -27,125 +27,100 @@ struct SettingsView: View { @Default(.videoPlayerJumpBackward) var jumpBackwardLength var body: some View { - NavigationView { - Form { - Section(header: EmptyView()) { + Form { + Section { + HStack { + Text("User") + Spacer() + Text(SessionManager.current.user.username ?? "") + .foregroundColor(.jellyfinPurple) + } + + Button { + settingsRouter.route(to: .serverDetail) + } label: { HStack { - Text("User") + Text("Server") Spacer() - Text(SessionManager.current.user.username ?? "") + Text(ServerEnvironment.current.server.name ?? "") .foregroundColor(.jellyfinPurple) } - - NavigationLink( - destination: ServerDetailView(), - label: { - HStack { - Text("Server") - Spacer() - Text(ServerEnvironment.current.server.name ?? "") - .foregroundColor(.jellyfinPurple) - } - }) - - Button { - close = false - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - SessionManager.current.logout() - let nc = NotificationCenter.default - nc.post(name: Notification.Name("didSignOut"), object: nil) - } - } label: { - Text("Sign out") - .font(.callout) - } - } - Section(header: Text("Playback")) { - Picker("Default local quality", selection: $inNetworkStreamBitrate) { - ForEach(self.viewModel.bitrates, id: \.self) { bitrate in - Text(bitrate.name).tag(bitrate.value) - } - } - - Picker("Default remote quality", selection: $outOfNetworkStreamBitrate) { - ForEach(self.viewModel.bitrates, id: \.self) { bitrate in - Text(bitrate.name).tag(bitrate.value) - } - } - - Picker("Jump Forward Length", selection: $jumpForwardLength) { - ForEach(self.viewModel.videoPlayerJumpLengths, id: \.self) { length in - Text(length.label).tag(length.rawValue) - } - } - - Picker("Jump Backward Length", selection: $jumpBackwardLength) { - ForEach(self.viewModel.videoPlayerJumpLengths, id: \.self) { length in - Text(length.label).tag(length.rawValue) - } - } } - Section(header: Text("Accessibility")) { - Toggle("Automatically show subtitles", isOn: $isAutoSelectSubtitles) - SearchablePicker(label: "Preferred subtitle language", - options: viewModel.langs, - optionToString: { $0.name }, - selected: Binding(get: { - viewModel.langs - .first(where: { $0.isoCode == autoSelectSubtitlesLangcode - }) ?? - .auto - }, - set: { autoSelectSubtitlesLangcode = $0.isoCode })) - SearchablePicker(label: "Preferred audio language", - options: viewModel.langs, - optionToString: { $0.name }, - selected: Binding(get: { - viewModel.langs - .first(where: { $0.isoCode == autoSelectAudioLangcode }) ?? - .auto - }, - set: { autoSelectAudioLangcode = $0.isoCode })) - Picker(NSLocalizedString("Appearance", comment: ""), selection: $appAppearance) { - ForEach(self.viewModel.appearances, id: \.self) { appearance in - Text(appearance.localizedName).tag(appearance.rawValue) - } - }.onChange(of: appAppearance, perform: { value in - guard let appearance = AppAppearance(rawValue: value) else { return } - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = appearance.style - }) - } - - Section(header: Text(ServerEnvironment.current.server.name ?? "")) { - HStack { - Text("Signed in as \(username)").foregroundColor(.primary) - Spacer() - Button { - print("logging out") - mainRouter.route(to: .connectToServer) - settingsRouter.dismiss() - } label: { - Text("Switch user").font(.callout) - } - } - Button { + Button { + settingsRouter.dismiss { SessionManager.current.logout() - mainRouter.route(to: .connectToServer) - settingsRouter.dismiss() - } label: { - Text("Sign out").font(.callout) + mainRouter?.route(to: .connectToServer) + } + } label: { + Text("Sign out") + .font(.callout) + } + } + Section(header: Text("Playback")) { + Picker("Default local quality", selection: $inNetworkStreamBitrate) { + ForEach(self.viewModel.bitrates, id: \.self) { bitrate in + Text(bitrate.name).tag(bitrate.value) + } + } + + Picker("Default remote quality", selection: $outOfNetworkStreamBitrate) { + ForEach(self.viewModel.bitrates, id: \.self) { bitrate in + Text(bitrate.name).tag(bitrate.value) + } + } + + Picker("Jump Forward Length", selection: $jumpForwardLength) { + ForEach(self.viewModel.videoPlayerJumpLengths, id: \.self) { length in + Text(length.label).tag(length.rawValue) + } + } + + Picker("Jump Backward Length", selection: $jumpBackwardLength) { + ForEach(self.viewModel.videoPlayerJumpLengths, id: \.self) { length in + Text(length.label).tag(length.rawValue) } } } - .navigationBarTitle("Settings", displayMode: .inline) - .toolbar { - ToolbarItemGroup(placement: .navigationBarLeading) { - Button { - settingsRouter.dismiss() - } label: { - Image(systemName: "xmark") + + Section(header: Text("Accessibility")) { + Toggle("Automatically show subtitles", isOn: $isAutoSelectSubtitles) + SearchablePicker(label: "Preferred subtitle language", + options: viewModel.langs, + optionToString: { $0.name }, + selected: Binding(get: { + viewModel.langs + .first(where: { $0.isoCode == autoSelectSubtitlesLangcode + }) ?? + .auto + }, + set: { autoSelectSubtitlesLangcode = $0.isoCode })) + SearchablePicker(label: "Preferred audio language", + options: viewModel.langs, + optionToString: { $0.name }, + selected: Binding(get: { + viewModel.langs + .first(where: { $0.isoCode == autoSelectAudioLangcode }) ?? + .auto + }, + set: { autoSelectAudioLangcode = $0.isoCode })) + Picker(NSLocalizedString("Appearance", comment: ""), selection: $appAppearance) { + ForEach(self.viewModel.appearances, id: \.self) { appearance in + Text(appearance.localizedName).tag(appearance.rawValue) } + }.onChange(of: appAppearance, perform: { value in + guard let appearance = AppAppearance(rawValue: value) else { return } + UIApplication.shared.windows.first?.overrideUserInterfaceStyle = appearance.style + }) + } + } + .navigationBarTitle("Settings", displayMode: .inline) + .toolbar { + ToolbarItemGroup(placement: .navigationBarLeading) { + Button { + settingsRouter.dismiss() + } label: { + Image(systemName: "xmark") } } } diff --git a/JellyfinPlayer/VideoPlayer.swift b/JellyfinPlayer/VideoPlayer.swift index cef3bf52..f4799009 100644 --- a/JellyfinPlayer/VideoPlayer.swift +++ b/JellyfinPlayer/VideoPlayer.swift @@ -28,7 +28,6 @@ protocol PlayerViewControllerDelegate: AnyObject { class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRemoteMediaClientListener { @RouterObject - var main: ViewRouter? weak var delegate: PlayerViewControllerDelegate?