Skip to content

Commit ffecb95

Browse files
committed
Added profile editing and viewing. Improvements to the data that is displayed
1 parent d32a7c5 commit ffecb95

38 files changed

+3204
-2550
lines changed

Cluster/Base.lproj/Main.storyboard

Lines changed: 88 additions & 37 deletions
Large diffs are not rendered by default.

Cluster/Cluster-Bridging-Header.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
#import <ParseUI/PFImageView.h>
99
#import <MBProgressHUD/MBProgressHUD.h>
1010
#import <SlackTextViewController/SLKTextViewController.h>
11-
#import "BLMultiColorLoader.h"
11+
#import "BLMultiColorLoader.h"
12+
#import "UITextView+Placeholder.h"

Cluster/EditProfileTableViewController.swift

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,43 @@ import Photos
1111

1212
class EditProfileTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
1313

14-
@IBOutlet weak var coverImage: UIImageView!
15-
@IBOutlet weak var profileImage: UIImageView!
14+
@IBOutlet weak var coverImage: PFImageView!
15+
@IBOutlet weak var profileImage: PFImageView!
1616
@IBOutlet weak var profileImageOverlay: UIVisualEffectView!
1717
@IBOutlet weak var aboutMeTextView: UITextView!
18-
@IBOutlet weak var nameTextField: UITextField!
18+
@IBOutlet weak var logOutButton: DesignableButton!
19+
@IBOutlet weak var firstNameTextField: UITextField!
20+
@IBOutlet weak var lastNameTextField: UITextField!
1921
@IBOutlet weak var ageTextField: UITextField!
2022
@IBOutlet weak var locationTextField: UITextField!
21-
@IBOutlet weak var logOutButton: DesignableButton!
2223

24+
var user: PFUser! = PFUser.currentUser()
2325
private var profilePic: UIImage!
2426
private var coverPic: UIImage!
2527

26-
let numberOfRowsAtSection: [Int] = [4, 3]
28+
let numberOfRowsAtSection: [Int] = [5, 3]
2729

30+
@IBAction func saveProfileInformationPressed(sender: AnyObject) {
31+
if (self.validAttributes()) {
32+
let firstName = self.firstNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
33+
let lastName = self.lastNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
34+
let age = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
35+
let location = self.locationTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
36+
let biography = self.aboutMeTextView.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
37+
self.user.setObject(firstName!, forKey: "firstName")
38+
self.user.setObject(lastName!, forKey: "lastName")
39+
self.user.setObject(age!, forKey: "age")
40+
self.user.setObject(location!, forKey: "location")
41+
self.user.setObject(biography!, forKey: "biography")
42+
self.user.saveEventually()
43+
self.dismissViewControllerAnimated(true, completion: nil)
44+
} else {
45+
let alert = UIAlertController.init(title: "Save Error", message: "Please enter all your information before we can save your profile.", preferredStyle: .Alert)
46+
let okAction = UIAlertAction.init(title: "OK", style: .Default, handler: nil)
47+
alert.addAction(okAction)
48+
self.presentViewController(alert, animated: true, completion: nil)
49+
}
50+
}
2851
//MARK: - Change Status Bar to White
2952
override func preferredStatusBarStyle() -> UIStatusBarStyle {
3053
return .LightContent
@@ -43,15 +66,48 @@ class EditProfileTableViewController: UITableViewController, UIImagePickerContro
4366
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
4467
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
4568

46-
69+
// Change the keyboard type for the age text field
70+
self.ageTextField.keyboardType = .DecimalPad
71+
72+
// Update the profile with user information
73+
self.loadImages()
74+
self.updateTextFields()
4775
}
4876

49-
//MARK: Text View Handler
77+
private func loadImages() {
78+
self.profileImage.file = self.user.objectForKey("avatar") as? PFFile
79+
self.profileImage.loadInBackground()
80+
}
5081

51-
deinit {
52-
NSNotificationCenter.defaultCenter().removeObserver(self)
82+
// Sets the initial tableview textfield values
83+
private func updateTextFields() {
84+
self.firstNameTextField.text = self.user.objectForKey("firstName") as? String
85+
self.lastNameTextField.text = self.user.objectForKey("lastName") as? String
86+
87+
if (self.user.objectForKey("age") != nil) {
88+
let age = self.user.objectForKey("age") as? Int
89+
self.ageTextField.text = "\(age)"
90+
}
91+
92+
self.locationTextField.text = self.user.objectForKey("location") as? String
93+
94+
// Update the about me placeholder
95+
self.aboutMeTextView.placeholder = "Tell us about yourself..."
96+
self.aboutMeTextView.text = self.user.objectForKey("biography") as? String
97+
}
98+
99+
private func validAttributes() -> Bool {
100+
let firstName = self.firstNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
101+
let lastName = self.lastNameTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
102+
let age = self.ageTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
103+
let location = self.locationTextField.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
104+
let biography = self.aboutMeTextView.text?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
105+
106+
return firstName?.length > 0 && lastName?.length > 0 && age?.length > 0 && location?.length > 0 && biography?.length > 0
53107
}
54108

109+
//MARK: Text View Handler
110+
55111
func keyboardWillHide(notification: NSNotification) {
56112
self.aboutMeTextView.contentInset = UIEdgeInsetsZero
57113
self.aboutMeTextView.scrollIndicatorInsets = UIEdgeInsetsZero

Cluster/ProfileViewController.swift

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class ProfileViewController: UIViewController {
2121
@IBOutlet weak var scroller: UIScrollView!
2222
@IBOutlet weak var profileImageView: PFImageView!
2323
@IBOutlet weak var ageLabel: UILabel!
24+
@IBOutlet weak var biographyLabel: UILabel!
25+
26+
@IBAction func menuButtonPressed(sender: AnyObject) {
27+
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
28+
let editProfileController = storyboard.instantiateViewControllerWithIdentifier("EditProfileTableViewController")
29+
self.presentViewController(editProfileController, animated: true, completion: nil)
30+
}
2431

2532
//MARK: - Change Status Bar to White
2633
override func preferredStatusBarStyle() -> UIStatusBarStyle {
@@ -30,13 +37,7 @@ class ProfileViewController: UIViewController {
3037
override func viewDidLoad() {
3138
super.viewDidLoad()
3239

33-
// Load profile info
34-
self.profileImageView.file = self.user!.objectForKey("avatar") as? PFFile
35-
self.profileImageView.loadInBackground()
36-
37-
let firstName = user?.objectForKey("firstName") as! String
38-
let lastName = user?.objectForKey("lastName") as! String
39-
self.nameLabel.text = firstName + " " + lastName
40+
self.loadProfileInfo()
4041

4142
scroller.contentInset = UIEdgeInsetsMake(0, 0, 400, 0)
4243

@@ -106,4 +107,32 @@ class ProfileViewController: UIViewController {
106107
func presentCamera() {
107108

108109
}
110+
111+
private func loadProfileInfo() {
112+
// Load profile info
113+
self.profileImageView.file = self.user!.objectForKey("avatar") as? PFFile
114+
self.profileImageView.loadInBackground()
115+
116+
let firstName = user?.objectForKey("firstName") as! String
117+
let lastName = user?.objectForKey("lastName") as! String
118+
self.nameLabel.text = firstName + " " + lastName
119+
120+
if (self.user?.objectForKey("age") != nil) {
121+
let age = self.user?.objectForKey("age") as? Int
122+
self.ageLabel.text = "\(age) yrs"
123+
} else {
124+
self.ageLabel.text = "🤔"
125+
}
126+
127+
if (self.user?.objectForKey("biography") != nil) {
128+
129+
} else {
130+
self.biographyLabel.text = self.randomBiographyString()
131+
}
132+
}
133+
134+
private func randomBiographyString() -> String {
135+
let firstName = self.user?.objectForKey("firstName") as? String
136+
return "Surely \(firstName) is clever, but they haven't shared anything with us."
137+
}
109138
}

Podfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pod 'ParseUI'
55
pod 'ParseFacebookUtilsV4'
66
pod 'MBProgressHUD'
77
pod 'SlackTextViewController'
8-
pod 'SWRevealTableViewCell'
8+
pod 'SWRevealTableViewCell'
9+
pod 'UITextView+Placeholder'

Podfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PODS:
2323
- Parse (~> 1.9)
2424
- SlackTextViewController (1.9.1)
2525
- SWRevealTableViewCell (0.3.5)
26+
- UITextView+Placeholder (1.1.1)
2627

2728
DEPENDENCIES:
2829
- MBProgressHUD
@@ -31,6 +32,7 @@ DEPENDENCIES:
3132
- ParseUI
3233
- SlackTextViewController
3334
- SWRevealTableViewCell
35+
- UITextView+Placeholder
3436

3537
SPEC CHECKSUMS:
3638
Bolts: f52a250053bb517ca874523c3913776359ab3def
@@ -42,5 +44,6 @@ SPEC CHECKSUMS:
4244
ParseUI: af2eba584799da4a9fbdac0e178662d7438b502e
4345
SlackTextViewController: 6b0d1030c53937226fc5358f217af2a34fc211cf
4446
SWRevealTableViewCell: c97ca17df7153f2f130f307ea90399d4b19e4e15
47+
UITextView+Placeholder: a6fc3e0378f3870036ec562a7537cbf6dbae4bf6
4548

4649
COCOAPODS: 0.39.0

Pods/Headers/Private/UITextView+Placeholder/UITextView+Placeholder.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Headers/Public/UITextView+Placeholder/UITextView+Placeholder.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/Manifest.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)