diff --git a/Bruin Bite/Storyboards/Dont Eat Alone/Base.lproj/Profile.storyboard b/Bruin Bite/Storyboards/Dont Eat Alone/Base.lproj/Profile.storyboard
index c455467..6b4e0a5 100644
--- a/Bruin Bite/Storyboards/Dont Eat Alone/Base.lproj/Profile.storyboard
+++ b/Bruin Bite/Storyboards/Dont Eat Alone/Base.lproj/Profile.storyboard
@@ -113,6 +113,9 @@
+
+
+
@@ -368,10 +374,206 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Bruin Bite/View Controllers/EditProfileViewController.swift b/Bruin Bite/View Controllers/EditProfileViewController.swift
index da962fb..779cc8d 100644
--- a/Bruin Bite/View Controllers/EditProfileViewController.swift
+++ b/Bruin Bite/View Controllers/EditProfileViewController.swift
@@ -5,7 +5,7 @@
import UIKit
-class EditProfileViewController: UIViewController, UITextViewDelegate {
+class EditProfileViewController: UIViewController, UITextViewDelegate, ProfilePictureDownloadDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, ProfilePictureUploadDelegate {
@IBOutlet weak var profilePic: UIImageView!
@IBOutlet weak var userName: UITextField!
@@ -13,6 +13,7 @@ class EditProfileViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var major: UITextField!
@IBOutlet weak var bio: UITextView!
@IBOutlet weak var bioChar: UILabel!
+ var imagePickerController: UIImagePickerController?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
@@ -28,6 +29,10 @@ class EditProfileViewController: UIViewController, UITextViewDelegate {
profilePic.layer.shadowOffset = CGSize(width: 0, height: 1)
profilePic.layer.shadowOpacity = 1
profilePic.layer.shadowRadius = 1.0
+ profilePic.layer.masksToBounds = true
+ let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(picTapped(tapGestureRecognizer:)))
+ profilePic.isUserInteractionEnabled = true
+ profilePic.addGestureRecognizer(tapGestureRecognizer)
userName.text = UserDefaultsManager.shared.getFirstName()
year.selectedSegmentIndex = UserDefaultsManager.shared.getYear() - 1
@@ -35,6 +40,16 @@ class EditProfileViewController: UIViewController, UITextViewDelegate {
bio.text = UserDefaultsManager.shared.getSelfBio()
bio.delegate = self
bioChar.text = "\(bio.text.count)"
+
+ ProfilePictureAPI().download(pictureForUserID: UserManager.shared.getUID(), delegate: self)
+ }
+
+ func profilePicture(didDownloadimage image: UIImage, forUserWithID _: Int) {
+ profilePic.image = image
+ }
+
+ func profilePicture(failedWithError error: String?) {
+ print("Failed to download profile picture: \(error ?? "")")
}
override func viewWillDisappear(_ animated: Bool) {
@@ -63,5 +78,60 @@ class EditProfileViewController: UIViewController, UITextViewDelegate {
self.bioChar.text = "\(numberOfChars)"
return numberOfChars < 250 // 250 character limit for Bio
}
+
+
+ @objc func picTapped(tapGestureRecognizer: UITapGestureRecognizer) {
+ // Allows user to choose between photo library and camera
+ let alertController = UIAlertController(title: nil, message: "Where do you want to get your picture from?", preferredStyle: .actionSheet)
+
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
+ alertController.addAction(cancelAction)
+
+ let photoLibraryAction = UIAlertAction(title: "Photo from Library", style: .default) { (action) in
+ self.showImagePickerController(sourceType: .photoLibrary)
+ }
+
+ alertController.addAction(photoLibraryAction)
+
+ // Only show camera option if rear camera is available
+ if (UIImagePickerController.isCameraDeviceAvailable(.rear)) {
+ let cameraAction = UIAlertAction(title: "Photo from Camera", style: .default) { (action) in
+ self.showImagePickerController(sourceType: .camera)
+ }
+ alertController.addAction(cameraAction)
+ }
+ present(alertController, animated: true, completion: nil)
+ }
+
+
+ func showImagePickerController(sourceType: UIImagePickerControllerSourceType) {
+ imagePickerController = UIImagePickerController()
+ imagePickerController!.sourceType = sourceType
+ imagePickerController!.delegate = self
+ present(imagePickerController!, animated: true, completion: nil)
+ }
+
+ func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
+ if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
+ self.profilePic.image = pickedImage
+
+ ProfilePictureAPI().upload(profilePicture: pickedImage, delegate: self)
+ }
+
+ dismiss(animated: true, completion: nil)
+ }
+
+ func profilePicture(uploadCompleted: Bool, failedWithError error: String?) {
+ if (uploadCompleted) {
+ // do nothing weeee
+ } else {
+ print("Failed to upload profile picture: " + (error ?? ""))
+ let alert = UIAlertController(title: "Upload Failed", message: "Your photo could not be uploaded at this time. Please try again later.", preferredStyle: .alert)
+ alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
+ self.profilePic.image = UIImage(named: "ProfilePic")
+ }))
+ self.present(alert, animated: true, completion: nil)
+ }
+ }
}
diff --git a/Bruin Bite/View Controllers/ProfileViewController.swift b/Bruin Bite/View Controllers/ProfileViewController.swift
index 487e060..d43e3c5 100644
--- a/Bruin Bite/View Controllers/ProfileViewController.swift
+++ b/Bruin Bite/View Controllers/ProfileViewController.swift
@@ -16,14 +16,6 @@ class ProfileViewController: UIViewController, ReadDelegate, AlertPresentable, L
@IBOutlet weak var userName: UILabel!
@IBOutlet weak var yearMajor: UILabel!
@IBOutlet weak var shortBio: UITextView!
-
- private var COMING_SOON_POPUP: UIAlertController {
- get {
- let alert = UIAlertController(title: "Edit Profile Coming Soon", message: "We're working hard on this feature and you will be able to edit your profile soon. Meanwhile you can email us at hello.bruin-bite@gmail.com with the profile changes you want and we'll update it for you!", preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
- return alert
- }
- }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
@@ -86,10 +78,6 @@ class ProfileViewController: UIViewController, ReadDelegate, AlertPresentable, L
yearMajor.text = "Year: \(year)" + " | " + "Major: \(major)"
shortBio.text = UserDefaultsManager.shared.getSelfBio()
}
-
- @IBAction func didPressEditProfile(_ sender: Any) {
- self.present(COMING_SOON_POPUP, animated: true)
- }
@IBAction func didPressFeedback(_ sender: Any) {
guard let url = URL(string: "https://docs.google.com/forms/d/1sFffuMFWwTsIi7R9rIyRVTRysj_m9LH14XxGzbFsxPg/edit") else {