diff --git a/AmahiAnywhere/AmahiAnywhere.xcodeproj/project.pbxproj b/AmahiAnywhere/AmahiAnywhere.xcodeproj/project.pbxproj index 0097eb7938f..c93b59da7ef 100644 --- a/AmahiAnywhere/AmahiAnywhere.xcodeproj/project.pbxproj +++ b/AmahiAnywhere/AmahiAnywhere.xcodeproj/project.pbxproj @@ -80,11 +80,13 @@ 727A95E024D2DA350057C27C /* UIImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 727A95DF24D2DA350057C27C /* UIImageExtension.swift */; }; 72BDA8B524A9ED6900B4469E /* QueueItemTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72BDA8B324A9ED6900B4469E /* QueueItemTableViewCell.swift */; }; 72BDA8B624A9ED6900B4469E /* QueueItemTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 72BDA8B424A9ED6900B4469E /* QueueItemTableViewCell.xib */; }; + 72BDA8B824AAA61700B4469E /* TimeStamp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72BDA8B724AAA61700B4469E /* TimeStamp.swift */; }; 72DAFE1C24B6276A00755E25 /* AudioPlayerDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72DAFE1B24B6276A00755E25 /* AudioPlayerDataModel.swift */; }; 80F3FDC7206C0D4D0061CD51 /* ConnectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80F3FDC6206C0D4D0061CD51 /* ConnectionViewController.swift */; }; 80F60700206BE1530098BC60 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80F606FF206BE1530098BC60 /* SettingsViewController.swift */; }; 8A0A88F8227CE39C00A1360C /* MimeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4612851D2051DB770061EC21 /* MimeType.swift */; }; 8A67FC2B22666F81005A5038 /* OfflineFile+MimeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A67FC2A22666F81005A5038 /* OfflineFile+MimeType.swift */; }; + 991F5521231217AC00EFA0DF /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 991F5520231217AC00EFA0DF /* CloudKit.framework */; }; 9935DAAC2301EB2F004816E1 /* RecentsPersistenceService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9935DAAB2301EB2F004816E1 /* RecentsPersistenceService.swift */; }; 9935DAB02301ED86004816E1 /* RecentFile+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9935DAAE2301ED86004816E1 /* RecentFile+CoreDataClass.swift */; }; 9935DAB22301EE24004816E1 /* RecentsDatabaseHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9935DAB12301EE24004816E1 /* RecentsDatabaseHelper.swift */; }; @@ -225,11 +227,13 @@ 727A95DF24D2DA350057C27C /* UIImageExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = ""; }; 72BDA8B324A9ED6900B4469E /* QueueItemTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueItemTableViewCell.swift; sourceTree = ""; }; 72BDA8B424A9ED6900B4469E /* QueueItemTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = QueueItemTableViewCell.xib; sourceTree = ""; }; + 72BDA8B724AAA61700B4469E /* TimeStamp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeStamp.swift; sourceTree = ""; }; 72DAFE1B24B6276A00755E25 /* AudioPlayerDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerDataModel.swift; sourceTree = ""; }; 80F3FDC6206C0D4D0061CD51 /* ConnectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionViewController.swift; sourceTree = ""; }; 80F606FF206BE1530098BC60 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 8A67FC2A22666F81005A5038 /* OfflineFile+MimeType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OfflineFile+MimeType.swift"; sourceTree = ""; }; 9913634D22D5D2F100B48586 /* AmahiAnywhere.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AmahiAnywhere.entitlements; sourceTree = ""; }; + 991F5520231217AC00EFA0DF /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; 9935DAAB2301EB2F004816E1 /* RecentsPersistenceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentsPersistenceService.swift; sourceTree = ""; }; 9935DAAE2301ED86004816E1 /* RecentFile+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RecentFile+CoreDataClass.swift"; sourceTree = ""; }; 9935DAB12301EE24004816E1 /* RecentsDatabaseHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentsDatabaseHelper.swift; sourceTree = ""; }; @@ -304,6 +308,7 @@ buildActionMask = 2147483647; files = ( 07A3AB2E5DFE0D2AD44B0F33 /* Pods_AmahiAnywhere.framework in Frameworks */, + 991F5521231217AC00EFA0DF /* CloudKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -411,6 +416,7 @@ C446600BA8E0E01249C2486F /* Frameworks */ = { isa = PBXGroup; children = ( + 991F5520231217AC00EFA0DF /* CloudKit.framework */, F5293AC0952F87B50DCD644D /* Pods_AmahiAnywhere.framework */, ); name = Frameworks; @@ -440,6 +446,7 @@ ADAFF8DB2250209700287409 /* AudioThumbnailGenerator.swift */, 9938343C22CBAAA2002A8213 /* Toast.swift */, 3B37EBAE22ED11650065CB77 /* Units.swift */, + 72BDA8B724AAA61700B4469E /* TimeStamp.swift */, 9935DAB32301FA21004816E1 /* RecentFiles.swift */, 727A95DF24D2DA350057C27C /* UIImageExtension.swift */, ); @@ -885,6 +892,7 @@ C86CA92920D3D26300C8EDCA /* OfflineFile+CoreData.swift in Sources */, 3B33325A22BAA40B00BC61EB /* FilesViewController+UICollectionViewDelegates.swift in Sources */, 4605964D204F3666004FA066 /* ServerShare.swift in Sources */, + 72BDA8B824AAA61700B4469E /* TimeStamp.swift in Sources */, 72BDA8B524A9ED6900B4469E /* QueueItemTableViewCell.swift in Sources */, 3BCAFBAF22C6DC1A0044057E /* OfflineFilesViewController+Sorting.swift in Sources */, AD8F2FE0226E9351009C8C4B /* SettingsViewController+TableViewDataSource.swift in Sources */, diff --git a/AmahiAnywhere/AmahiAnywhere/AmahiAnywhere.entitlements b/AmahiAnywhere/AmahiAnywhere/AmahiAnywhere.entitlements index ba21fbdaf29..1c19977c9fd 100644 --- a/AmahiAnywhere/AmahiAnywhere/AmahiAnywhere.entitlements +++ b/AmahiAnywhere/AmahiAnywhere/AmahiAnywhere.entitlements @@ -2,7 +2,19 @@ + com.apple.developer.icloud-container-identifiers + + com.apple.developer.icloud-services + + CloudDocuments + com.apple.developer.networking.wifi-info + com.apple.developer.ubiquity-container-identifiers + + com.apple.developer.ubiquity-kvstore-identifier + $(TeamIdentifierPrefix)$(CFBundleIdentifier) + keychain-access-groups + diff --git a/AmahiAnywhere/AmahiAnywhere/AppDelegate.swift b/AmahiAnywhere/AmahiAnywhere/AppDelegate.swift index a75dc747d48..6deb53fcf31 100644 --- a/AmahiAnywhere/AmahiAnywhere/AppDelegate.swift +++ b/AmahiAnywhere/AmahiAnywhere/AppDelegate.swift @@ -66,7 +66,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { populateRegistrationDomain() - useCastContainerViewController = false NotificationCenter.default.addObserver(self, selector: #selector(syncWithUserDefaults), diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyButton.colorset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyButton.colorset/Contents.json new file mode 100644 index 00000000000..76b961cc86c --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyButton.colorset/Contents.json @@ -0,0 +1,56 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.000", + "green" : "0.000", + "red" : "0.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyCross.colorset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyCross.colorset/Contents.json new file mode 100644 index 00000000000..e7cb87c1236 --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/FloatyCross.colorset/Contents.json @@ -0,0 +1,56 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.000", + "green" : "0.000", + "red" : "0.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.000", + "green" : "0.000", + "red" : "0.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/Contents.json new file mode 100644 index 00000000000..c6c7b4772c5 --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/Contents.json @@ -0,0 +1,39 @@ +{ + "images" : [ + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "1x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "2x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "filename" : "image.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/image.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/image.png new file mode 100644 index 00000000000..759bf1e745d Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/Image-1.imageset/image.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/Contents.json index 56c8f03f4d5..69cfbd01d80 100644 --- a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/Contents.json +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/Contents.json @@ -49,7 +49,7 @@ "scale" : "2x" }, { - "filename" : "camera-1.png", + "filename" : "image-1.png", "idiom" : "universal", "scale" : "3x" }, diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/camera-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/camera-1.png deleted file mode 100644 index d9c8e3cca03..00000000000 Binary files a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/camera-1.png and /dev/null differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/image-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/image-1.png new file mode 100644 index 00000000000..759bf1e745d Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/camera.imageset/image-1.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/Contents.json new file mode 100644 index 00000000000..28b685052a4 --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/Contents.json @@ -0,0 +1,83 @@ +{ + "images" : [ + { + "filename" : "document_light-1.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "filename" : "document_light.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "filename" : "document-1.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "2x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "3x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document-1.png new file mode 100644 index 00000000000..a0d1a28908f Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document-1.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light-1.png new file mode 100644 index 00000000000..0ae1b1f5863 Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light-1.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light.png new file mode 100644 index 00000000000..0ae1b1f5863 Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/document.imageset/document_light.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/Contents.json b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/Contents.json new file mode 100644 index 00000000000..82e62dbee74 --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/Contents.json @@ -0,0 +1,83 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "1x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "idiom" : "universal", + "scale" : "2x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "imageedit_7_7116068300-1.png", + "idiom" : "universal", + "scale" : "3x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "light" + } + ], + "filename" : "imageedit_7_7116068300.png", + "idiom" : "universal", + "scale" : "3x" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "filename" : "video-1.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300-1.png new file mode 100644 index 00000000000..d8a62f9277f Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300-1.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300.png new file mode 100644 index 00000000000..d8a62f9277f Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/imageedit_7_7116068300.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/video-1.png b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/video-1.png new file mode 100644 index 00000000000..e19159939c8 Binary files /dev/null and b/AmahiAnywhere/AmahiAnywhere/Assets.xcassets/videoFloaty.imageset/video-1.png differ diff --git a/AmahiAnywhere/AmahiAnywhere/Base/BaseUIViewController.swift b/AmahiAnywhere/AmahiAnywhere/Base/BaseUIViewController.swift index 360e3acd30e..1dacf0bea15 100644 --- a/AmahiAnywhere/AmahiAnywhere/Base/BaseUIViewController.swift +++ b/AmahiAnywhere/AmahiAnywhere/Base/BaseUIViewController.swift @@ -93,7 +93,7 @@ class BaseUIViewController: UIViewController, GCKSessionManagerListener, GCKRequ } @objc func deviceOrientationDidChange(_: Notification) { - // TBD + print("Orientation changed") } override func viewWillAppear(_ animated: Bool) { diff --git a/AmahiAnywhere/AmahiAnywhere/Data/Remote/ApiCalls/ServerApi.swift b/AmahiAnywhere/AmahiAnywhere/Data/Remote/ApiCalls/ServerApi.swift index 772eb05b5de..5789ba52cbf 100644 --- a/AmahiAnywhere/AmahiAnywhere/Data/Remote/ApiCalls/ServerApi.swift +++ b/AmahiAnywhere/AmahiAnywhere/Data/Remote/ApiCalls/ServerApi.swift @@ -211,4 +211,22 @@ class ServerApi { return components.url } + + public func getShareUri(_ share: ServerShare) -> URL? { + var components = URLComponents(string: serverAddress!)! + components.path = "/files" + + components.queryItems = [ + URLQueryItem(name: "s", value: share.name), + URLQueryItem(name: "session", value: server.session_token) + ] + + if let authToken = auth_token{ + components.queryItems?.append(URLQueryItem(name: "auth", value: authToken)) + } + components.percentEncodedQuery = components.percentEncodedQuery? + .replacingOccurrences(of: "+", with: "%2B") + + return components.url + } } diff --git a/AmahiAnywhere/AmahiAnywhere/Info.plist b/AmahiAnywhere/AmahiAnywhere/Info.plist index e1f3cb1f7c5..73e54909360 100644 --- a/AmahiAnywhere/AmahiAnywhere/Info.plist +++ b/AmahiAnywhere/AmahiAnywhere/Info.plist @@ -27,12 +27,14 @@ NSAllowsArbitraryLoads + NSBluetoothAlwaysUsageDescription + Allow access to Bluetooth to use accesories for audio play NSCameraUsageDescription - Allow access to your camera to take photos and store them in the app or your Amahi server + Please allow access to your camera to take pictures for your HDA server + NSMicrophoneUsageDescription + Please allow access to your microphone to record a video for upload NSPhotoLibraryAddUsageDescription Allow access to your photo library to select photos for upload - NSBluetoothAlwaysUsageDescription - Allow access to Bluetooth to use accesories for audio play UIBackgroundModes audio diff --git a/AmahiAnywhere/AmahiAnywhere/Presentation/Files/FilesViewController.swift b/AmahiAnywhere/AmahiAnywhere/Presentation/Files/FilesViewController.swift index bc0362fc74f..124984b5b37 100644 --- a/AmahiAnywhere/AmahiAnywhere/Presentation/Files/FilesViewController.swift +++ b/AmahiAnywhere/AmahiAnywhere/Presentation/Files/FilesViewController.swift @@ -12,6 +12,7 @@ import AVFoundation import Alamofire import GoogleCast import Floaty +import MobileCoreServices class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { @@ -32,6 +33,9 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { print("setMediaInfo: \(String(describing: mediaInfo))") } } + + //fileTypeNumber: Image = 0, Video = 1, Document = 2 + var fileTypeNumber = 0 var currentDownloadRequest:DownloadRequest? public var sessionManager: GCKSessionManager! public var mediaInformation: GCKMediaInformation? @@ -92,6 +96,9 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { let interactor = Interactor() + let documentUploadTypes = [kUTTypePDF as String, kUTTypeText as String, kUTTypeImage as String] + var documentPicker: UIDocumentPickerViewController! + override func viewDidLoad() { super.viewDidLoad() setupNotifications() @@ -128,11 +135,33 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { imagePicker.delegate = self } + func setupDocumentPicker(){ + documentPicker = UIDocumentPickerViewController(documentTypes: documentUploadTypes, in: .import) + documentPicker.delegate = self + documentPicker.allowsMultipleSelection = false + if UIDevice().userInterfaceIdiom == .phone{ + documentPicker.modalPresentationStyle = .formSheet + } + } + func setupFloaty(){ - floaty.addItem("Upload an image", icon: UIImage(named: "camera")) { (item) in - self.uploadImageTapped() + self.uploadImageVideoTapped(isTypePhoto: true) } + + floaty.addItem("Upload a video", icon: UIImage(named: "videoFloaty")) { (item) in + self.uploadImageVideoTapped(isTypePhoto: false) + } + + floaty.addItem("Upload a document", icon: UIImage(named: "document")) { (item) in + self.uploadDocumentTapped() + } + + } + + @objc func uploadDocumentTapped(){ + self.present(documentPicker, animated: true, completion: nil) + self.fileTypeNumber = 2 } @objc func unreachableHDA(){ @@ -155,7 +184,11 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { self.present(alertVC, animated: true, completion: nil) } - func uploadImageTapped(){ + func uploadImageVideoTapped(isTypePhoto: Bool){ + imagePicker.mediaTypes = isTypePhoto ? [kUTTypeImage as String] : [kUTTypeMovie as String] + self.fileTypeNumber = isTypePhoto ? 0 : 1 + let libraryTitle = isTypePhoto ? "Photo Library" : "Video Library" + let alertVC = UIAlertController(title: "Select your source", message: nil, preferredStyle: .actionSheet) alertVC.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (_) in @@ -163,13 +196,14 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { self.present(self.imagePicker, animated: true, completion: nil) })) - alertVC.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: { (_) in + alertVC.addAction(UIAlertAction(title: libraryTitle, style: .default, handler: { (_) in self.imagePicker.sourceType = .photoLibrary self.present(self.imagePicker, animated: true, completion: nil) })) alertVC.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) - + alertVC.popoverPresentationController?.sourceView = floaty.subviews.first + alertVC.popoverPresentationController?.sourceRect = floaty.subviews.first?.frame ?? floaty.frame self.present(alertVC, animated: true, completion: nil) } @@ -238,6 +272,10 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener { if imagePicker == nil{ setupImagePicker() } + + if documentPicker == nil{ + setupDocumentPicker() + } } func setupNotifications(){ @@ -607,8 +645,90 @@ extension FilesViewController: UINavigationControllerDelegate, UIImagePickerCont func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { picker.dismiss(animated: true, completion: nil) - guard let _ = info[.editedImage] as? UIImage else { - return + let mediaType = info[UIImagePickerController.InfoKey.mediaType] as! CFString + var fileName: String = "" + var mimeType: String = "" + + var url: String = "" + if directory != nil { + url = ServerApi.shared!.getFileUri(directory!)!.absoluteString + } + else { + url = ServerApi.shared!.getShareUri(share)!.absoluteString + } + + let assetPath = info[UIImagePickerController.InfoKey.referenceURL] as? NSURL + + if assetPath != nil { + let ext = assetPath!.absoluteString?.components(separatedBy: "ext=")[1].lowercased() + if ext == "png" || ext == "jpg" || ext == "heic" { + mimeType = "image/jpeg" + } + else { + if ext == "mp4" { + mimeType = "video/mp4" + } + else if ext == "mov" { + mimeType = "video/quicktime" + } + else if ext == "flv" { + mimeType = "video/x-flv" + } + else if ext == "avi" { + mimeType = "video/x-msvideo" + } + } + } + else { + if self.fileTypeNumber == 0 { + mimeType = "image/jpeg" + } + else { + mimeType = "video/quicktime" + } + } + + switch mediaType { + case kUTTypeImage: + guard let image = info[.editedImage] as? UIImage else { + return + } + fileName = "IMG-" + TimeStamp().getCurrentTimeStamp() + ".jpeg" + let data: Data = image.jpegData(compressionQuality: 100)! + Network.shared.uploadFile(url, data: data, fileName: fileName, mime: mimeType) { success in + if success { + self.showStatusAlert(title: "Image was successfully uploaded", true) + } + else { + self.showStatusAlert(title: "An error occured while uploading the image", true) + } + self.presenter.getFiles(self.share, directory: self.directory) + } + + break + case kUTTypeMovie: + guard let videoURL = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL else { + return + } + do { + let data = try Data(contentsOf: videoURL as URL, options: .mappedIfSafe) + AmahiLogger.log(data) + fileName = "VIDEO-" + TimeStamp().getCurrentTimeStamp() + ".mp4" + Network.shared.uploadFile(url, data: data, fileName: fileName, mime: mimeType) { success in + if success { + self.showStatusAlert(title: "Video was successfully uploaded", true) + } + else { + self.showStatusAlert(title: "An error occured while uploading the video", true) + } + self.presenter.getFiles(self.share, directory: self.directory) + } + } catch { + AmahiLogger.log(error.localizedDescription) + } + break + default: + break } } } @@ -622,3 +742,34 @@ extension FilesViewController: UIViewControllerTransitioningDelegate { return interactor.hasStarted ? interactor : nil } } + +extension FilesViewController: UIDocumentPickerDelegate{ + func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { + guard let myURL = urls.first else { + return + } + var url: String = "" + if directory != nil { + url = ServerApi.shared!.getFileUri(directory!)!.absoluteString + } + else { + url = ServerApi.shared!.getShareUri(share)!.absoluteString + } + + let fileName = myURL.lastPathComponent + let mimeType = "application/\(myURL.lastPathComponent.components(separatedBy: ".")[1])" + + do { + let data = try Data(contentsOf: myURL as URL, options: .mappedIfSafe) + Network.shared.uploadFile(url, data: data, fileName: fileName, mime: mimeType) { success in + if success { + self.showStatusAlert(title: "Document was successfully uploaded", true) + } + else { + self.showStatusAlert(title: "An error occured while uploading the document", true) + } + self.presenter.getFiles(self.share, directory: self.directory) + } + } catch { return } + } +} diff --git a/AmahiAnywhere/AmahiAnywhere/StoryBoards/Base.lproj/Main.storyboard b/AmahiAnywhere/AmahiAnywhere/StoryBoards/Base.lproj/Main.storyboard index fa9a410a737..b6e1c19467c 100644 --- a/AmahiAnywhere/AmahiAnywhere/StoryBoards/Base.lproj/Main.storyboard +++ b/AmahiAnywhere/AmahiAnywhere/StoryBoards/Base.lproj/Main.storyboard @@ -845,8 +845,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -922,69 +985,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1047,19 +1047,19 @@ - + - + - + - + @@ -1822,6 +1822,12 @@ + + + + + + diff --git a/AmahiAnywhere/AmahiAnywhere/Utils/Network.swift b/AmahiAnywhere/AmahiAnywhere/Utils/Network.swift index 244c62d2675..039119c4ad3 100644 --- a/AmahiAnywhere/AmahiAnywhere/Utils/Network.swift +++ b/AmahiAnywhere/AmahiAnywhere/Utils/Network.swift @@ -145,6 +145,30 @@ public class Network { } } + public func uploadFile(_ url: String!, data: Data, fileName: String!, mime: String!, parameters: Parameters = [:], headers: HTTPHeaders = [:], completion: @escaping (_ isSuccessful: Bool ) -> Void) { + Alamofire.upload(multipartFormData: { multipartFormData in + for (key,value) in parameters { + multipartFormData.append((value as! String).data(using: .utf8)!, withName: key) + } + multipartFormData.append(data, withName: "file", fileName: fileName,mimeType: mime) + }, + usingThreshold: UInt64.init(), + to: url, + method: .post, + encodingCompletion: { encodingResult in + switch encodingResult { + case .success(let upload, _, _): + upload.response { response in + AmahiLogger.log(response) + completion(true) + } + case .failure(let encodingError): + AmahiLogger.log(encodingError.localizedDescription) + completion(false) + } + }) + } + func downloadRecentFileToStorage(recentFile: Recent, progressCompletion: @escaping (_ percent: Float) -> Void, completion: @escaping (_ isSuccessful: Bool ) -> Void) -> DownloadRequest?{ diff --git a/AmahiAnywhere/AmahiAnywhere/Utils/TimeStamp.swift b/AmahiAnywhere/AmahiAnywhere/Utils/TimeStamp.swift new file mode 100644 index 00000000000..072768411e0 --- /dev/null +++ b/AmahiAnywhere/AmahiAnywhere/Utils/TimeStamp.swift @@ -0,0 +1,18 @@ +// +// TimeStamp.swift +// AmahiAnywhere +// +// Created by Shresth Pratap Singh on 30/06/20. +// Copyright © 2020 Amahi. All rights reserved. +// + +import Foundation + +class TimeStamp { + + func getCurrentTimeStamp() -> String { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" + return formatter.string(from: Date()) + } +}