|
| 1 | +// |
| 2 | +// EditProfileTableViewController.swift |
| 3 | +// Cluster |
| 4 | +// |
| 5 | +// Created by lsecrease on 10/14/15. |
| 6 | +// Copyright (c) 2015 ImagineME. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import UIKit |
| 10 | +import Photos |
| 11 | + |
| 12 | +class EditProfileTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { |
| 13 | + |
| 14 | + @IBOutlet weak var coverImage: UIImageView! |
| 15 | + @IBOutlet weak var profileImage: UIImageView! |
| 16 | + @IBOutlet weak var profileImageOverlay: UIVisualEffectView! |
| 17 | + @IBOutlet weak var aboutMeTextView: UITextView! |
| 18 | + |
| 19 | + private var profilePic: UIImage! |
| 20 | + private var coverPic: UIImage! |
| 21 | + |
| 22 | + let numberOfRowsAtSection: [Int] = [4, 2] |
| 23 | + |
| 24 | + //MARK: - Change Status Bar to White |
| 25 | + override func preferredStatusBarStyle() -> UIStatusBarStyle { |
| 26 | + return .LightContent |
| 27 | + } |
| 28 | + |
| 29 | + override func viewDidLoad() { |
| 30 | + super.viewDidLoad() |
| 31 | + |
| 32 | + profileImage.layer.cornerRadius = profileImage.bounds.width / 2 |
| 33 | + profileImage.layer.masksToBounds = true |
| 34 | + |
| 35 | + profileImageOverlay.layer.cornerRadius = profileImageOverlay.bounds.width / 2 |
| 36 | + profileImageOverlay.layer.masksToBounds = true |
| 37 | + |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + // MARK: - Table view data source |
| 44 | + |
| 45 | + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { |
| 46 | + // #warning Potentially incomplete method implementation. |
| 47 | + // Return the number of sections. |
| 48 | + return 2 |
| 49 | + } |
| 50 | + |
| 51 | + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| 52 | + var rows: Int = 0 |
| 53 | + |
| 54 | + if section < numberOfRowsAtSection.count { |
| 55 | + rows = numberOfRowsAtSection[section] |
| 56 | + } |
| 57 | + |
| 58 | + return rows |
| 59 | + |
| 60 | + } |
| 61 | + |
| 62 | + @IBAction func profileImageChange(sender: DesignableButton) { |
| 63 | + |
| 64 | + let authorization = PHPhotoLibrary.authorizationStatus() |
| 65 | + |
| 66 | + if authorization == .NotDetermined { |
| 67 | + PHPhotoLibrary.requestAuthorization({ (status) -> Void in |
| 68 | + //self.pickFeaturedImageClicked(sender) |
| 69 | + dispatch_async(dispatch_get_main_queue(), { () -> Void in |
| 70 | + self.profileImageChange(sender) |
| 71 | + }) |
| 72 | + }) |
| 73 | + return |
| 74 | + } |
| 75 | + //Do you want to Take a Photo or Video with the Camera |
| 76 | + if authorization == .Authorized { |
| 77 | + let controller = ImagePickerSheetController() |
| 78 | + controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in |
| 79 | + |
| 80 | + self.presentCamera() |
| 81 | + |
| 82 | + }, secondaryHandler: { (action, numberOfPhotos) -> () in |
| 83 | + controller.getSelectedImagesWithCompletion({ (images) -> Void in |
| 84 | + self.profilePic = images[0] |
| 85 | + self.profileImage.image = self.profilePic |
| 86 | + }) |
| 87 | + })) |
| 88 | + |
| 89 | + controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel)) |
| 90 | + |
| 91 | + presentViewController(controller, animated: true, completion: nil) |
| 92 | + |
| 93 | + } |
| 94 | + } |
| 95 | + @IBAction func coverImageChange(sender: DesignableButton) { |
| 96 | + |
| 97 | + let authorization = PHPhotoLibrary.authorizationStatus() |
| 98 | + |
| 99 | + if authorization == .NotDetermined { |
| 100 | + PHPhotoLibrary.requestAuthorization({ (status) -> Void in |
| 101 | + //self.pickFeaturedImageClicked(sender) |
| 102 | + dispatch_async(dispatch_get_main_queue(), { () -> Void in |
| 103 | + self.profileImageChange(sender) |
| 104 | + }) |
| 105 | + }) |
| 106 | + return |
| 107 | + } |
| 108 | + //Do you want to Take a Photo or Video with the Camera |
| 109 | + if authorization == .Authorized { |
| 110 | + let controller = ImagePickerSheetController() |
| 111 | + controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in |
| 112 | + |
| 113 | + self.presentCamera() |
| 114 | + |
| 115 | + }, secondaryHandler: { (action, numberOfPhotos) -> () in |
| 116 | + controller.getSelectedImagesWithCompletion({ (images) -> Void in |
| 117 | + self.coverPic = images[0] |
| 118 | + self.coverImage.image = self.coverPic |
| 119 | + }) |
| 120 | + })) |
| 121 | + |
| 122 | + controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel)) |
| 123 | + |
| 124 | + presentViewController(controller, animated: true, completion: nil) |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + } |
| 129 | + |
| 130 | + func presentCamera() { |
| 131 | + let imagePicker = UIImagePickerController() |
| 132 | + imagePicker.allowsEditing = false |
| 133 | + imagePicker.delegate = self |
| 134 | + imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary |
| 135 | + self.presentViewController(imagePicker, animated: true, completion: nil) |
| 136 | + } |
| 137 | + |
| 138 | + @IBAction func deleteAccountButtonTapped(sender: DesignableButton) { |
| 139 | + |
| 140 | + println("Delete Account Button Tapped") |
| 141 | + } |
| 142 | + |
| 143 | +} |
0 commit comments