mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-21 18:56:29 +10:00
only update if profileUserIsMe
This commit is contained in:
@@ -1444,15 +1444,8 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
|
||||
case ProfileSection.Footer.rawValue:
|
||||
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(footerCellIdentifier, forIndexPath: indexPath) as! ProfileFooterCell
|
||||
|
||||
cell.configureWithNickname(profileUser?.nickname ?? "", username: profileUser?.username, introduction: introductionText)
|
||||
|
||||
if let profileUser = profileUser {
|
||||
switch profileUser {
|
||||
case .DiscoveredUserType(let discoveredUser):
|
||||
cell.location = CLLocation(latitude: discoveredUser.latitude, longitude: discoveredUser.longitude)
|
||||
case .UserType(let user):
|
||||
cell.location = CLLocation(latitude: user.latitude, longitude: user.longitude)
|
||||
}
|
||||
cell.configureWithProfileUser(profileUser, introduction: introductionText)
|
||||
}
|
||||
|
||||
return cell
|
||||
|
||||
@@ -36,6 +36,38 @@ class ProfileFooterCell: UICollectionViewCell {
|
||||
YepUserDefaults.userLocationName.removeListenerWithName(listener.userLocationName)
|
||||
}
|
||||
|
||||
private func updateUIWithUserLocationName(userLocationName: String?) {
|
||||
|
||||
if let userLocationName = userLocationName {
|
||||
locationContainerView.hidden = false
|
||||
locationLabel.text = userLocationName
|
||||
|
||||
} else {
|
||||
locationContainerView.hidden = true
|
||||
}
|
||||
}
|
||||
|
||||
var profileUserIsMe = false {
|
||||
didSet {
|
||||
if profileUserIsMe {
|
||||
YepUserDefaults.userLocationName.bindAndFireListener(listener.userLocationName, action: { [weak self] userLocationName in
|
||||
self?.updateUIWithUserLocationName(userLocationName)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var newUserLocationName: String? {
|
||||
didSet {
|
||||
if profileUserIsMe {
|
||||
YepUserDefaults.userLocationName.value = newUserLocationName
|
||||
|
||||
} else {
|
||||
updateUIWithUserLocationName(newUserLocationName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
@@ -45,19 +77,24 @@ class ProfileFooterCell: UICollectionViewCell {
|
||||
introductionLabel.font = YepConfig.Profile.introductionLabelFont
|
||||
introductionLabel.textColor = UIColor.yepGrayColor()
|
||||
|
||||
YepUserDefaults.userLocationName.bindAndFireListener(listener.userLocationName, action: { [weak self] userLocationName in
|
||||
|
||||
if let userLocationName = userLocationName {
|
||||
self?.locationContainerView.hidden = false
|
||||
self?.locationLabel.text = userLocationName
|
||||
|
||||
} else {
|
||||
self?.locationContainerView.hidden = true
|
||||
}
|
||||
})
|
||||
newUserLocationName = nil
|
||||
}
|
||||
|
||||
func configureWithNickname(nickname: String, username: String?, introduction: String) {
|
||||
func configureWithProfileUser(profileUser: ProfileUser, introduction: String) {
|
||||
|
||||
profileUserIsMe = profileUser.isMe
|
||||
|
||||
configureWithNickname(profileUser.nickname ?? "", username: profileUser.username, introduction: introduction)
|
||||
|
||||
switch profileUser {
|
||||
case .DiscoveredUserType(let discoveredUser):
|
||||
location = CLLocation(latitude: discoveredUser.latitude, longitude: discoveredUser.longitude)
|
||||
case .UserType(let user):
|
||||
location = CLLocation(latitude: user.latitude, longitude: user.longitude)
|
||||
}
|
||||
}
|
||||
|
||||
private func configureWithNickname(nickname: String, username: String?, introduction: String) {
|
||||
|
||||
nicknameLabel.text = nickname
|
||||
|
||||
@@ -92,8 +129,7 @@ class ProfileFooterCell: UICollectionViewCell {
|
||||
|
||||
if let placemarks = placemarks {
|
||||
if let firstPlacemark = placemarks.first {
|
||||
let name = firstPlacemark.locality ?? (firstPlacemark.name ?? firstPlacemark.country)
|
||||
YepUserDefaults.userLocationName.value = name
|
||||
self?.newUserLocationName = firstPlacemark.locality ?? (firstPlacemark.name ?? firstPlacemark.country)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user