diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 45f86bc..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/xcode.xml b/.idea/xcode.xml index 341efb1..6bd1ab3 100644 --- a/.idea/xcode.xml +++ b/.idea/xcode.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Podfile b/Podfile index ea2c944..a697a3b 100644 --- a/Podfile +++ b/Podfile @@ -16,6 +16,7 @@ target 'kplayer' do pod 'Nimbus/Photos' pod 'Nimbus/PagingScrollView' pod 'BMPlayer', '0.8.6' + pod 'WebBrowser' #pod 'AFNetworking', '~>2.1' #pod 'Dollar', '6.1.0' #pod 'Cent', '6.0.3' diff --git a/kplayer.xcodeproj/project.pbxproj b/kplayer.xcodeproj/project.pbxproj index ebb9466..dda6767 100644 --- a/kplayer.xcodeproj/project.pbxproj +++ b/kplayer.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 1C73640D928DE56D35175D39 /* UploadOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736260E748CF136FF37EA7 /* UploadOperation.swift */; }; 1C73646F87B495A47D7943C7 /* NetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7369EC16B19B32B515169E /* NetData.swift */; }; 1C736503B656C999E5E12081 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7365B06FA66294E99AC2D3 /* NetworkManager.swift */; }; - 1C73651E1241702E5032A8A4 /* scratch.txt in Resources */ = {isa = PBXBuildFile; fileRef = 1C736E3BE8EC464D6F5DC8FA /* scratch.txt */; }; 1C73654C9EA6D255CFC039C5 /* NetworkHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C73620D01687FB4F1811C5C /* NetworkHelper.swift */; }; 1C7365885FAF292F2221ED44 /* MediaPhotoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C73673DC671535E3A049F54 /* MediaPhotoController.swift */; }; 1C73675C34BE0990D44570BE /* ItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736253AB7A95EA41B605B7 /* ItemModel.swift */; }; @@ -29,7 +28,6 @@ 1C736D16E81BA1FB325200E0 /* HanekeFetchOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7360744ABACC3557D05760 /* HanekeFetchOperation.swift */; }; 1C736D24891597F2728230EE /* ImageLoadOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7360A94DBECA685ED8602F /* ImageLoadOperation.swift */; }; 1C736D24B49451141CD4B64D /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7369F53095B7A4D65679C2 /* DetailViewController.swift */; }; - 1C736E1B6330FC91332F204D /* scratch2.txt in Resources */ = {isa = PBXBuildFile; fileRef = 1C7362A332872013B9B04CBB /* scratch2.txt */; }; 1C736F6A223D4ADB2E1BA733 /* ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736069C214E9522BB1BD97 /* ItemCell.swift */; }; 1C736FB92B19FE17E4357C85 /* MediaItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C73688DAB88F9360FB62A49 /* MediaItem.swift */; }; AA74B07A01F0E99E6DEC7D1B /* Pods_kplayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B75159FFCD5A882E6F167FE /* Pods_kplayer.framework */; }; @@ -60,7 +58,6 @@ 1C73620D01687FB4F1811C5C /* NetworkHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkHelper.swift; sourceTree = ""; }; 1C736253AB7A95EA41B605B7 /* ItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemModel.swift; sourceTree = ""; }; 1C736260E748CF136FF37EA7 /* UploadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadOperation.swift; sourceTree = ""; }; - 1C7362A332872013B9B04CBB /* scratch2.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = scratch2.txt; sourceTree = ""; }; 1C73648CEC974A2500172064 /* ViewControllerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerExtensions.swift; sourceTree = ""; }; 1C7365B06FA66294E99AC2D3 /* NetworkManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = ""; }; 1C7367379DEE94EBF3FAFA78 /* VideoPlayerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoPlayerController.swift; sourceTree = ""; }; @@ -75,7 +72,6 @@ 1C736D981F8315FFD7D40695 /* KBMPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KBMPlayer.swift; sourceTree = ""; }; 1C736D9BB5498E7E8F11C754 /* HeaderCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderCell.swift; sourceTree = ""; }; 1C736DCCE3AA9993E15F7652 /* UIImageExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = ""; }; - 1C736E3BE8EC464D6F5DC8FA /* scratch.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = scratch.txt; sourceTree = ""; }; 1C736F9338CE36708244D42A /* DataLoadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataLoadOperation.swift; sourceTree = ""; }; 6D522F61736592330F481B4F /* Pods-kplayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-kplayer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-kplayer/Pods-kplayer.debug.xcconfig"; sourceTree = ""; }; 8B75159FFCD5A882E6F167FE /* Pods_kplayer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_kplayer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -228,9 +224,7 @@ 1C73615846EE8B07DAAFD230 /* detail */, 1C7364808E72BFA7575E75E1 /* master */, 1C7363B608460DED4F522D1C /* photo */, - 1C736E3BE8EC464D6F5DC8FA /* scratch.txt */, 1C736F3946A38499113D351A /* video */, - 1C7362A332872013B9B04CBB /* scratch2.txt */, ); path = kplayer; sourceTree = ""; @@ -308,18 +302,18 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = "Marco Schmickler"; TargetAttributes = { C98AF5CE1B124D6A00D196CC = { CreatedOnToolsVersion = 6.3.1; DevelopmentTeam = G9J99WBBN9; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; C98AF5E81B124D6A00D196CC = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 1000; TestTargetID = C98AF5CE1B124D6A00D196CC; }; }; @@ -352,8 +346,6 @@ C98AF5E41B124D6A00D196CC /* LaunchScreen.xib in Resources */, C98AF5E11B124D6A00D196CC /* Images.xcassets in Resources */, 1C736A5FA5BA53B2597F2ED7 /* Kirschkeks-256x256.png in Resources */, - 1C73651E1241702E5032A8A4 /* scratch.txt in Resources */, - 1C736E1B6330FC91332F204D /* scratch2.txt in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -381,6 +373,7 @@ "${BUILT_PRODUCTS_DIR}/NVActivityIndicatorView/NVActivityIndicatorView.framework", "${BUILT_PRODUCTS_DIR}/Nimbus/Nimbus.framework", "${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework", + "${BUILT_PRODUCTS_DIR}/WebBrowser/WebBrowser.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -391,6 +384,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NVActivityIndicatorView.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimbus.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebBrowser.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -498,12 +492,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -552,12 +548,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -602,7 +600,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -621,7 +620,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -641,7 +641,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "schmickler.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/kplayer.app/kplayer"; }; name = Debug; @@ -658,7 +659,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "schmickler.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/kplayer.app/kplayer"; }; name = Release; diff --git a/kplayer/AppDelegate.swift b/kplayer/AppDelegate.swift index b65f204..c254a19 100644 --- a/kplayer/AppDelegate.swift +++ b/kplayer/AppDelegate.swift @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let splitViewController = self.window!.rootViewController as! UISplitViewController let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController @@ -118,7 +118,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) // Replace this with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - NSLog("Unresolved error \(error), \(error!.userInfo)") + NSLog("Unresolved error \(String(describing: error)), \(error!.userInfo)") abort() } catch { fatalError() @@ -133,7 +133,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele if coordinator == nil { return nil } - var managedObjectContext = NSManagedObjectContext() + var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.mainQueueConcurrencyType) managedObjectContext.persistentStoreCoordinator = coordinator return managedObjectContext }() @@ -142,15 +142,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele func saveContext () { if let moc = self.managedObjectContext { - var error: NSError? = nil if moc.hasChanges { do { try moc.save() - } catch let error1 as NSError { - error = error1 + } catch let error as NSError { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - NSLog("Unresolved error \(error), \(error!.userInfo)") + NSLog("Unresolved error \(error), \(error.userInfo)") abort() } } diff --git a/kplayer/core/MediaItem.swift b/kplayer/core/MediaItem.swift index 1fcdcaa..403c9bc 100644 --- a/kplayer/core/MediaItem.swift +++ b/kplayer/core/MediaItem.swift @@ -121,7 +121,7 @@ class MediaItem: CustomDebugStringConvertible { let len = "/srv/samba/ren".count let rootPostfix = (root as NSString).substring(from: len) let tpath = "/srv/samba/ren/thumb\(rootPostfix)/\(path)\(name)" - let enc = tpath.addingPercentEscapes(using: String.Encoding.isoLatin1)! + let enc = tpath.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! return enc + "/" } @@ -130,7 +130,7 @@ class MediaItem: CustomDebugStringConvertible { Absolute URL, unter der das Thumbnail des Items abgerufen werden kann. */ var thumbUrlAbsolute: String { - let enc = thumbUrl!.addingPercentEscapes(using: String.Encoding.isoLatin1)! + let enc = thumbUrl!.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! return NetworkManager.sharedInstance.baseurl + "/service/download" + enc } @@ -140,7 +140,7 @@ class MediaItem: CustomDebugStringConvertible { var imageUrlAbsolute: String { var imageUrl = thumbUrl!.replacingOccurrences(of: "_thumb.", with: ".") imageUrl = imageUrl.replacingOccurrences(of: "?preview=true", with: "") - imageUrl = imageUrl.addingPercentEscapes(using: String.Encoding.isoLatin1)! + imageUrl = imageUrl.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! return NetworkManager.sharedInstance.baseurl + "/service/download" + imageUrl } @@ -162,8 +162,8 @@ class MediaItem: CustomDebugStringConvertible { */ var fullPath: String { let fpath = "\(root)/\(path)/\(name)" - let enc = fpath.addingPercentEscapes(using: String.Encoding.isoLatin1) - return enc! + let enc = fpath.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! + return enc } var debugDescription: String { @@ -173,7 +173,7 @@ class MediaItem: CustomDebugStringConvertible { var encodedDir: String? { let dir = "\(root)/\(path)" - return dir.addingPercentEscapes(using: String.Encoding.isoLatin1) + return dir.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) } func superRoot() -> MediaItem { diff --git a/kplayer/core/NetworkManager.swift b/kplayer/core/NetworkManager.swift index db3a978..f1068b0 100644 --- a/kplayer/core/NetworkManager.swift +++ b/kplayer/core/NetworkManager.swift @@ -28,11 +28,11 @@ class NetworkManager { var root = rootParam if root.contains("*") { - root = rootParam[rootParam.startIndex.. Void)) + func setCompletionHandler(handler: @escaping (() -> Void)) } class AVPlayerController: UIViewController, ItemController { var player = KBMPlayer() var currentItem: MediaItem? - var completionHandler: ((Void) -> Void)? + var completionHandler: (() -> Void)? var buttons = Dictionary() @@ -51,11 +51,11 @@ class AVPlayerController: UIViewController, ItemController { navigationItem.rightBarButtonItems = [barbutton!] backButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(AVPlayerController.back(_:))) - speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItemStyle.plain, target: self, action: #selector(AVPlayerController.speed(_:))) - zoomButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItemStyle.plain, target: self, action: #selector(AVPlayerController.zoom(_:))) - aspectButton = UIBarButtonItem(title:"1", style:UIBarButtonItemStyle.plain, target: self, action: #selector(AVPlayerController.aspect(_:))) + speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(AVPlayerController.speed(_:))) + zoomButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(AVPlayerController.zoom(_:))) + aspectButton = UIBarButtonItem(title:"1", style:UIBarButtonItem.Style.plain, target: self, action: #selector(AVPlayerController.aspect(_:))) playButton = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(AVPlayerController.startstop(_:))) - reviewButton = UIBarButtonItem(title:"Edit ", style:UIBarButtonItemStyle.plain, target: self, action: #selector(AVPlayerController.doEdit(_:))) + reviewButton = UIBarButtonItem(title:"Edit ", style:UIBarButtonItem.Style.plain, target: self, action: #selector(AVPlayerController.doEdit(_:))) navigationItem.leftBarButtonItems = [backButton!, speedButton!, playButton!, zoomButton!, aspectButton!, reviewButton!] @@ -83,11 +83,11 @@ class AVPlayerController: UIViewController, ItemController { currentItem = item } - func setCompletionHandler(handler: @escaping ((Void) -> Void)) { + func setCompletionHandler(handler: @escaping (() -> Void)) { completionHandler = handler } - func doEdit(_ sender: AnyObject) { + @objc func doEdit(_ sender: AnyObject) { if (!allowEdit) { return } @@ -102,7 +102,7 @@ class AVPlayerController: UIViewController, ItemController { } } - func startstop(_ sender: AnyObject) { + @objc func startstop(_ sender: AnyObject) { if player.isPlaying { player.pause() } @@ -124,7 +124,7 @@ class AVPlayerController: UIViewController, ItemController { print("play") } - func zoom(_ sender: AnyObject) { + @objc func zoom(_ sender: AnyObject) { zoomOption += 1 if zoomOption >= zoomOptions.count { zoomOption = 0 @@ -138,7 +138,7 @@ print("play") print("zoom \(zoom)") } - func aspect(_ sender: AnyObject) { + @objc func aspect(_ sender: AnyObject) { aspect += 1 if aspect > 3 { aspect = 1 @@ -161,7 +161,7 @@ print("play") aspectButton!.title = "\(aspect)" } - func speed(_ sender: AnyObject) { + @objc func speed(_ sender: AnyObject) { speedOption += 1 if speedOption >= speedOptions.count { speedOption = 0 @@ -208,7 +208,7 @@ print("finish") if newItem.image != nil { let icon = newItem.image!.scaleToSize(66.0, height: 44.0) - button.setBackgroundImage(icon, for: UIControlState()); + button.setBackgroundImage(icon, for: UIControl.State()); } else { if newItem.thumbUrl != nil { let URL = Foundation.URL(string: newItem.thumbUrlAbsolute)! @@ -216,7 +216,7 @@ print("finish") Shared.imageCache.fetch(URL: URL).onSuccess { i in let icon = i.scaleToSize(66.0, height: 44.0) - button.setBackgroundImage(icon, for: UIControlState.normal); + button.setBackgroundImage(icon, for: UIControl.State.normal); } } } @@ -231,7 +231,7 @@ print("finish") buttons[button] = newItem } - func thumbnailClicked(_ source: UIButton) { + @objc func thumbnailClicked(_ source: UIButton) { player.seek(buttons[source]!.time!) // moviePlayer!.currentPlaybackRate = Float(speedOptions[speedOption]) @@ -239,7 +239,7 @@ print("finish") // print("goto \(buttons[source]!.time!) is \(moviePlayer!.currentPlaybackTime)") } - func update() { + @objc func update() { reviewButton!.title = currentItem!.name @@ -291,28 +291,28 @@ print("finish") moviePlayer.addGestureRecognizer(twoFingersTwoTapsGesture) let sR = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight)) - sR.direction = UISwipeGestureRecognizerDirection.right + sR.direction = UISwipeGestureRecognizer.Direction.right sR.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR) let sL = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft)) - sL.direction = UISwipeGestureRecognizerDirection.left + sL.direction = UISwipeGestureRecognizer.Direction.left sL.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sL) let sR2 = UISwipeGestureRecognizer(target: self, action: #selector(swipeDown)) - sR2.direction = UISwipeGestureRecognizerDirection.down + sR2.direction = UISwipeGestureRecognizer.Direction.down sR2.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR2) let sR3 = UISwipeGestureRecognizer(target: self, action: #selector(swipeUp)) - sR3.direction = UISwipeGestureRecognizerDirection.up + sR3.direction = UISwipeGestureRecognizer.Direction.up sR3.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR3) } - func swipeUp() { + @objc func swipeUp() { print("u") print("Type: \(currentItem!.type) Count: \(currentItem!.children.count) Index: \(index) Current: \(currentItem!.index)") @@ -349,7 +349,7 @@ print("finish") } - func swipeRight() { + @objc func swipeRight() { // print("r") // player.currentPlaybackRate = Float(0.0) // player.currentPlaybackTime = player.currentPlaybackTime - 30.0 @@ -362,7 +362,7 @@ print("finish") } - func swipeDown() { + @objc func swipeDown() { print("d") if !edit { var newIndex = currentItem!.index - 1 @@ -390,7 +390,7 @@ print("finish") } - func swipeLeft() { + @objc func swipeLeft() { print("l") // player.currentPlaybackRate = Float(0.0) // player.currentPlaybackTime = player.currentPlaybackTime + 30.0 @@ -408,7 +408,7 @@ print("finish") print("resumePlay") } - func captureThumbnail() { + @objc func captureThumbnail() { if edit { let asset = player.playerLayer!.playerItem!.asset @@ -441,7 +441,7 @@ print("finish") newItem.parent = currentItem! currentItem!.children.append(newItem) - print(newItem.time) + print(newItem.time!) addItemButton(newItem) } diff --git a/kplayer/detail/DetailViewController.swift b/kplayer/detail/DetailViewController.swift index 986a836..3e89f9c 100644 --- a/kplayer/detail/DetailViewController.swift +++ b/kplayer/detail/DetailViewController.swift @@ -57,11 +57,11 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout collectionView.delegate = self collectionView.register(ItemCell.self, forCellWithReuseIdentifier: "Cell") collectionView.backgroundColor = UIColor.lightGray - collectionView.register(HeaderCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "HeaderView"); + collectionView.register(HeaderCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "HeaderView"); view.addSubview(collectionView) view.autoresizesSubviews = true - collectionView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight] + collectionView.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight] // Do any additional setup after loading the view, typically from a nib. collectionView.reloadData() @@ -81,16 +81,16 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout } } - func vplayer() { + @objc func vplayer() { videoplayer = !videoplayer } - func favorites() { + @objc func favorites() { showFavoritesOnly = !showFavoritesOnly collectionView.reloadData() } - func overview() { + @objc func overview() { let pc = MediaPhotoController() var i = [MediaItem]() @@ -114,7 +114,7 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout } } - func refreshItems(_ notification: Notification) { + @objc func refreshItems(_ notification: Notification) { if notification.object == nil { if self.collectionView != nil { @@ -163,8 +163,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout } } - func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { - if (gestureRecognizer.state != UIGestureRecognizerState.ended) { + @objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if (gestureRecognizer.state != UIGestureRecognizer.State.ended) { return; } let p = gestureRecognizer.location(in: self.collectionView); @@ -243,7 +243,7 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { - case UICollectionElementKindSectionHeader: + case UICollectionView.elementKindSectionHeader: let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HeaderView", @@ -276,7 +276,7 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout showVideo() } else { - let len = items.root.characters.count + let len = items.root.count let url = NetworkManager.sharedInstance.baseurl + "/service/listfiles" + items.fullPath print(items) @@ -291,9 +291,9 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout for s in json as! [String] { if s.lowercased().hasSuffix(".jpg") { - let l = s.characters.count + let l = s.count let name = NSURL(fileURLWithPath: s).lastPathComponent! - var pathlen = l - len - name.characters.count + var pathlen = l - len - name.count // if (pathlen > 1000) { print(pathlen) @@ -307,8 +307,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegateFlowLayout let path = (s as NSString).substring(with: NSMakeRange(len + 1, pathlen - 2)) let folderName = NSURL(fileURLWithPath: path).lastPathComponent! - let fl = path.characters.count - let pfl = fl - folderName.characters.count + let fl = path.count + let pfl = fl - folderName.count print("\(folderName) \(pfl)") let fpath = s.substringLeft(pfl) diff --git a/kplayer/detail/ItemCell.swift b/kplayer/detail/ItemCell.swift index a87c35f..49d494f 100644 --- a/kplayer/detail/ItemCell.swift +++ b/kplayer/detail/ItemCell.swift @@ -23,7 +23,7 @@ class ItemCell: UICollectionViewCell { super.init(frame: frame) image = UIImageView(frame: frame) - image.contentMode = UIViewContentMode.scaleAspectFit + image.contentMode = UIView.ContentMode.scaleAspectFit autolayout(["imag": image], constraints: diff --git a/kplayer/detail/VideoPlayerController.swift b/kplayer/detail/VideoPlayerController.swift index 0e1df99..1bf5f03 100644 --- a/kplayer/detail/VideoPlayerController.swift +++ b/kplayer/detail/VideoPlayerController.swift @@ -32,7 +32,7 @@ class VideoPlayerController: UIViewController, ItemController { var allowEdit = true var index = 0 - func setCompletionHandler(handler: @escaping ((Void) -> Void)) { + func setCompletionHandler(handler: @escaping (() -> Void)) { completionHandler = handler } @@ -43,9 +43,9 @@ class VideoPlayerController: UIViewController, ItemController { navigationItem.rightBarButtonItems = [barbutton!] backButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(VideoPlayerController.back(_:))) - speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItemStyle.plain, target: self, action: #selector(VideoPlayerController.speed(_:))) + speedButton = UIBarButtonItem(title:"1.0", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoPlayerController.speed(_:))) playButton = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(VideoPlayerController.startstop(_:))) - reviewButton = UIBarButtonItem(title:"Edit ", style:UIBarButtonItemStyle.plain, target: self, action: #selector(VideoPlayerController.doEdit(_:))) + reviewButton = UIBarButtonItem(title:"Edit ", style:UIBarButtonItem.Style.plain, target: self, action: #selector(VideoPlayerController.doEdit(_:))) navigationItem.leftBarButtonItems = [backButton!, playButton!, speedButton!, reviewButton!] @@ -59,7 +59,7 @@ class VideoPlayerController: UIViewController, ItemController { currentItem = item } - func doEdit(_ sender: AnyObject) { + @objc func doEdit(_ sender: AnyObject) { if (!allowEdit) { return } @@ -74,7 +74,7 @@ class VideoPlayerController: UIViewController, ItemController { } } - func startstop(_ sender: AnyObject) { + @objc func startstop(_ sender: AnyObject) { if moviePlayer!.playbackState == MPMoviePlaybackState.playing { moviePlayer!.pause() } @@ -90,7 +90,7 @@ class VideoPlayerController: UIViewController, ItemController { print("play") } - func speed(_ sender: AnyObject) { + @objc func speed(_ sender: AnyObject) { speedOption += 1 if speedOption >= speedOptions.count { speedOption = 0 @@ -137,12 +137,12 @@ print("play") } } - func playerItemDidReachEnd(_ note: Notification) { + @objc func playerItemDidReachEnd(_ note: Notification) { print("finish") // Timer.scheduledTimer(timeInterval: 0.6, target: self, selector: #selector(update), userInfo: nil, repeats: false) } - func showThumbnail(_ note: Notification) { + @objc func showThumbnail(_ note: Notification) { let userInfo = note.userInfo! as NSDictionary let thumbnail = userInfo.object(forKey: MPMoviePlayerThumbnailImageKey) as! UIImage let time = userInfo.object(forKey: MPMoviePlayerThumbnailTimeKey) as! TimeInterval @@ -168,7 +168,7 @@ print("finish") if newItem.image != nil { let icon = newItem.image!.scaleToSize(66.0, height: 44.0) - button.setBackgroundImage(icon, for: UIControlState()); + button.setBackgroundImage(icon, for: UIControl.State()); } else { if newItem.thumbUrl != nil { let URL = Foundation.URL(string: newItem.thumbUrlAbsolute)! @@ -176,7 +176,7 @@ print("finish") Shared.imageCache.fetch(URL: URL).onSuccess { i in let icon = i.scaleToSize(66.0, height: 44.0) - button.setBackgroundImage(icon, for: UIControlState.normal); + button.setBackgroundImage(icon, for: UIControl.State.normal); } } } @@ -191,7 +191,7 @@ print("finish") buttons[button] = newItem } - func thumbnailClicked(_ source: UIButton) { + @objc func thumbnailClicked(_ source: UIButton) { moviePlayer!.currentPlaybackTime = buttons[source]!.time! moviePlayer!.currentPlaybackRate = Float(speedOptions[speedOption]) @@ -199,7 +199,7 @@ print("finish") print("goto \(buttons[source]!.time!) is \(moviePlayer!.currentPlaybackTime)") } - func update() { + @objc func update() { if let player = self.moviePlayer { // if !(player.duration > 0.0) { @@ -233,7 +233,7 @@ print("finish") } } - func enteredFullscreen() { + @objc func enteredFullscreen() { let mp = UIApplication.shared.keyWindow; if let moviePlayerContainer = mp!.recursiveSearchForViewWithName("MPVideoContainerView") { if (moviePlayerContainer.gestureRecognizers != nil) { @@ -243,7 +243,7 @@ print("finish") } } - func exitedFullscreen() { + @objc func exitedFullscreen() { moviePlayer!.view.removeFromSuperview(); moviePlayer = nil; NotificationCenter.default.removeObserver(self); @@ -257,28 +257,28 @@ print("finish") moviePlayer.addGestureRecognizer(twoFingersTwoTapsGesture) let sR = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight)) - sR.direction = UISwipeGestureRecognizerDirection.right + sR.direction = UISwipeGestureRecognizer.Direction.right sR.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR) let sL = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft)) - sL.direction = UISwipeGestureRecognizerDirection.left + sL.direction = UISwipeGestureRecognizer.Direction.left sL.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sL) let sR2 = UISwipeGestureRecognizer(target: self, action: #selector(swipeDown)) - sR2.direction = UISwipeGestureRecognizerDirection.down + sR2.direction = UISwipeGestureRecognizer.Direction.down sR2.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR2) let sR3 = UISwipeGestureRecognizer(target: self, action: #selector(swipeUp)) - sR3.direction = UISwipeGestureRecognizerDirection.up + sR3.direction = UISwipeGestureRecognizer.Direction.up sR3.numberOfTouchesRequired = 1 moviePlayer.addGestureRecognizer(sR3) } - func swipeUp() { + @objc func swipeUp() { print("u") if let player = self.moviePlayer { print("Type: \(currentItem!.type) Count: \(currentItem!.children.count) Index: \(index) Current: \(currentItem!.index)") @@ -317,7 +317,7 @@ print("finish") } } - func swipeRight() { + @objc func swipeRight() { print("r") if let player = self.moviePlayer { moviePlayer!.currentPlaybackRate = Float(0.0) @@ -331,7 +331,7 @@ print("finish") } } - func swipeDown() { + @objc func swipeDown() { print("d") if let player = self.moviePlayer { @@ -361,7 +361,7 @@ print("finish") } } - func swipeLeft() { + @objc func swipeLeft() { print("l") if let player = self.moviePlayer { moviePlayer!.currentPlaybackRate = Float(0.0) @@ -380,7 +380,7 @@ print("finish") print("resumePlay") } - func twoFingersTwoTaps() { + @objc func twoFingersTwoTaps() { if edit { thumbnailTime = moviePlayer!.currentPlaybackTime print("tap \(thumbnailTime)") diff --git a/kplayer/master/MasterViewController.swift b/kplayer/master/MasterViewController.swift index dc718b9..d1f9c21 100644 --- a/kplayer/master/MasterViewController.swift +++ b/kplayer/master/MasterViewController.swift @@ -44,7 +44,7 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { if str.hasSuffix("*") { let txt = str[str.startIndex ..< str.index(str.endIndex, offsetBy: -1)] if let p = model.items[0].parent { - let neu = MediaItem(name: txt, path: p.path + "*" + txt, root: p.root, type: ItemType.DETAILS) + let neu = MediaItem(name: String(txt), path: p.path + "*" + txt, root: p.root, type: ItemType.DETAILS) model.items.append(neu) neu.parent = p self.tableView.reloadData() @@ -281,7 +281,7 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { return false } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { } } @@ -294,7 +294,7 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { cell.textLabel!.text = object.path } - cell.accessoryType = UITableViewCellAccessoryType.none + cell.accessoryType = UITableViewCell.AccessoryType.none } } diff --git a/kplayer/photo/MediaPhotoController.swift b/kplayer/photo/MediaPhotoController.swift index baa460c..52055e8 100644 --- a/kplayer/photo/MediaPhotoController.swift +++ b/kplayer/photo/MediaPhotoController.swift @@ -150,7 +150,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView preview += "\(tu);" } - preview = preview.addingPercentEscapes(using: String.Encoding.isoLatin1)! + preview = preview.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! let u2 = "\(NetworkManager.sharedInstance.baseurl)/service/preload?preview=\(preview)" let u3 = URL(string: u2) @@ -182,7 +182,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView super.didReceiveMemoryWarning() } - func shot() { + @objc func shot() { let currentItem = items[photoAlbumView.centerPageIndex] var imageUrl = currentItem.thumbUrl!.replacingOccurrences(of: "_thumb.jpg", with: ".jpg") imageUrl = imageUrl.replacingOccurrences(of: "?preview=true", with: "") @@ -195,7 +195,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView } } - func back() { + @objc func back() { imageCache.removeAllObjects() operationQueue.cancelAllOperations() @@ -206,7 +206,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView completionHandler!() } - func slideShow() { + @objc func slideShow() { slide += 1 if (slide > 2) { slide = 0 @@ -217,7 +217,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView } } - func showItem() { + @objc func showItem() { var nextItem = photoAlbumView.centerPageIndex + 1 if (nextItem >= (items).count) { @@ -234,7 +234,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView } } - func play() { + @objc func play() { let currentItem = items[photoAlbumView.centerPageIndex] if (currentItem.type == ItemType.PICS) { @@ -429,7 +429,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView * You should always try to reuse pages by calling dequeueReusablePageWithIdentifier: on the * paging scroll view before allocating a new page. */ - func pagingScrollView(_ pagingScrollView: NIPagingScrollView, pageViewFor pageViewForIndex: Int) -> UIView { + func pagingScrollView(_ pagingScrollView: NIPagingScrollView, pageViewFor pageViewForIndex: Int) -> (UIView & NIPagingScrollViewPageProtocol)! { let view = photoAlbumView.pagingScrollView(pagingScrollView, pageViewFor: pageViewForIndex) as! NIPhotoScrollView view.maximumScale = 3; diff --git a/kplayer/util/LayoutTools.swift b/kplayer/util/LayoutTools.swift index 6a3a00f..a6f1d03 100644 --- a/kplayer/util/LayoutTools.swift +++ b/kplayer/util/LayoutTools.swift @@ -27,13 +27,13 @@ public extension UIView { if index + 1 < constraints.count && !(constraints[index + 1] is String) { index += 1 let constr: NSArray = NSLayoutConstraint.constraints(withVisualFormat: c as! String, - options: constraints[index] as! NSLayoutFormatOptions, + options: constraints[index] as! NSLayoutConstraint.FormatOptions, metrics: nil, views: views) as NSArray addConstraints(constr as! [NSLayoutConstraint]) } else { let constr: NSArray = NSLayoutConstraint.constraints(withVisualFormat: c as! String, - options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views) as NSArray + options: NSLayoutConstraint.FormatOptions(rawValue: 0), metrics: nil, views: views) as NSArray addConstraints(constr as! [NSLayoutConstraint]) } } diff --git a/kplayer/util/NetData.swift b/kplayer/util/NetData.swift index a2c4857..4d87c32 100644 --- a/kplayer/util/NetData.swift +++ b/kplayer/util/NetData.swift @@ -42,12 +42,12 @@ class NetData self.filename = filename } init(pngImage: UIImage, filename: String) { - data = UIImagePNGRepresentation(pngImage)! + data = pngImage.pngData()! self.mimeType = MimeType.ImagePng self.filename = filename } init(jpegImage: UIImage, compressionQuanlity: CGFloat, filename: String) { - data = UIImageJPEGRepresentation(jpegImage, compressionQuanlity)! + data = jpegImage.jpegData(compressionQuality: compressionQuanlity)! self.mimeType = MimeType.ImageJpeg self.filename = filename } diff --git a/kplayer/util/ViewControllerExtensions.swift b/kplayer/util/ViewControllerExtensions.swift index fef54b0..431dfe8 100644 --- a/kplayer/util/ViewControllerExtensions.swift +++ b/kplayer/util/ViewControllerExtensions.swift @@ -30,7 +30,7 @@ public extension UIViewController { } func findChildController(_ my: T.Type) -> T? { - for child in childViewControllers { + for child in children { if let result = child as? T { // (XXX) return result @@ -59,7 +59,7 @@ public extension UIViewController { func embedChildViewController(_ vc: UIViewController, inView: UIView) { vc.view.frame = inView.bounds; - addChildViewController(vc); + addChild(vc); inView.removeAllSubViews(); inView.addSubview(vc.view); }