Merge branch 'main' into theme-setting

This commit is contained in:
Ethan Pippin 2021-07-26 13:44:22 -06:00
commit 1398d6cac0
11 changed files with 113 additions and 63 deletions

View File

@ -111,6 +111,7 @@ struct ConnectToServerView: View {
TextField(NSLocalizedString("Server URL", comment: ""), text: $uri)
.disableAutocorrection(true)
.autocapitalization(.none)
.keyboardType(.URL)
Button {
viewModel.connectToServer()
} label: {

View File

@ -22,6 +22,11 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>

View File

@ -109,6 +109,7 @@ struct ConnectToServerView: View {
TextField(NSLocalizedString("Server URL", comment: ""), text: $uri)
.disableAutocorrection(true)
.autocapitalization(.none)
.keyboardType(.URL)
Button {
viewModel.connectToServer()
} label: {

View File

@ -30,8 +30,6 @@
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>${PRODUCT_NAME} uses Bluetooth to discover nearby Cast devices.</string>

View File

@ -34,7 +34,7 @@ struct ItemView: View {
.statusBar(hidden: true)
.edgesIgnoringSafeArea(.all)
.prefersHomeIndicatorAutoHidden(true)
}.supportedOrientations(.landscape), isActive: $videoPlayerItem.shouldShowPlayer) {
}, isActive: $videoPlayerItem.shouldShowPlayer) {
EmptyView()
}
VStack {
@ -56,7 +56,6 @@ struct ItemView: View {
.navigationBarHidden(false)
.navigationBarBackButtonHidden(false)
.environmentObject(videoPlayerItem)
.supportedOrientations(.all)
}
}
}

View File

@ -209,6 +209,8 @@ class EmailHelper: NSObject, MFMailComposeViewControllerDelegate {
@main
struct JellyfinPlayerApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
let persistenceController = PersistenceController.shared
var body: some Scene {
@ -224,3 +226,12 @@ struct JellyfinPlayerApp: App {
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
static var orientationLock = UIInterfaceOrientationMask.all
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
AppDelegate.orientationLock
}
}

View File

@ -12,13 +12,13 @@ import SwiftUI
struct LibrarySearchView: View {
@StateObject var viewModel: LibrarySearchViewModel
@State var searchQuery = ""
@State private var tracks: [GridItem] = Array(repeating: .init(.flexible()), count: Int(UIScreen.main.bounds.size.width) / 125)
func recalcTracks() {
tracks = Array(repeating: .init(.flexible()), count: Int(UIScreen.main.bounds.size.width) / 125)
}
var body: some View {
ZStack {
VStack {
@ -40,7 +40,7 @@ struct LibrarySearchView: View {
}
.navigationBarTitle("Search", displayMode: .inline)
}
var suggestionsListView: some View {
ScrollView {
LazyVStack(spacing: 8) {
@ -61,7 +61,7 @@ struct LibrarySearchView: View {
.padding(.horizontal, 16)
}
}
var resultView: some View {
let items = items(for: viewModel.selectedItemType)
return VStack(alignment: .leading, spacing: 16) {
@ -90,7 +90,7 @@ struct LibrarySearchView: View {
recalcTracks()
}
}
func items(for type: ItemType) -> [BaseItemDto] {
switch type {
case .episode:
@ -106,7 +106,7 @@ struct LibrarySearchView: View {
}
private extension ItemType {
var localized: String {
switch self {
case .episode:

View File

@ -73,7 +73,7 @@ struct SettingsView: View {
})
}
Section {
Section(header: Text(ServerEnvironment.current.server.name ?? "")) {
HStack {
Text("Signed in as \(username)").foregroundColor(.primary)
Spacer()

View File

@ -81,7 +81,7 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
var playbackItem = PlaybackItem()
var remoteTimeUpdateTimer: Timer?
var upNextViewModel: UpNextViewModel = UpNextViewModel()
var lastOri: UIDeviceOrientation!
var lastOri: UIInterfaceOrientation!
// MARK: IBActions
@IBAction func seekSliderStart(_ sender: Any) {
@ -387,6 +387,7 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
// MARK: viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
if manifest.type == "Movie" {
titleLabel.text = manifest.name ?? ""
} else {
@ -396,14 +397,21 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
upNextViewModel.delegate = self
}
lastOri = UIDevice.current.orientation
DispatchQueue.main.async {
self.lastOri = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
AppDelegate.orientationLock = .landscape
if !UIDevice.current.orientation.isLandscape || UIDevice.current.orientation.isFlat {
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
if !self.lastOri.isLandscape {
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
}
}
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(didChangedOrientation), name: UIDevice.orientationDidChangeNotification, object: nil)
}
@objc func didChangedOrientation() {
lastOri = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
}
func mediaHasStartedPlaying() {
@ -438,12 +446,15 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.tabBar.isHidden = false
self.navigationController?.isNavigationBarHidden = false
overrideUserInterfaceStyle = .unspecified
UIDevice.current.setValue(lastOri.rawValue, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
super.viewWillDisappear(animated)
DispatchQueue.main.async {
AppDelegate.orientationLock = .all
UIDevice.current.setValue(self.lastOri.rawValue, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
}
}
// MARK: viewDidAppear
@ -479,19 +490,19 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
MediaInfoAPI.getPostedPlaybackInfo(itemId: manifest.id!, userId: SessionManager.current.user.user_id!, maxStreamingBitrate: Int(maxBitrate), startTimeTicks: manifest.userData?.playbackPositionTicks ?? 0, autoOpenLiveStream: true, playbackInfoDto: playbackInfo)
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
break
case .failure(let error):
if let err = error as? ErrorResponse {
switch err {
case .error(401, _, _, _):
self.delegate?.exitPlayer(self)
SessionManager.current.logout()
case .error:
self.delegate?.exitPlayer(self)
}
case .finished:
break
case .failure(let error):
if let err = error as? ErrorResponse {
switch err {
case .error(401, _, _, _):
self.delegate?.exitPlayer(self)
SessionManager.current.logout()
case .error:
self.delegate?.exitPlayer(self)
}
break
}
break
}
}, receiveValue: { [self] response in
playSessionId = response.playSessionId ?? ""
@ -906,35 +917,35 @@ extension PlayerViewController: GCKSessionManagerListener {
// MARK: - VLCMediaPlayer Delegates
extension PlayerViewController: VLCMediaPlayerDelegate {
func mediaPlayerStateChanged(_ aNotification: Notification!) {
let currentState: VLCMediaPlayerState = mediaPlayer.state
switch currentState {
case .stopped :
LogManager.shared.log.debug("Player state changed: STOPPED")
break
case .ended :
LogManager.shared.log.debug("Player state changed: ENDED")
break
case .playing :
LogManager.shared.log.debug("Player state changed: PLAYING")
sendProgressReport(eventName: "unpause")
delegate?.hideLoadingView(self)
paused = false
case .paused :
LogManager.shared.log.debug("Player state changed: PAUSED")
paused = true
case .opening :
LogManager.shared.log.debug("Player state changed: OPENING")
case .buffering :
LogManager.shared.log.debug("Player state changed: BUFFERING")
delegate?.showLoadingView(self)
case .error :
LogManager.shared.log.error("Video had error.")
sendStopReport()
case .esAdded:
mainActionButton.setImage(UIImage(systemName: "pause"), for: .normal)
@unknown default:
break
}
let currentState: VLCMediaPlayerState = mediaPlayer.state
switch currentState {
case .stopped :
LogManager.shared.log.debug("Player state changed: STOPPED")
break
case .ended :
LogManager.shared.log.debug("Player state changed: ENDED")
break
case .playing :
LogManager.shared.log.debug("Player state changed: PLAYING")
sendProgressReport(eventName: "unpause")
delegate?.hideLoadingView(self)
paused = false
case .paused :
LogManager.shared.log.debug("Player state changed: PAUSED")
paused = true
case .opening :
LogManager.shared.log.debug("Player state changed: OPENING")
case .buffering :
LogManager.shared.log.debug("Player state changed: BUFFERING")
delegate?.showLoadingView(self)
case .error :
LogManager.shared.log.error("Video had error.")
sendStopReport()
case .esAdded:
mainActionButton.setImage(UIImage(systemName: "pause"), for: .normal)
@unknown default:
break
}
}
func mediaPlayerTimeChanged(_ aNotification: Notification!) {

View File

@ -1,6 +1,9 @@
<p align="center">
<img alt="SwiftFin" height="125" src="https://github.com/jellyfin/SwiftFin/raw/main/JellyfinPlayer/Assets.xcassets/AppIcon.appiconset/152.png">
<h2 align="center">SwiftFin</h2>
<a href="https://translate.jellyfin.org/engage/swiftfin/">
<img src="https://translate.jellyfin.org/widgets/swiftfin/-/svg-badge.svg"/>
</a>
<a href="https://matrix.to/#/+jellyfin:matrix.org">
<img src="https://img.shields.io/matrix/jellyfin:matrix.org">
</a>
@ -19,6 +22,27 @@
<a href='https://testflight.apple.com/join/WiN0G62Q'><img height='70' alt='Join the Beta on TestFlight' src='https://anotherlens.app/testflight-badge.png'/></a>
**Don't see SwiftFin in your language?**
Check out our [Weblate instance](https://translate.jellyfin.org/projects/swiftfin/) to help translate SwiftFin and other projects.
<a href="https://translate.jellyfin.org/engage/swiftfin/">
<img src="https://translate.jellyfin.org/widgets/swiftfin/-/multi-auto.svg"/>
</a>
## ⚙️ Development
Xcode 13.0 with command line tools.
### Build Process
```bash
# install Cocoapods (if not installed)
$ sudo gem install cocoapods
# install dependencies
$ pod install
# open workspace and build it
$ open JellyfinPlayer.xcworkspace
```