Skip to content

Commit

Permalink
Merge pull request #239 from Marton-Zeisler/UploadUI
Browse files Browse the repository at this point in the history
Upload UI for videos and documents
  • Loading branch information
csoni111 committed Aug 24, 2019
2 parents caec692 + 0c472e5 commit 57e5084
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "document.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "video.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</dict>
<key>NSCameraUsageDescription</key>
<string>Please allow access to your camera to take pictures for your HDA server</string>
<key>NSMicrophoneUsageDescription</key>
<string>Please allow access to your microphone to record a video for upload</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Please allow access to your photo library to select photos for upload</string>
<key>UIBackgroundModes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Lightbox
import AVFoundation
import GoogleCast
import Floaty
import MobileCoreServices

class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {

Expand Down Expand Up @@ -90,6 +91,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()
Expand All @@ -111,11 +115,30 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
imagePicker.delegate = self
}

func setupDocumentPicker(){
documentPicker = UIDocumentPickerViewController(documentTypes: documentUploadTypes, in: .import)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
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)
}

@objc func expiredAuthTokenHDA(){
Expand All @@ -129,15 +152,18 @@ 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]
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
self.imagePicker.sourceType = .camera
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)
}))
Expand Down Expand Up @@ -204,6 +230,10 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
if imagePicker == nil{
setupImagePicker()
}

if documentPicker == nil{
setupDocumentPicker()
}
}

func setupNotifications(){
Expand Down Expand Up @@ -556,3 +586,14 @@ 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
}

print("selected document url : \(myURL)")
}

}

0 comments on commit 57e5084

Please sign in to comment.