<commit_before>//
//  MemesCollectionViewController.swift
//  MemeMe
//
//  Created by <NAME> on 4/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

class MemesCollectionViewController: UICollectionViewController {
    
    @IBOutlet weak var flowLayout: UICollectionViewFlowLayout!
    
    var memes: [Meme] {
        return MemeDataSource.sharedInstance.memes
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.delegate = self
        collectionView?.dataSource = MemeDataSource.sharedInstance
        
        setupCollectionFlow(view.frame.size)
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        collectionView?.reloadData()
    }
}

// MARK: - Flow Layout

extension MemesCollectionViewController : UICollectionViewDelegateFlowLayout{
    
    private func setupCollectionFlow(size: CGSize) {
        
        // This is to fix a bug.
        // Sometimes when on tableview and turn landscape
        // and haven't visited collection view yet, flowLayout
        // will still be nil for some reason. This guard statement fixes it
        guard flowLayout != nil else {
            return
        }
        
        let space: CGFloat = 3.0
        let dimension = (min(size.width,size.width) - (2 * space)) / 3.0
        
        flowLayout.minimumInteritemSpacing = space
        flowLayout.minimumLineSpacing = space
        flowLayout.itemSize = CGSizeMake(dimension, dimension)
        
    }
    
    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        setupCollectionFlow(size)
    }
}

// MARK: - UICollectionViewDelegate

extension MemesCollectionViewController {
    
    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        if let vc = storyboard?.instantiateViewControllerWithIdentifier(Storyboard.ID.DisplayMemeViewController) as? DisplayMemeViewController {
            vc.setMeme(memes[indexPath.row])
            navigationController?.pushViewController(vc, animated: true)
        }
    }
}<commit_msg>Ready for initial submission of MemeMe 2.0.<commit_after>//
//  MemesCollectionViewController.swift
//  MemeMe
//
//  Created by <NAME> on 4/12/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

class MemesCollectionViewController: UICollectionViewController {
    
    @IBOutlet weak var flowLayout: UICollectionViewFlowLayout!
    
    var memes: [Meme] {
        return MemeDataSource.sharedInstance.memes
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.delegate = self
        collectionView?.dataSource = MemeDataSource.sharedInstance
        
        setupCollectionFlow(view.frame.size)
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        collectionView?.reloadData()
    }
}

// MARK: - Flow Layout

extension MemesCollectionViewController : UICollectionViewDelegateFlowLayout{
    
    private func setupCollectionFlow(size: CGSize) {
        
        // This is to fix a bug.
        // Sometimes when on tableview and turn landscape
        // and haven't visited collection view yet, flowLayout
        // will still be nil for some reason. This guard statement fixes it
        guard flowLayout != nil else {
            return
        }
        
        let space: CGFloat = 3.0
        let dimension = (min(size.width,size.width) - (2 * space)) / 3.0
        
        flowLayout.minimumInteritemSpacing = space
        flowLayout.minimumLineSpacing = space
        flowLayout.itemSize = CGSizeMake(dimension, dimension)
        
    }
    
    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        setupCollectionFlow(size)
    }
}

// MARK: - UICollectionViewDelegate

extension MemesCollectionViewController {

    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        if let vc = storyboard?.instantiateViewControllerWithIdentifier(Storyboard.ID.DisplayMemeViewController) as? DisplayMemeViewController {
            vc.setMeme(memes[indexPath.row])
            navigationController?.pushViewController(vc, animated: true)
        }
    }
}
{'fraction_non_alphanumeric': 0.07647323436797121, 'fraction_numerical': 0.006747638326585695, 'mean_word_length': 2.7654530059271805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6432737', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1169, 'n_words': 282}