<commit_before>//
//  ImageFeedCollectionViewCell.swift
//  BluePic
//
//  Created by <NAME> on 12/1/15.
//  Copyright © 2015 MIL. All rights reserved.
//

import UIKit

class ProfileCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var captionLabel: UILabel!
    @IBOutlet weak var photographerNameLabel: UILabel!
    @IBOutlet weak var timeSincePostedLabel: UILabel!
    @IBOutlet weak var moreButton: UIButton!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
    
        // Initialization code
    }
    
    
    
    func setupData(url : String?, image : UIImage?, displayName : String?, timeStamp: Double?, fileName : String?){
        
        
        setImageView(url, fileName: fileName)
        
//        if let img = image {
//            
//            imageView.image = img
//            
//            //timeSincePostedLabel.text = NSLocalizedString("1s", comment: "")
//            
//        }
//        else{
//            if let nsurl = NSURL(string: urlString){
//            
//                imageView.sd_setImageWithURL(nsurl, completed: { _ in
//                
//                
//                
//                })
//            }
//        }
        
        captionLabel.text = displayName?.uppercaseString ?? ""
        
        
        if let tStamp = timeStamp {
            
            timeSincePostedLabel.text = NSDate.timeStringSinceIntervalSinceReferenceDate(tStamp)
            
            
        }
        
        
    }
    
    
    
    func setImageView(url : String?, fileName : String?){
        let urlString = url ?? ""
        
        
        //unwrap fileName and facebook user id to be safe
        if let fName = fileName, let userID = FacebookDataManager.SharedInstance.fbUniqueUserID {
            let id = fName + userID
            
            if let img = CameraDataManager.SharedInstance.picturesTakenDuringAppSessionById[id] {
                
                //set placeholderImage with local copy of image in cache, and try to pull image from url if url is valid
                if let nsurl = NSURL(string: urlString){
                    //                    imageView.sd_setImageWithURL(nsurl, placeholderImage: img)
                    
                    imageView.image = img
                    //downloadImageWithSDWebImage(urlString, id: id)
                    
                    imageView.sd_setImageWithURL(nsurl, placeholderImage: img, completed: { result  in
                        
                        //clear camera data cache since we will be using sdWebImage's cache from now on
                        if result.0 != nil{
                            CameraDataManager.SharedInstance.picturesTakenDuringAppSessionById[id] = nil
                        }
                    })
                }
                    //url is not valid, so set imageView with local copy of image in cache
                else{
                    imageView.image = img
                }
            }
            else{
                if let nsurl = NSURL(string: urlString){
                    imageView.sd_setImageWithURL(nsurl)
                }
            }
        }
            //fileName or facebook user id were nil
        else {
            //set imageView with image from url if url is valid
            if let nsurl = NSURL(string: urlString){
                imageView.sd_setImageWithURL(nsurl)
            }
            
        }
    }
    
    
    
    
    

}
<commit_msg>cleaned up a little bit of code<commit_after>//
//  ImageFeedCollectionViewCell.swift
//  BluePic
//
//  Created by <NAME> on 12/1/15.
//  Copyright © 2015 MIL. All rights reserved.
//

import UIKit

class ProfileCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var captionLabel: UILabel!
    @IBOutlet weak var photographerNameLabel: UILabel!
    @IBOutlet weak var timeSincePostedLabel: UILabel!
    @IBOutlet weak var moreButton: UIButton!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
    
        // Initialization code
    }
    
    
    
    func setupData(url : String?, image : UIImage?, displayName : String?, timeStamp: Double?, fileName : String?){
        
        
        setImageView(url, fileName: fileName)
        
        
        captionLabel.text = displayName?.uppercaseString ?? ""
        
        
        if let tStamp = timeStamp {
            
            timeSincePostedLabel.text = NSDate.timeStringSinceIntervalSinceReferenceDate(tStamp)
            
            
        }
        
        
    }
    
    
    
    func setImageView(url : String?, fileName : String?){
        let urlString = url ?? ""
        
        
        //unwrap fileName and facebook user id to be safe
        if let fName = fileName, let userID = FacebookDataManager.SharedInstance.fbUniqueUserID {
            let id = fName + userID
            
            if let img = CameraDataManager.SharedInstance.picturesTakenDuringAppSessionById[id] {
                
                //set placeholderImage with local copy of image in cache, and try to pull image from url if url is valid
                if let nsurl = NSURL(string: urlString){
                    //                    imageView.sd_setImageWithURL(nsurl, placeholderImage: img)
                    
                    imageView.image = img
                    //downloadImageWithSDWebImage(urlString, id: id)
                    
                    imageView.sd_setImageWithURL(nsurl, placeholderImage: img, completed: { result  in
                        
                        //clear camera data cache since we will be using sdWebImage's cache from now on
                        if result.0 != nil{
                            CameraDataManager.SharedInstance.picturesTakenDuringAppSessionById[id] = nil
                        }
                    })
                }
                    //url is not valid, so set imageView with local copy of image in cache
                else{
                    imageView.image = img
                }
            }
            else{
                if let nsurl = NSURL(string: urlString){
                    imageView.sd_setImageWithURL(nsurl)
                }
            }
        }
            //fileName or facebook user id were nil
        else {
            //set imageView with image from url if url is valid
            if let nsurl = NSURL(string: urlString){
                imageView.sd_setImageWithURL(nsurl)
            }
            
        }
    }
    
    
    
    
    

}

{'fraction_non_alphanumeric': 0.0703276971420021, 'fraction_numerical': 0.0031423013616639233, 'mean_word_length': 1.292967409948542, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6537904', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1682, 'n_words': 446}