@@ -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 ) ;
0 commit comments