From 4f3f6d4c08203d6d42d5bf19ba85e230894f1747 Mon Sep 17 00:00:00 2001 From: Ethan Pippin Date: Mon, 3 Jan 2022 19:00:02 -0700 Subject: [PATCH] more iOS settings and fix appearance setting --- JellyfinPlayer/App/JellyfinPlayerApp.swift | 10 +-- .../Views/BasicAppSettingsView.swift | 39 +++++++++-- .../Views/OverlaySettingsView.swift | 2 + JellyfinPlayer/Views/SettingsView.swift | 4 +- .../VideoPlayer/VLCPlayerOverlayView.swift | 65 ++++++++++--------- .../MainCoordinator/iOSMainCoordinator.swift | 10 +++ Shared/Singleton/SessionManager.swift | 3 - .../SwiftfinStore/SwiftfinStoreDefaults.swift | 3 + .../BasicAppSettingsViewModel.swift | 10 ++- Shared/ViewModels/VideoPlayerViewModel.swift | 2 + 10 files changed, 97 insertions(+), 51 deletions(-) diff --git a/JellyfinPlayer/App/JellyfinPlayerApp.swift b/JellyfinPlayer/App/JellyfinPlayerApp.swift index 88d6880a..e87b3234 100644 --- a/JellyfinPlayer/App/JellyfinPlayerApp.swift +++ b/JellyfinPlayer/App/JellyfinPlayerApp.swift @@ -15,7 +15,6 @@ import SwiftUI struct JellyfinPlayerApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate - @Default(.appAppearance) var appAppearance var body: some Scene { WindowGroup { @@ -25,21 +24,18 @@ struct JellyfinPlayerApp: App { window?.rootViewController = PreferenceUIHostingController(wrappedView: MainCoordinator().view()) }) .onAppear { - setupAppearance() + JellyfinPlayerApp.setupAppearance() } .onOpenURL { url in AppURLHandler.shared.processDeepLink(url: url) } - .onChange(of: appAppearance) { newValue in - setupAppearance() - } } } - private func setupAppearance() { + static func setupAppearance() { let scenes = UIApplication.shared.connectedScenes let windowScene = scenes.first as? UIWindowScene - windowScene?.windows.first?.overrideUserInterfaceStyle = appAppearance.style + windowScene?.windows.first?.overrideUserInterfaceStyle = Defaults[.appAppearance].style } } diff --git a/JellyfinPlayer/Views/BasicAppSettingsView.swift b/JellyfinPlayer/Views/BasicAppSettingsView.swift index 71fe5a0b..ef441842 100644 --- a/JellyfinPlayer/Views/BasicAppSettingsView.swift +++ b/JellyfinPlayer/Views/BasicAppSettingsView.swift @@ -15,7 +15,9 @@ struct BasicAppSettingsView: View { @EnvironmentObject var basicAppSettingsRouter: BasicAppSettingsCoordinator.Router @ObservedObject var viewModel: BasicAppSettingsViewModel - @State var resetTapped: Bool = false + @State var resetUserSettingsTapped: Bool = false + @State var resetAppSettingsTapped: Bool = false + @State var removeAllUsersTapped: Bool = false @Default(.appAppearance) var appAppearance @Default(.defaultHTTPScheme) var defaultHTTPScheme @@ -43,15 +45,40 @@ struct BasicAppSettingsView: View { } Button { - resetTapped = true + resetUserSettingsTapped = true + } label: { + Text("Reset User Settings") + } + + Button { + resetAppSettingsTapped = true + } label: { + Text("Reset App Settings") + } + + Button { + removeAllUsersTapped = true + } label: { + Text("Remove All Users") + } + } + .alert("Reset User Settings", isPresented: $resetUserSettingsTapped, actions: { + Button(role: .destructive) { + viewModel.resetUserSettings() } label: { L10n.reset.text } - } - .alert(L10n.reset, isPresented: $resetTapped, actions: { + }) + .alert("Reset App Settings", isPresented: $resetAppSettingsTapped, actions: { Button(role: .destructive) { - viewModel.reset() - basicAppSettingsRouter.dismissCoordinator() + viewModel.resetAppSettings() + } label: { + L10n.reset.text + } + }) + .alert("Remove All Users", isPresented: $removeAllUsersTapped, actions: { + Button(role: .destructive) { + viewModel.removeAllUsers() } label: { L10n.reset.text } diff --git a/JellyfinPlayer/Views/OverlaySettingsView.swift b/JellyfinPlayer/Views/OverlaySettingsView.swift index f9cc687f..eb0e611a 100644 --- a/JellyfinPlayer/Views/OverlaySettingsView.swift +++ b/JellyfinPlayer/Views/OverlaySettingsView.swift @@ -16,6 +16,7 @@ struct OverlaySettingsView: View { @Default(.shouldShowPlayPreviousItem) var shouldShowPlayPreviousItem @Default(.shouldShowPlayNextItem) var shouldShowPlayNextItem @Default(.shouldShowAutoPlay) var shouldShowAutoPlay + @Default(.shouldShowJumpButtonsInOverlayMenu) var shouldShowJumpButtonsInOverlayMenu var body: some View { Form { @@ -29,6 +30,7 @@ struct OverlaySettingsView: View { Toggle("\(Image(systemName: "chevron.left.circle")) Play Previous Item", isOn: $shouldShowPlayPreviousItem) Toggle("\(Image(systemName: "chevron.right.circle")) Play Next Item", isOn: $shouldShowPlayNextItem) Toggle("\(Image(systemName: "play.circle.fill")) Auto Play", isOn: $shouldShowAutoPlay) + Toggle("Allow Edit Jump Lengths", isOn: $shouldShowJumpButtonsInOverlayMenu) } } } diff --git a/JellyfinPlayer/Views/SettingsView.swift b/JellyfinPlayer/Views/SettingsView.swift index 501d2c0f..3bb528fd 100644 --- a/JellyfinPlayer/Views/SettingsView.swift +++ b/JellyfinPlayer/Views/SettingsView.swift @@ -41,7 +41,7 @@ struct SettingsView: View { } label: { HStack { Text("Server") - .foregroundColor(.white) + .foregroundColor(.primary) Spacer() Text(viewModel.server.name) .foregroundColor(.jellyfinPurple) @@ -94,7 +94,7 @@ struct SettingsView: View { } label: { HStack { Text("Overlay") - .foregroundColor(.white) + .foregroundColor(.primary) Spacer() Text(overlayType.label) diff --git a/JellyfinPlayer/Views/VideoPlayer/VLCPlayerOverlayView.swift b/JellyfinPlayer/Views/VideoPlayer/VLCPlayerOverlayView.swift index eea32862..5e7dce0d 100644 --- a/JellyfinPlayer/Views/VideoPlayer/VLCPlayerOverlayView.swift +++ b/JellyfinPlayer/Views/VideoPlayer/VLCPlayerOverlayView.swift @@ -190,44 +190,45 @@ struct VLCPlayerOverlayView: View { } } - Menu { - ForEach(VideoPlayerJumpLength.allCases, id: \.self) { forwardLength in - Button { - viewModel.jumpForwardLength = forwardLength - } label: { - if forwardLength == viewModel.jumpForwardLength { - Label(forwardLength.shortLabel, systemImage: "checkmark") - } else { - Text(forwardLength.shortLabel) + if viewModel.shouldShowJumpButtonsInOverlayMenu { + Menu { + ForEach(VideoPlayerJumpLength.allCases, id: \.self) { forwardLength in + Button { + viewModel.jumpForwardLength = forwardLength + } label: { + if forwardLength == viewModel.jumpForwardLength { + Label(forwardLength.shortLabel, systemImage: "checkmark") + } else { + Text(forwardLength.shortLabel) + } } } - } - } label: { - HStack { - Image(systemName: "goforward") - Text("Jump Forward Length") - } - } - - Menu { - ForEach(VideoPlayerJumpLength.allCases, id: \.self) { backwardLength in - Button { - viewModel.jumpBackwardLength = backwardLength - } label: { - if backwardLength == viewModel.jumpBackwardLength { - Label(backwardLength.shortLabel, systemImage: "checkmark") - } else { - Text(backwardLength.shortLabel) - } + } label: { + HStack { + Image(systemName: "goforward") + Text("Jump Forward Length") } } - } label: { - HStack { - Image(systemName: "gobackward") - Text("Jump Backward Length") + + Menu { + ForEach(VideoPlayerJumpLength.allCases, id: \.self) { backwardLength in + Button { + viewModel.jumpBackwardLength = backwardLength + } label: { + if backwardLength == viewModel.jumpBackwardLength { + Label(backwardLength.shortLabel, systemImage: "checkmark") + } else { + Text(backwardLength.shortLabel) + } + } + } + } label: { + HStack { + Image(systemName: "gobackward") + Text("Jump Backward Length") + } } } - } label: { Image(systemName: "ellipsis.circle") } diff --git a/Shared/Coordinators/MainCoordinator/iOSMainCoordinator.swift b/Shared/Coordinators/MainCoordinator/iOSMainCoordinator.swift index 067d16f9..5a1e5eb7 100644 --- a/Shared/Coordinators/MainCoordinator/iOSMainCoordinator.swift +++ b/Shared/Coordinators/MainCoordinator/iOSMainCoordinator.swift @@ -7,6 +7,8 @@ * Copyright 2021 Aiden Vigue & Jellyfin Contributors */ +import Combine +import Defaults import Foundation import Nuke import Stinsen @@ -18,6 +20,8 @@ final class MainCoordinator: NavigationCoordinatable { @Root var mainTab = makeMainTab @Root var serverList = makeServerList + + private var cancellables = Set() init() { if SessionManager.main.currentLogin != nil { @@ -45,6 +49,12 @@ final class MainCoordinator: NavigationCoordinatable { nc.addObserver(self, selector: #selector(didLogOut), name: SwiftfinNotificationCenter.Keys.didSignOut, object: nil) nc.addObserver(self, selector: #selector(processDeepLink), name: SwiftfinNotificationCenter.Keys.processDeepLink, object: nil) nc.addObserver(self, selector: #selector(didChangeServerCurrentURI), name: SwiftfinNotificationCenter.Keys.didChangeServerCurrentURI, object: nil) + + Defaults.publisher(.appAppearance) + .sink { _ in + JellyfinPlayerApp.setupAppearance() + } + .store(in: &cancellables) } @objc func didLogIn() { diff --git a/Shared/Singleton/SessionManager.swift b/Shared/Singleton/SessionManager.swift index 59c7cae2..bdf96aae 100644 --- a/Shared/Singleton/SessionManager.swift +++ b/Shared/Singleton/SessionManager.swift @@ -254,9 +254,6 @@ final class SessionManager { delete(server: server) } - // Delete general UserDefaults - SwiftfinStore.Defaults.generalSuite.removeAll() - SwiftfinNotificationCenter.main.post(name: SwiftfinNotificationCenter.Keys.didPurge, object: nil) } diff --git a/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift b/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift index fc5207ae..921a3ba9 100644 --- a/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift +++ b/Shared/SwiftfinStore/SwiftfinStoreDefaults.swift @@ -49,6 +49,9 @@ extension Defaults.Keys { static let shouldShowPlayNextItem = Key("shouldShowNextItem", default: true, suite: SwiftfinStore.Defaults.generalSuite) static let shouldShowAutoPlay = Key("shouldShowAutoPlayNextItem", default: true, suite: SwiftfinStore.Defaults.generalSuite) + // Should show video player items in overlay menu + static let shouldShowJumpButtonsInOverlayMenu = Key("shouldShowJumpButtonsInMenu", default: true, suite: SwiftfinStore.Defaults.generalSuite) + // Experimental settings struct Experimental { static let syncSubtitleStateWithAdjacent = Key("experimental.syncSubtitleState", default: false, suite: SwiftfinStore.Defaults.generalSuite) diff --git a/Shared/ViewModels/BasicAppSettingsViewModel.swift b/Shared/ViewModels/BasicAppSettingsViewModel.swift index 9cc1fa43..fb5c8887 100644 --- a/Shared/ViewModels/BasicAppSettingsViewModel.swift +++ b/Shared/ViewModels/BasicAppSettingsViewModel.swift @@ -13,7 +13,15 @@ final class BasicAppSettingsViewModel: ViewModel { let appearances = AppAppearance.allCases - func reset() { + func resetUserSettings() { + SwiftfinStore.Defaults.generalSuite.removeAll() + } + + func resetAppSettings() { + SwiftfinStore.Defaults.universalSuite.removeAll() + } + + func removeAllUsers() { SessionManager.main.purge() } } diff --git a/Shared/ViewModels/VideoPlayerViewModel.swift b/Shared/ViewModels/VideoPlayerViewModel.swift index 2069185d..f810ce62 100644 --- a/Shared/ViewModels/VideoPlayerViewModel.swift +++ b/Shared/ViewModels/VideoPlayerViewModel.swift @@ -62,6 +62,7 @@ final class VideoPlayerViewModel: ViewModel { let shouldShowPlayPreviousItem: Bool let shouldShowPlayNextItem: Bool let shouldShowAutoPlay: Bool + let shouldShowJumpButtonsInOverlayMenu: Bool // MARK: General let item: BaseItemDto @@ -134,6 +135,7 @@ final class VideoPlayerViewModel: ViewModel { self.jumpBackwardLength = Defaults[.videoPlayerJumpBackward] self.jumpForwardLength = Defaults[.videoPlayerJumpForward] self.jumpGesturesEnabled = Defaults[.jumpGesturesEnabled] + self.shouldShowJumpButtonsInOverlayMenu = Defaults[.shouldShowJumpButtonsInOverlayMenu] super.init()