-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileViewController.swift
More file actions
150 lines (117 loc) · 5.47 KB
/
ProfileViewController.swift
File metadata and controls
150 lines (117 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// ProfileViewController.swift
// Cluster
//
// Created by lsecrease on 9/22/15.
// Copyright (c) 2015 ImagineME. All rights reserved.
//
import UIKit
import Photos
class ProfileViewController: UIViewController {
var user: PFUser! = PFUser.currentUser()
@IBOutlet weak var coverImage: PFImageView!
@IBOutlet weak var editButton: DesignableButton!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var menuButton: UIButton!
@IBOutlet weak var scroller: UIScrollView!
@IBOutlet weak var profileImageView: PFImageView!
@IBOutlet weak var ageLabel: UILabel!
@IBOutlet weak var biographyLabel: UILabel!
@IBOutlet weak var locationLabel: UILabel!
@IBAction func menuButtonPressed(sender: AnyObject) {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let editProfileController = storyboard.instantiateViewControllerWithIdentifier("EditProfileTableViewController")
self.presentViewController(editProfileController, animated: true, completion: nil)
}
//MARK: - Change Status Bar to White
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func viewDidLoad() {
super.viewDidLoad()
scroller.contentInset = UIEdgeInsetsMake(0, 0, 400, 0)
self.profileImageView.layer.cornerRadius = self.profileImageView.bounds.width / 2
self.profileImageView.layer.masksToBounds = true
editButton.layer.cornerRadius = editButton.bounds.width / 2
editButton.layer.masksToBounds = true
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.loadProfileInfo()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.scroller.frame = self.view.bounds
self.scroller.contentSize.height = 400
self.scroller.contentSize.width = 0
}
@IBAction func klusterNowButtonPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func addPhotoClicked(sender: DesignableButton) {
let authorization = PHPhotoLibrary.authorizationStatus()
if authorization == .NotDetermined {
PHPhotoLibrary.requestAuthorization({ (status) -> Void in
//self.pickFeaturedImageClicked(sender)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.addPhotoClicked(sender)
})
})
return
}
//Do you want to Take a Photo or Video with the Camera
if authorization == .Authorized {
let controller = ImagePickerSheetController()
controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in
self.presentCamera()
}, secondaryHandler: { (action, numberOfPhotos) -> () in
controller.getSelectedImagesWithCompletion({ (images) -> Void in
let image = images[0]
let imageData = UIImagePNGRepresentation(image!)
let file = PFFile.init(name: "avatar.png", data: imageData!)
self.profileImageView.image = image
let user = PFUser.currentUser()
user?.setObject(file!, forKey: "avatar")
user?.saveInBackgroundWithBlock({ (save: Bool, error: NSError?) -> Void in
if (error != nil) {
print("We have an error...")
}
})
})
}))
controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel))
presentViewController(controller, animated: true, completion: nil)
}
}
func presentCamera() {
}
private func loadProfileInfo() {
// Load profile info
self.profileImageView.file = self.user.objectForKey("avatar") as? PFFile
self.profileImageView.loadInBackground()
self.coverImage.file = self.user.objectForKey("coverImage") as? PFFile
self.coverImage.loadInBackground()
let firstName = self.user.objectForKey("firstName") as! String
let lastName = self.user.objectForKey("lastName") as! String
self.nameLabel.text = firstName + " " + lastName
if let location = self.user.objectForKey("location") as? String {
self.locationLabel.text = location
} else {
self.locationLabel.text = "🌎"
}
if let age = self.user.objectForKey("age") as? Int {
self.ageLabel.text = "\(age) yrs"
} else {
self.ageLabel.text = "🤔"
}
if let bio = self.user.objectForKey("biography") as? String {
self.biographyLabel.text = bio
} else {
self.biographyLabel.text = self.randomBiographyString()
}
}
private func randomBiographyString() -> String {
let firstName = self.user.objectForKey("firstName") as! String
return "Surely \(firstName) is clever, but they haven't shared anything with us."
}
}