Skip to content

Commit f432d10

Browse files
committed
layout fixes and data loading improvements
1 parent 077c7d7 commit f432d10

9 files changed

Lines changed: 90 additions & 65 deletions

Cluster/.DS_Store

0 Bytes
Binary file not shown.

Cluster/Base.lproj/Main.storyboard

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@
11881188
</segue>
11891189
</connections>
11901190
</button>
1191-
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="fashion" translatesAutoresizingMaskIntoConstraints="NO" id="4th-al-Vy1">
1191+
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="fashion" translatesAutoresizingMaskIntoConstraints="NO" id="4th-al-Vy1" customClass="PFImageView">
11921192
<rect key="frame" x="0.0" y="0.0" width="600" height="200"/>
11931193
<constraints>
11941194
<constraint firstAttribute="height" constant="200" id="BRc-Gv-hn4"/>
@@ -1323,7 +1323,7 @@
13231323
<connections>
13241324
<outlet property="ageLabel" destination="6G2-dD-aoK" id="bTw-Ie-PGg"/>
13251325
<outlet property="biographyLabel" destination="Zyu-Yz-Gte" id="QxE-We-OPB"/>
1326-
<outlet property="coverImage" destination="4th-al-Vy1" id="J3B-OA-Dwi"/>
1326+
<outlet property="coverImage" destination="4th-al-Vy1" id="ju4-Ap-UWO"/>
13271327
<outlet property="editButton" destination="YPD-vd-zbQ" id="mLd-pS-D6B"/>
13281328
<outlet property="locationLabel" destination="Cwa-67-syF" id="Co5-hH-L2V"/>
13291329
<outlet property="menuButton" destination="RxG-pW-nCC" id="RBu-x0-Iy0"/>
@@ -1942,24 +1942,12 @@
19421942
<rect key="frame" x="0.0" y="0.0" width="600" height="67.5"/>
19431943
<autoresizingMask key="autoresizingMask"/>
19441944
<subviews>
1945-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="What are we doing tonight?" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lGT-du-aC0">
1945+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="750" verticalHuggingPriority="750" text="What are we doing tonight?" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lGT-du-aC0">
19461946
<rect key="frame" x="66" y="33" width="514" height="21"/>
1947-
<constraints>
1948-
<constraint firstAttribute="height" constant="21" id="GTa-6H-g1q"/>
1949-
</constraints>
19501947
<fontDescription key="fontDescription" type="system" pointSize="14"/>
19511948
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
19521949
<nil key="highlightedColor"/>
19531950
</label>
1954-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Michael Fellows" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="olg-OI-0pz">
1955-
<rect key="frame" x="66" y="4" width="514" height="29"/>
1956-
<constraints>
1957-
<constraint firstAttribute="height" constant="29" id="Icm-aX-xnJ"/>
1958-
</constraints>
1959-
<fontDescription key="fontDescription" type="system" pointSize="19"/>
1960-
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
1961-
<nil key="highlightedColor"/>
1962-
</label>
19631951
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="profile1" translatesAutoresizingMaskIntoConstraints="NO" id="uIc-BZ-8gG" customClass="PFImageView">
19641952
<rect key="frame" x="8" y="4" width="50" height="50"/>
19651953
<gestureRecognizers/>
@@ -1973,16 +1961,26 @@
19731961
</userDefinedRuntimeAttribute>
19741962
</userDefinedRuntimeAttributes>
19751963
</imageView>
1964+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="751" verticalHuggingPriority="751" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" text="Michael Fellows" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="olg-OI-0pz">
1965+
<rect key="frame" x="66" y="4" width="514" height="29"/>
1966+
<constraints>
1967+
<constraint firstAttribute="height" constant="29" id="bTO-oE-B4W"/>
1968+
</constraints>
1969+
<fontDescription key="fontDescription" type="system" pointSize="19"/>
1970+
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
1971+
<nil key="highlightedColor"/>
1972+
</label>
19761973
</subviews>
19771974
<constraints>
1978-
<constraint firstItem="olg-OI-0pz" firstAttribute="top" secondItem="Ueo-H1-dwC" secondAttribute="topMargin" constant="-4" id="2bb-Fd-tBp"/>
1979-
<constraint firstItem="olg-OI-0pz" firstAttribute="leading" secondItem="uIc-BZ-8gG" secondAttribute="trailing" constant="8" id="KWq-7A-fbx"/>
1980-
<constraint firstItem="lGT-du-aC0" firstAttribute="leading" secondItem="uIc-BZ-8gG" secondAttribute="trailing" constant="8" id="Ki2-Nc-pkj"/>
1975+
<constraint firstItem="lGT-du-aC0" firstAttribute="top" secondItem="olg-OI-0pz" secondAttribute="bottom" id="1dy-po-O9O"/>
1976+
<constraint firstAttribute="trailing" secondItem="olg-OI-0pz" secondAttribute="trailing" constant="20" id="2vy-ZZ-zCx"/>
1977+
<constraint firstItem="olg-OI-0pz" firstAttribute="leading" secondItem="uIc-BZ-8gG" secondAttribute="trailing" constant="8" id="9Rw-iI-M0Q"/>
1978+
<constraint firstItem="lGT-du-aC0" firstAttribute="leading" secondItem="uIc-BZ-8gG" secondAttribute="trailing" constant="8" id="AVa-1H-TfB"/>
1979+
<constraint firstAttribute="trailing" secondItem="lGT-du-aC0" secondAttribute="trailing" constant="20" id="RAd-YS-N9T"/>
19811980
<constraint firstAttribute="leadingMargin" secondItem="uIc-BZ-8gG" secondAttribute="leading" id="VUm-KX-RGz"/>
1981+
<constraint firstAttribute="bottom" secondItem="lGT-du-aC0" secondAttribute="bottom" constant="13.5" id="YkT-VH-VuT"/>
19821982
<constraint firstItem="uIc-BZ-8gG" firstAttribute="top" secondItem="Ueo-H1-dwC" secondAttribute="topMargin" constant="-4" id="dLb-Ih-2Jy"/>
1983-
<constraint firstAttribute="trailingMargin" secondItem="lGT-du-aC0" secondAttribute="trailing" constant="12" id="l8v-EC-iQ0"/>
1984-
<constraint firstAttribute="trailingMargin" secondItem="olg-OI-0pz" secondAttribute="trailing" constant="12" id="oE1-a4-nik"/>
1985-
<constraint firstItem="lGT-du-aC0" firstAttribute="top" secondItem="olg-OI-0pz" secondAttribute="bottom" id="w8I-CY-I5J"/>
1983+
<constraint firstItem="olg-OI-0pz" firstAttribute="top" secondItem="Ueo-H1-dwC" secondAttribute="top" constant="4" id="nIc-P2-hgv"/>
19861984
</constraints>
19871985
</tableViewCellContentView>
19881986
<connections>

Cluster/EditProfileTableViewController.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,19 @@ class EditProfileTableViewController: UITableViewController, UIImagePickerContro
7979
private func loadImages() {
8080
self.profileImage.file = self.user.objectForKey("avatar") as? PFFile
8181
self.profileImage.loadInBackground()
82+
83+
// Set a placeholder image
84+
self.coverImage.image = UIImage(named: "fashion")
85+
self.coverImage.file = self.user.objectForKey("coverImage") as? PFFile
86+
self.coverImage.loadInBackground()
8287
}
8388

8489
// Sets the initial tableview textfield values
8590
private func updateTextFields() {
8691
self.firstNameTextField.text = self.user.objectForKey("firstName") as? String
8792
self.lastNameTextField.text = self.user.objectForKey("lastName") as? String
8893

89-
if (self.user.objectForKey("age") != nil) {
90-
let age = self.user.objectForKey("age") as? Int
94+
if let age = self.user.objectForKey("age") as? Int {
9195
self.ageTextField.text = "\(age)"
9296
}
9397

@@ -203,6 +207,18 @@ class EditProfileTableViewController: UITableViewController, UIImagePickerContro
203207
controller.getSelectedImagesWithCompletion({ (images) -> Void in
204208
self.coverPic = images[0]
205209
self.coverImage.image = self.coverPic
210+
211+
let imageData = UIImagePNGRepresentation(self.coverPic)
212+
let file = PFFile.init(name: "cover.png", data: imageData!)
213+
self.user.setObject(file!, forKey: "coverImage")
214+
self.user.saveInBackgroundWithBlock({ (success, error) -> Void in
215+
if (error != nil) {
216+
let alert = UIAlertController.init(title: "Error", message: "Unable to update cover image.", preferredStyle: .Alert)
217+
let okAction = UIAlertAction.init(title: "OK", style: .Default, handler: nil)
218+
alert.addAction(okAction)
219+
self.presentViewController(alert, animated: true, completion: nil)
220+
}
221+
})
206222
})
207223
}))
208224

Cluster/HomeViewController.swift

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class HomeViewController: UIViewController {
2626
private var klusters = [PFObject]()
2727
var locationManager = CLLocationManager()
2828
var currentGeoPoint: PFGeoPoint?
29+
var userProfileView: ProfileNameView?
2930

3031
//MARK: - Change Status Bar to White
3132
override func preferredStatusBarStyle() -> UIStatusBarStyle {
@@ -51,17 +52,6 @@ class HomeViewController: UIViewController {
5152
let tapRecognizer = UITapGestureRecognizer.init(target: self, action: "viewTapped:")
5253
self.view.addGestureRecognizer(tapRecognizer)
5354

54-
// Update the user profile information
55-
// let user = PFUser.currentUser()
56-
// self.profileAvatar.file = user?.objectForKey("avatarThumbnail") as? PFFile
57-
// self.profileAvatar.loadInBackground()
58-
//
59-
// let firstName = user?.objectForKey("firstName") as? String
60-
// self.currentUserFullNameButton.setTitle(firstName, forState: .Normal)
61-
//
62-
// profileAvatar.layer.cornerRadius = 10.0
63-
// profileAvatar.clipsToBounds = true
64-
6555
self.calculateCurrentLocation()
6656

6757
self.addProfileView()
@@ -84,6 +74,8 @@ class HomeViewController: UIViewController {
8474
// let's request location authorization
8575
self.locationManager.requestWhenInUseAuthorization()
8676
}
77+
78+
self.updateUserInfo()
8779
}
8880

8981
private func showLogin() {
@@ -163,26 +155,37 @@ class HomeViewController: UIViewController {
163155
}
164156
}
165157

158+
/**
159+
Updates the bottom-right view of the user
160+
We call this when the view appears in case a user
161+
changes their name or avatar.
162+
**/
163+
private func updateUserInfo() {
164+
self.userProfileView?.layoutForUser(PFUser.currentUser())
165+
}
166+
166167
private func addProfileView() {
167168
let user = PFUser.currentUser()
168169
let firstName = user?.objectForKey("firstName") as? String
169170
let maxWidth = self.view.frame.size.width - 200.0
170171
let font = UIFont.systemFontOfSize(17)
171172
let labelWidth = self.widthForlabel(firstName, font: font, maxWidth: maxWidth)
172173
let profileFrame = CGRectMake(0, 0, labelWidth, 40)
173-
let userProfileView = ProfileNameView.init(frame: profileFrame)
174-
userProfileView.layoutForUser(user)
175-
self.view.addSubview(userProfileView)
176-
177-
let profileRecognizer = UITapGestureRecognizer.init(target: self, action: "profileTapped:")
178-
userProfileView.addGestureRecognizer(profileRecognizer)
179-
180-
let metrics = ["spacing" : 6]
181-
let views = ["userProfileView" : userProfileView]
182-
let profileH = NSLayoutConstraint.constraintsWithVisualFormat("H:[userProfileView]-|", options: NSLayoutFormatOptions(rawValue: 0) , metrics: nil, views: views)
183-
let profileY = NSLayoutConstraint.constraintsWithVisualFormat("V:[userProfileView]-(spacing)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics , views: views)
184-
self.view.addConstraints(profileH)
185-
self.view.addConstraints(profileY)
174+
self.userProfileView = ProfileNameView.init(frame: profileFrame)
175+
if let userProfileView = self.userProfileView {
176+
userProfileView.layoutForUser(user)
177+
self.view.addSubview(userProfileView)
178+
179+
let profileRecognizer = UITapGestureRecognizer.init(target: self, action: "profileTapped:")
180+
userProfileView.addGestureRecognizer(profileRecognizer)
181+
182+
let metrics = ["spacing" : 6]
183+
let views = ["userProfileView" : userProfileView]
184+
let profileH = NSLayoutConstraint.constraintsWithVisualFormat("H:[userProfileView]-|", options: NSLayoutFormatOptions(rawValue: 0) , metrics: nil, views: views)
185+
let profileY = NSLayoutConstraint.constraintsWithVisualFormat("V:[userProfileView]-(spacing)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics , views: views)
186+
self.view.addConstraints(profileH)
187+
self.view.addConstraints(profileY)
188+
}
186189
}
187190

188191
private func widthForlabel(text: String?, font: UIFont, maxWidth: CGFloat) -> CGFloat {
@@ -291,7 +294,6 @@ extension HomeViewController : UICollectionViewDataSource
291294
let k = Kluster.init(object: self.klusters[(sender.view?.tag)!])
292295
messagesController.kluster = k
293296

294-
295297
// Show kluster
296298
let navigationController = MessagesNavigationController.init(rootViewController: messagesController)
297299
self.presentViewController(navigationController, animated: true, completion: nil);

Cluster/LoginViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LoginViewController: UIViewController {
1717
(user: PFUser?, error: NSError?) -> Void in
1818
if let user = user {
1919

20-
let shouldMakeFacebookRequest: Bool = true // (user.isNew || user.objectForKey("firstName") == nil)
20+
let shouldMakeFacebookRequest: Bool = (user.isNew || user.objectForKey("firstName") == nil || user.objectForKey("lastName") == nil)
2121
if shouldMakeFacebookRequest {
2222
print("User signed up and logged in through Facebook!")
2323

Cluster/MessagesTableViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class MessagesTableViewController: UITableViewController {
2828
override func viewDidLoad() {
2929
super.viewDidLoad()
3030

31+
// Set dynamic row height
32+
self.tableView.rowHeight = UITableViewAutomaticDimension
33+
self.tableView.estimatedRowHeight = 68.0
34+
3135
// Format the navigation bar
3236
self.navigationItem.title = self.kluster.title
3337

@@ -171,10 +175,6 @@ class MessagesTableViewController: UITableViewController {
171175
cell.avatarImageView.addGestureRecognizer(tapRecognizer)
172176
return cell
173177
}
174-
175-
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
176-
return 68
177-
}
178178

179179
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
180180
return textViewHeight

Cluster/MyKlusterViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ extension MyKlusterViewController : UITableViewDataSource
9595
}
9696

9797
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
98-
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
99-
let klusterVC = storyboard.instantiateViewControllerWithIdentifier("KlusterViewController") as! KlusterViewController;
10098
let k = Kluster.init(object: self.klusters[indexPath.row])
101-
klusterVC.kluster = k
99+
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
100+
let messagesController = storyboard.instantiateViewControllerWithIdentifier("MessagesTableViewController") as! MessagesTableViewController
101+
messagesController.kluster = k
102102

103103
// Show kluster
104-
let navigationController = UINavigationController.init(rootViewController: klusterVC)
104+
let navigationController = MessagesNavigationController.init(rootViewController: messagesController)
105105
self.presentViewController(navigationController, animated: true, completion: nil);
106106
}
107107
}

Cluster/ProfileNameView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ class ProfileNameView : UIView {
5858
super.init(coder: aDecoder)
5959
}
6060

61-
func layoutForUser(user: PFUser!) {
62-
self.nameLabel.text = user.objectForKey("firstName") as? String
63-
self.avatarImageView.file = user.objectForKey("avatarThumbnail") as? PFFile
64-
self.avatarImageView.loadInBackground()
61+
func layoutForUser(user: PFUser?) {
62+
if let user = user {
63+
self.nameLabel.text = user.objectForKey("firstName") as? String
64+
self.avatarImageView.file = user.objectForKey("avatarThumbnail") as? PFFile
65+
self.avatarImageView.loadInBackground()
66+
}
6567
}
6668
}

0 commit comments

Comments
 (0)