<commit_before>//
//  PostDesignStudioViewController.swift
//  DesignStudioExpress
//
//  Created by <NAME> on 12/12/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import MHVideoPhotoGallery

class PostDesignStudioViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, MHGalleryDataSource,MHGalleryDelegate {

    @IBOutlet weak var collectionView: UICollectionView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        
        
        self.collectionView.registerClass(MHMediaPreviewCollectionViewCell.self, forCellWithReuseIdentifier: "MHMediaPreviewCollectionViewCell")
        

        // Do any additional setup after loading the view.
    }
    
    // MARK: - UICollectionViewDataSource
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 2
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cellIdentifier = "MHMediaPreviewCollectionViewCell"
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! MHMediaPreviewCollectionViewCell
        
        cell.thumbnail.contentMode = .ScaleAspectFill
        
        cell.thumbnail.image = nil;
        cell.galleryItem = MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image);
        
        return cell;
    }
    
    // MARK: - UICollectionViewDelegate
    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! MHMediaPreviewCollectionViewCell
        let imageView = cell.thumbnail
        let gallery = MHGalleryController(presentationStyle: .ImageViewerNavigationBarShown)
        gallery.UICustomization.showOverView = false
        gallery.galleryItems = [MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image)]
        gallery.presentingFromImageView = imageView
        gallery.presentationIndex = indexPath.row
        //gallery.delegate = self ??
        
        self.presentMHGalleryController(gallery, animated: true, completion: nil)
        
        
    }
    
    // MARK: - MHGalleryDataSource
    
    func itemForIndex(index: Int) -> MHGalleryItem! {
        
        return MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image)<commit_msg>#14 Added callback for closing gallery and fixed bug with setting the placeholder data<commit_after>//
//  PostDesignStudioViewController.swift
//  DesignStudioExpress
//
//  Created by <NAME> on 12/12/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import MHVideoPhotoGallery

class PostDesignStudioViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, MHGalleryDataSource,MHGalleryDelegate {

    @IBOutlet weak var collectionView: UICollectionView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        
        
        self.collectionView.registerClass(MHMediaPreviewCollectionViewCell.self, forCellWithReuseIdentifier: "MHMediaPreviewCollectionViewCell")
        
        // Do any additional setup after loading the view.
    }
    
    // MARK: - UICollectionViewDataSource
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 2
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cellIdentifier = "MHMediaPreviewCollectionViewCell"
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! MHMediaPreviewCollectionViewCell
        
        cell.thumbnail.contentMode = .ScaleAspectFill
        
        cell.thumbnail.image = nil;
        cell.galleryItem = MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image);
        
        return cell;
    }
    
    // MARK: - UICollectionViewDelegate
    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! MHMediaPreviewCollectionViewCell
        let imageView = cell.thumbnail
        let gallery = MHGalleryController(presentationStyle: .ImageViewerNavigationBarShown)
        gallery.UICustomization.showOverView = false
        gallery.galleryItems = [MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image),MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image)]
        gallery.presentingFromImageView = imageView
        gallery.presentationIndex = indexPath.row
        gallery.galleryDelegate = self
        
        
        
        gallery.finishedCallback = { [weak gallery] (currentIndex: Int, image: UIImage!, interactiveTransition: MHTransitionDismissMHGallery!, viewMode: MHGalleryViewMode) -> Void in
            
            let newIndexPath: NSIndexPath = NSIndexPath(forRow: currentIndex, inSection: 0)
            let cellFrame: CGRect = collectionView.collectionViewLayout.layoutAttributesForItemAtIndexPath(newIndexPath)!.frame
            collectionView.scrollRectToVisible(cellFrame, animated: false)
            
            dispatch_async(dispatch_get_main_queue(), {[weak gallery] () -> Void in
                collectionView.reloadItemsAtIndexPaths([newIndexPath])
                collectionView.scrollToItemAtIndexPath(newIndexPath, atScrollPosition: .CenteredHorizontally, animated: false)
                let cell: MHMediaPreviewCollectionViewCell = collectionView.cellForItemAtIndexPath(newIndexPath) as! MHMediaPreviewCollectionViewCell
                
                gallery!.dismissViewControllerAnimated(true, dismissImageView: cell.thumbnail, completion: nil)
            })
        }
        self.presentMHGalleryController(gallery, animated: true, completion: nil)
    }
    
    
    // MARK: - MHGalleryDataSource
    
    func itemForIndex(index: Int) -> MHGalleryItem! {
        
        return MHGalleryItem (URL: "https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300", galleryType: MHGalleryType.Image)
{'fraction_non_alphanumeric': 0.0839662447257384, 'fraction_numerical': 0.020534458509142053, 'mean_word_length': 3.444375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 7, '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': '5830399', 'n_tokens_mistral': 2117, 'n_tokens_neox': 1978, 'n_words': 357}