more iOS settings and fix appearance setting

This commit is contained in:
Ethan Pippin 2022-01-03 19:00:02 -07:00
parent 3eb92cd325
commit 4f3f6d4c08
10 changed files with 97 additions and 51 deletions

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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)

View File

@ -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")
}

View File

@ -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<AnyCancellable>()
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() {

View File

@ -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)
}

View File

@ -49,6 +49,9 @@ extension Defaults.Keys {
static let shouldShowPlayNextItem = Key<Bool>("shouldShowNextItem", default: true, suite: SwiftfinStore.Defaults.generalSuite)
static let shouldShowAutoPlay = Key<Bool>("shouldShowAutoPlayNextItem", default: true, suite: SwiftfinStore.Defaults.generalSuite)
// Should show video player items in overlay menu
static let shouldShowJumpButtonsInOverlayMenu = Key<Bool>("shouldShowJumpButtonsInMenu", default: true, suite: SwiftfinStore.Defaults.generalSuite)
// Experimental settings
struct Experimental {
static let syncSubtitleStateWithAdjacent = Key<Bool>("experimental.syncSubtitleState", default: false, suite: SwiftfinStore.Defaults.generalSuite)

View File

@ -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()
}
}

View File

@ -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()