diff --git a/Yep/ViewControllers/Discover/DiscoverViewController.swift b/Yep/ViewControllers/Discover/DiscoverViewController.swift index d9f81c9d..678c65bb 100644 --- a/Yep/ViewControllers/Discover/DiscoverViewController.swift +++ b/Yep/ViewControllers/Discover/DiscoverViewController.swift @@ -203,9 +203,6 @@ extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewData performSegueWithIdentifier("showProfile", sender: indexPath) } - - - } diff --git a/Yep/Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift b/Yep/Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift index d8034f9b..68fb8d27 100644 --- a/Yep/Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift +++ b/Yep/Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift @@ -9,6 +9,8 @@ import UIKit class DiscoverCardUserCell: UICollectionViewCell { + + let skillCellIdentifier = "SkillCell" @IBOutlet weak var avatarImageView: UIImageView! @@ -18,6 +20,10 @@ class DiscoverCardUserCell: UICollectionViewCell { @IBOutlet weak var userSkillsCollectionView: UICollectionView! + var discoveredUser: DiscoveredUser? + + let skillTextAttributes = [NSFontAttributeName: UIFont.skillTextFont()] + override func awakeFromNib() { super.awakeFromNib() // Initialization code @@ -27,11 +33,17 @@ class DiscoverCardUserCell: UICollectionViewCell { contentView.layer.masksToBounds = true avatarImageView.contentMode = UIViewContentMode.ScaleAspectFill avatarImageView.clipsToBounds = true + + userSkillsCollectionView.delegate = self + userSkillsCollectionView.dataSource = self + + userSkillsCollectionView.registerNib(UINib(nibName: skillCellIdentifier, bundle: nil), forCellWithReuseIdentifier: skillCellIdentifier) } func configureWithDiscoveredUser(discoveredUser: DiscoveredUser, collectionView: UICollectionView, indexPath: NSIndexPath) { // let radius = min(CGRectGetWidth(avatarImageView.bounds), CGRectGetHeight(avatarImageView.bounds)) * 0.5 + self.discoveredUser = discoveredUser let avatarURLString = discoveredUser.avatarURLString @@ -53,6 +65,47 @@ class DiscoverCardUserCell: UICollectionViewCell { usernameLabel.text = discoveredUser.nickname + userSkillsCollectionView.reloadData() + } } + +extension DiscoverCardUserCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { + + func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + if let discoveredUser = discoveredUser { + return discoveredUser.masterSkills.count + } else { + return 0 + } + } + + + func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { + if let discoveredUser = discoveredUser { + + let skillLocalName = discoveredUser.masterSkills[indexPath.row].localName ?? "" + + let rect = skillLocalName.boundingRectWithSize(CGSize(width: CGFloat(FLT_MAX), height: SkillCell.height), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: skillTextAttributes, context: nil) + + return CGSize(width: rect.width + 24, height: SkillCell.height) + } else { + return CGSizeZero + } + } + + func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + + if let discoveredUser = discoveredUser { + let cell = collectionView.dequeueReusableCellWithReuseIdentifier(skillCellIdentifier, forIndexPath: indexPath) as! SkillCell + + cell.skillLabel.text = discoveredUser.masterSkills[indexPath.row].localName ?? "" + + return cell + } else { + return UICollectionViewCell() + } + + } +}