tap Contacts to Profile

This commit is contained in:
nixzhu
2015-05-04 14:55:37 +08:00
parent 0a0bd85177
commit 7c8f19c82f
5 changed files with 137 additions and 66 deletions
+4 -4
View File
@@ -71,7 +71,7 @@
<outlet property="delegate" destination="la3-6z-2aH" id="zOV-zM-2KH"/>
</connections>
</collectionView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Q0w-sM-iIR" customClass="MessageToolbar" customModule="Yep" customModuleProvider="target">
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Q0w-sM-iIR" customClass="MessageToolbar" customModule="Yep" customModuleProvider="target">
<rect key="frame" x="0.0" y="250" width="600" height="50"/>
<items/>
</toolbar>
@@ -235,7 +235,7 @@
</navigationItem>
<connections>
<outlet property="contactsTableView" destination="3hF-wd-yhY" id="RfM-bD-4Oe"/>
<segue destination="la3-6z-2aH" kind="show" identifier="showConversation" id="oVL-QE-g4G"/>
<segue destination="AyC-pt-NR2" kind="show" identifier="showProfile" id="Pxr-1p-x84"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ynX-sO-VM0" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -360,7 +360,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="i6I-3Z-6M6" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1079" y="1045"/>
<point key="canvasLocation" x="1079" y="991"/>
</scene>
<!--Profile-->
<scene sceneID="Gwo-ON-4Er">
@@ -713,7 +713,7 @@
<image name="profile_avatar_frame" width="112" height="112"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="oVL-QE-g4G"/>
<segue reference="l4P-ds-ihU"/>
<segue reference="o3b-2D-AMq"/>
</inferredMetricsTieBreakers>
</document>
@@ -43,9 +43,14 @@ class ContactsViewController: UIViewController {
// MARK: Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showConversation" {
let vc = segue.destinationViewController as! ConversationViewController
vc.conversation = sender as! Conversation
if segue.identifier == "showProfile" {
let vc = segue.destinationViewController as! ProfileViewController
if let user = sender as? User {
vc.profileUser = ProfileUser.UserType(user)
}
vc.hidesBottomBarWhenPushed = true
}
}
}
@@ -79,24 +84,8 @@ extension ContactsViewController: UITableViewDataSource, UITableViewDelegate {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
//
// Profile
let friend = friends.objectAtIndex(UInt(indexPath.row)) as! User
if let conversation = friend.conversation {
performSegueWithIdentifier("showConversation", sender: conversation)
} else {
let newConversation = Conversation()
newConversation.type = ConversationType.OneToOne.rawValue
newConversation.withFriend = friend
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
realm.addObject(newConversation)
realm.commitWriteTransaction()
performSegueWithIdentifier("showConversation", sender: newConversation)
}
}
performSegueWithIdentifier("showProfile", sender: friend)
}
}
@@ -57,7 +57,7 @@ class DiscoverViewController: UIViewController {
let vc = segue.destinationViewController as! ProfileViewController
vc.discoveredUser = discoveredUser
vc.profileUser = ProfileUser.DiscoveredUserType(discoveredUser)
vc.hidesBottomBarWhenPushed = true
}
@@ -11,9 +11,14 @@ import Realm
let profileAvatarAspectRatio: CGFloat = 12.0 / 16.0
enum ProfileUser {
case DiscoveredUserType(DiscoveredUser)
case UserType(User)
}
class ProfileViewController: UIViewController {
var discoveredUser: DiscoveredUser?
var profileUser: ProfileUser?
@IBOutlet weak var profileCollectionView: UICollectionView!
@@ -67,8 +72,13 @@ class ProfileViewController: UIViewController {
profileCollectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: CGRectGetHeight(tabBarController.tabBar.bounds), right: 0)
}
if let discoveredUser = discoveredUser {
self.navigationItem.title = discoveredUser.nickname
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
self.navigationItem.title = discoveredUser.nickname
case .UserType(let user):
self.navigationItem.title = user.nickname
}
} else {
YepUserDefaults.nickname.bindAndFireListener("ProfileViewController.Title") { nickname in
@@ -76,7 +86,7 @@ class ProfileViewController: UIViewController {
}
}
if let discoveredUser = discoveredUser {
if let profileUser = profileUser {
let moreBarButtonItem = UIBarButtonItem(image: UIImage(named: "icon_more"), style: UIBarButtonItemStyle.Plain, target: self, action: "moreAction")
navigationItem.rightBarButtonItem = moreBarButtonItem
@@ -164,40 +174,65 @@ class ProfileViewController: UIViewController {
@IBAction func sayHi(sender: UIButton) {
if let discoveredUser = discoveredUser {
var stranger = userWithUserID(discoveredUser.id)
if let profileUser = profileUser {
let realm = RLMRealm.defaultRealm()
switch profileUser {
if stranger == nil {
let newUser = User()
case .DiscoveredUserType(let discoveredUser):
var stranger = userWithUserID(discoveredUser.id)
newUser.userID = discoveredUser.id
newUser.nickname = discoveredUser.nickname
newUser.avatarURLString = discoveredUser.avatarURLString
let realm = RLMRealm.defaultRealm()
newUser.friendState = UserFriendState.Stranger.rawValue
if stranger == nil {
let newUser = User()
realm.beginWriteTransaction()
realm.addObject(newUser)
realm.commitWriteTransaction()
newUser.userID = discoveredUser.id
newUser.nickname = discoveredUser.nickname
newUser.avatarURLString = discoveredUser.avatarURLString
stranger = newUser
}
newUser.friendState = UserFriendState.Stranger.rawValue
if let stranger = stranger {
if stranger.conversation == nil {
realm.beginWriteTransaction()
realm.addObject(newUser)
realm.commitWriteTransaction()
stranger = newUser
}
if let stranger = stranger {
if stranger.conversation == nil {
let newConversation = Conversation()
newConversation.type = ConversationType.OneToOne.rawValue
newConversation.withFriend = stranger
realm.beginWriteTransaction()
realm.addObject(newConversation)
realm.commitWriteTransaction()
}
if let conversation = stranger.conversation {
performSegueWithIdentifier("showConversation", sender: conversation)
NSNotificationCenter.defaultCenter().postNotificationName(YepNewMessagesReceivedNotification, object: nil)
}
}
case .UserType(let user):
if user.conversation == nil {
let newConversation = Conversation()
newConversation.type = ConversationType.OneToOne.rawValue
newConversation.withFriend = stranger
newConversation.withFriend = user
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
realm.addObject(newConversation)
realm.commitWriteTransaction()
}
if let conversation = stranger.conversation {
if let conversation = user.conversation {
performSegueWithIdentifier("showConversation", sender: conversation)
NSNotificationCenter.defaultCenter().postNotificationName(YepNewMessagesReceivedNotification, object: nil)
@@ -252,16 +287,27 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
return 1
case ProfileSection.Master.rawValue:
if let discoveredUser = discoveredUser {
return discoveredUser.masterSkills.count
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
return discoveredUser.masterSkills.count
case .UserType(let user):
return Int(user.masterSkills.count)
}
} else {
return masterSkills.count
}
case ProfileSection.Learning.rawValue:
if let discoveredUser = discoveredUser {
return discoveredUser.learningSkills.count
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
return discoveredUser.learningSkills.count
case .UserType(let user):
return Int(user.learningSkills.count)
}
} else {
return learningSkills.count
@@ -282,8 +328,13 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
case ProfileSection.Header.rawValue:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(headerCellIdentifier, forIndexPath: indexPath) as! ProfileHeaderCell
if let discoveredUser = discoveredUser {
cell.configureWithDiscoveredUser(discoveredUser)
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
cell.configureWithDiscoveredUser(discoveredUser)
case .UserType(let user):
cell.configureWithUser(user)
}
} else {
cell.configureWithMyInfo()
@@ -294,9 +345,15 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
case ProfileSection.Master.rawValue:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(skillCellIdentifier, forIndexPath: indexPath) as! SkillCell
if let discoveredUser = discoveredUser {
let skill = discoveredUser.masterSkills[indexPath.item]
cell.skillLabel.text = skill.localName
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
let skill = discoveredUser.masterSkills[indexPath.item]
cell.skillLabel.text = skill.localName
case .UserType(let user):
let userSkill = user.masterSkills[UInt(indexPath.item)] as! UserSkill
cell.skillLabel.text = userSkill.localName
}
} else {
let skill = masterSkills[indexPath.item]
@@ -308,15 +365,22 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
case ProfileSection.Learning.rawValue:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(skillCellIdentifier, forIndexPath: indexPath) as! SkillCell
if let discoveredUser = discoveredUser {
let skill = discoveredUser.learningSkills[indexPath.item]
cell.skillLabel.text = skill.localName
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
let skill = discoveredUser.learningSkills[indexPath.item]
cell.skillLabel.text = skill.localName
case .UserType(let user):
let userSkill = user.learningSkills[UInt(indexPath.item)] as! UserSkill
cell.skillLabel.text = userSkill.localName
}
} else {
let skill = learningSkills[indexPath.item]
cell.skillLabel.text = skill.localName
}
return cell
case ProfileSection.Footer.rawValue:
@@ -390,8 +454,14 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
case ProfileSection.Master.rawValue:
var skillLocalName = ""
if let discoveredUser = discoveredUser {
skillLocalName = discoveredUser.masterSkills[indexPath.item].localName
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
skillLocalName = discoveredUser.masterSkills[indexPath.item].localName
case .UserType(let user):
let userSkill = user.masterSkills[UInt(indexPath.item)] as! UserSkill
skillLocalName = userSkill.localName
}
} else {
skillLocalName = masterSkills[indexPath.item].localName
@@ -404,9 +474,15 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
case ProfileSection.Learning.rawValue:
var skillLocalName = ""
if let discoveredUser = discoveredUser {
skillLocalName = discoveredUser.learningSkills[indexPath.item].localName
if let profileUser = profileUser {
switch profileUser {
case .DiscoveredUserType(let discoveredUser):
skillLocalName = discoveredUser.learningSkills[indexPath.item].localName
case .UserType(let user):
let userSkill = user.learningSkills[UInt(indexPath.item)] as! UserSkill
skillLocalName = userSkill.localName
}
} else {
skillLocalName = learningSkills[indexPath.item].localName
}
@@ -53,6 +53,12 @@ class ProfileHeaderCell: UICollectionViewCell {
})
}
func configureWithUser(user: User) {
updateAvatarWithAvatarURLString(user.avatarURLString)
// TODO: User Location
}
func updateAvatarWithAvatarURLString(avatarURLString: String) {
avatarImageView.alpha = 0