diff --git a/Podfile.lock b/Podfile.lock index 00d4598a..a5c3009f 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -53,7 +53,7 @@ DEPENDENCIES: EXTERNAL SOURCES: MZFayeClient: - :path: "../CatchLib-iOS/MZFayeClient/" + :path: ../CatchLib-iOS/MZFayeClient/ SPEC CHECKSUMS: 1PasswordExtension: 9f471645d378283cb88c6d4bf502e4381a42c0ad diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index c09a654b..50b61d87 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -396,7 +396,7 @@ class ProfileViewController: UIViewController { } if user.friendState == UserFriendState.Me.rawValue { - YepUserDefaults.introduction.bindListener(Listener.Introduction) { [weak self] introduction in + YepUserDefaults.introduction.bindListener(self.listener.introduction) { [weak self] introduction in dispatch_async(dispatch_get_main_queue()) { if let introduction = introduction { self?.introductionText = introduction @@ -409,7 +409,7 @@ class ProfileViewController: UIViewController { } return introduction ?? NSLocalizedString("No Introduction yet.", comment: "") - }() + }() var masterSkills = [Skill]() @@ -479,17 +479,29 @@ class ProfileViewController: UIViewController { struct Listener { - static let Nickname = "ProfileViewController.Title" - static let Introduction = "Profile.introductionText" + let nickname: String + let introduction: String + let avatar: String } + lazy var listener: Listener = { + + var myUserID = "" + if let profileUser = self.profileUser where profileUser.isMe { + myUserID = profileUser.userID + } + + return Listener(nickname: "Profile.Title" + myUserID, introduction: "Profile.introductionText" + myUserID, avatar: "Profile.Avatar" + myUserID) + }() + // MARK: Life cycle deinit { NSNotificationCenter.defaultCenter().removeObserver(self) - YepUserDefaults.nickname.removeListenerWithName(Listener.Nickname) - YepUserDefaults.introduction.removeListenerWithName(Listener.Introduction) + YepUserDefaults.nickname.removeListenerWithName(listener.nickname) + YepUserDefaults.introduction.removeListenerWithName(listener.introduction) + YepUserDefaults.avatarURLString.removeListenerWithName(listener.avatar) profileCollectionView.delegate = nil @@ -683,11 +695,23 @@ class ProfileViewController: UIViewController { customNavigationItem.title = user.nickname if user.friendState == UserFriendState.Me.rawValue { - YepUserDefaults.nickname.bindListener(Listener.Nickname) { [weak self] nickname in + YepUserDefaults.nickname.bindListener(listener.nickname) { [weak self] nickname in dispatch_async(dispatch_get_main_queue()) { self?.customNavigationItem.title = nickname } } + + YepUserDefaults.avatarURLString.bindListener(listener.avatar) { [weak self] avatarURLString in + dispatch_async(dispatch_get_main_queue()) { + let indexPath = NSIndexPath(forItem: 0, inSection: ProfileSection.Header.rawValue) + if let cell = self?.profileCollectionView.cellForItemAtIndexPath(indexPath) as? ProfileHeaderCell { + if let avatarURLString = avatarURLString { + cell.blurredAvatarImage = nil // need reblur + cell.updateAvatarWithAvatarURLString(avatarURLString) + } + } + } + } } } diff --git a/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift b/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift index 408abd25..ea353d3f 100644 --- a/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift +++ b/Yep/Views/Cells/ProfileHeader/ProfileHeaderCell.swift @@ -20,14 +20,8 @@ class ProfileHeaderCell: UICollectionViewCell { var askedForPermission = false - struct Listener { - static let Avatar = "ProfileHeaderCell.Avatar" - } - deinit { NSNotificationCenter.defaultCenter().removeObserver(self) - - YepUserDefaults.avatarURLString.removeListenerWithName(Listener.Avatar) } override func awakeFromNib() { @@ -84,15 +78,6 @@ class ProfileHeaderCell: UICollectionViewCell { updateAvatarWithAvatarURLString(user.avatarURLString) if user.friendState == UserFriendState.Me.rawValue { - - YepUserDefaults.avatarURLString.bindListener(Listener.Avatar) { [weak self] avatarURLString in - dispatch_async(dispatch_get_main_queue()) { - if let avatarURLString = avatarURLString { - self?.blurredAvatarImage = nil // need reblur - self?.updateAvatarWithAvatarURLString(avatarURLString) - } - } - } if !askedForPermission { askedForPermission = true