<file_sep>//
//  Movie+CoreDataProperties.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 23/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//
//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
//  to delete and recreate this implementation file for your updated model.
//

import Foundation
import CoreData

extension Movie {

    @NSManaged var desc: String?
    @NSManaged var image: NSData?
    @NSManaged var link: String?
    @NSManaged var title: String?
    @NSManaged var year: String?
    @NSManaged var rated: String?
    @NSManaged var director: String?
    @NSManaged var imdbRating: String?
    @NSManaged var genre: String?

}
<file_sep>//
//  SearchBar.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 23/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit

class SearchBar: UISearchBar {
    
    var preferredFont: UIFont!
    var preferredTextColor: UIColor!
    
    init(frame: CGRect, font: UIFont, textColor: UIColor) {
        super.init(frame: frame)
        
        self.frame = frame
        preferredFont = font
        preferredTextColor = textColor
        
        searchBarStyle = UISearchBarStyle.Prominent
        translucent = false

        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func indexOfSearchFieldInSubviews() -> Int! {
        var index: Int!
        let searchBarView = subviews[0] as! UIView
        
        for var i=0; i<searchBarView.subviews.count; ++i {
            if searchBarView.subviews[i].isKindOfClass(UITextField) {
                index = i
                break
            }
        }
        
        return index
    }
    
  

}
<file_sep>//
//  MovieCell.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 15/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit
import Foundation
import GPUImage

class MovieCell: UITableViewCell {
    
    @IBOutlet weak var movieTitle: UILabel!
    @IBOutlet weak var movieImage: UIImageView!

    override func awakeFromNib() {
        super.awakeFromNib()
        
        movieImage.clipsToBounds = true
        
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func configureCell(movie: Movie) {
        movieTitle.text = movie.title
        
        let inputImage = movie.getMovieImg()
        
        let blurFilter = GPUImageGaussianBlurFilter()
        let monochrome = GPUImageGrayscaleFilter()
        let filterGroup = GPUImageFilterGroup()
        blurFilter.blurRadiusInPixels = 10
        
        filterGroup.addFilter(blurFilter)
        filterGroup.addFilter(monochrome)
        
        monochrome.addTarget(blurFilter)
        monochrome.useNextFrameForImageCapture()
        
        let outputImage = blurFilter.imageByFilteringImage(inputImage)
        
        movieImage.image = outputImage
        }
    
 
    

}
<file_sep>//
//  DetailedViewVC.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 16/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit
import CoreData
import Spring
import UICountingLabel

class DetailedViewVC: UIViewController {
    
    @IBOutlet weak var movieDesc: UILabel!
    @IBOutlet weak var movieImg: UIImageView!
    @IBOutlet weak var viewBg: UIImageView!
    @IBOutlet weak var movieImdb: UILabel!
    @IBOutlet weak var movieYear: UILabel!
    @IBOutlet weak var movieRating: UILabel!
    @IBOutlet weak var movieDirector: UILabel!
    
    var movie: Movie?

    override func viewDidLoad() {
        super.viewDidLoad()
        self.viewBg.image = movie?.getMovieImg()
        self.movieImg.image = movie?.getMovieImg()
        self.movieImg.layer.cornerRadius = movieImg.frame.size.width / 2
        self.movieImg.clipsToBounds = true
        self.movieImg.layer.borderWidth = 5
        self.movieImg.layer.borderColor = UIColor.whiteColor().CGColor
        self.movieImg.layer.shadowColor = UIColor(red: 157.0 / 255.0, green: 157.0 / 255.0, blue: 157.0 / 255.0, alpha: 0.5).CGColor
        self.movieImg.layer.shadowOpacity = 0.8
        self.movieImg.layer.shadowRadius = 5.0
        self.movieImg.layer.shadowOffset = CGSizeMake(0.0, 2.0)
        
        
        if let dir = movie?.director  {
            self.movieDirector.text = dir
        } else {
            self.movieDirector.text = "N/A"
        }
        
        if let rate = movie?.rated {
            self.movieRating.text = rate
        } else {
            self.movieRating.text = "N/A"
        }
        
        if let year = movie?.year {
            self.movieYear.text = year
        } else {
            self.movieYear.text = "N/A"
        }
        
        if let desc = movie?.desc {
            self.movieDesc.text = desc
        }else {
            self.movieDesc.text = "N/A"
        }
        
        if let imdb = movie?.imdbRating {
            self.movieImdb.text = imdb
        } else {
            self.movieImdb.text = "N/A"
        }
        
        
        blurCI()
        
     }
    

    func blurCI() {
        let darkBlur = UIBlurEffect(style: UIBlurEffectStyle.Dark)
        let blurView = UIVisualEffectView(effect: darkBlur)
        blurView.frame = self.view.frame
        viewBg.addSubview(blurView)
    }
    
    @IBAction func dismiss(sender: AnyObject){
        dismissViewControllerAnimated(true, completion: nil)
    }

    

}
<file_sep>//
//  NavigationBar.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 17/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit

class NavigationBar: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
        self.navigationBar.shadowImage = UIImage()
        self.navigationBar.translucent = true
    }

    



}
<file_sep>//
//  AddMovieButton.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 06/03/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit

class AddMovieButton: UIButton {

    override func awakeFromNib() {
        let shadowColor: CGFloat = 0.0 / 255.0
        layer.cornerRadius = 10.0
        layer.shadowColor = UIColor(red: shadowColor, green: shadowColor, blue: shadowColor, alpha: 0.5).CGColor
        layer.shadowOpacity = 0.5
        layer.shadowRadius = 2.0
        layer.shadowOffset = CGSizeMake(0.0, 2.0)
    }

}
<file_sep>//
//  addMovieVC.swift
//  SeeMe
//
//  Created by Leandersson, Johan (Grey London) on 15/02/2016.
//  Copyright © 2016 Leandersson, Johan (Grey London). All rights reserved.
//

import UIKit
import CoreData
import Alamofire
import SwiftyJSON

class addMovieVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UISearchBarDelegate {


    @IBOutlet weak var movieTitle: UILabel!
    @IBOutlet weak var movieImg: UIImageView!
    @IBOutlet weak var searchBar: UISearchBar!
    
    var imagePicker: UIImagePickerController!
    var imdbRating = ""
    var movieYear = ""
    var movieRating = ""
    var movieDirector = ""
    var movieDesc = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        searchBar.delegate = self
        imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        movieImg.layer.cornerRadius = 5.0
        movieImg.clipsToBounds = true
        movieTitle.text = ""
        
        self.movieImg.layer.cornerRadius = movieImg.frame.size.width / 2
        self.movieImg.clipsToBounds = true
        
    }


    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        imagePicker.dismissViewControllerAnimated(true, completion: nil)
        movieImg.image = image
    }
    

    
    @IBAction func addImg(sender: AnyObject) {
        presentViewController(imagePicker, animated: true, completion: nil)
    }
    
    @IBAction func addMovie(sender: AnyObject){
        if let title = movieTitle.text where title != "" {
            let app = UIApplication.sharedApplication().delegate as! AppDelegate
            let context = app.managedObjectContext
            let entity = NSEntityDescription.entityForName("Movie", inManagedObjectContext: context)!
            let movie = Movie(entity: entity, insertIntoManagedObjectContext: context)
            movie.title = title
            movie.desc = movieDesc
            movie.setMovieImage(movieImg.image!)
            movie.imdbRating = imdbRating
            movie.year = movieYear
            movie.rated = movieRating
            movie.director = movieDirector
            
            
            context.insertObject(movie)
            
                do {
                    try context.save()
                } catch {
                    print("Could not save movie")
                }
            
            dismissViewControllerAnimated(true, completion: nil)
        }
    }
    
    @IBAction func dismiss(sender: AnyObject){
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        movieTitle.resignFirstResponder()
        return true
    }
    
    func searchIMDB(){
        
        if let search = searchBar.text {
            
            let spaceless = search.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
            let url = NSURL(string: "http://www.omdbapi.com/?t=\(spaceless)&y=&plot=short&r=json")!
            
            Alamofire.request(.GET, url).responseJSON(completionHandler: { (response: Response<AnyObject, NSError>) -> Void in
                let result = response.result
                if let JSON = result.value as? Dictionary<String, String> {
                    
                    if let title = JSON["Title"] {
                        self.movieTitle.text = title.uppercaseString
                    }
                    
                    if let desc = JSON["Plot"] {
                        self.movieDesc = desc
                    }
                    
                    if let imdb = JSON["imdbRating"] {
                        self.imdbRating = imdb
                    }
                    
                    if let year = JSON["Year"] {
                        self.movieYear = year
                    }
                    
                    if let dir = JSON["Director"] {
                        self.movieDirector = dir
                    }
                    
                    if let rate = JSON["Rated"] {
                        self.movieRating = rate
                    }
                    
                    if let image = JSON["Poster"] {
                        
                        if image != "N/A"{
                            let url = NSURL(string: image)!
                            let data = NSData(contentsOfURL: url)!
                            let moviePoster = UIImage(data: data)
                            self.movieImg.image = moviePoster
                        } else {
                            self.movieImg.image = UIImage(named: "noposter")
                        }
                        
                    }
                    
                }
            })
            
        }
        
    }
    
    
    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        
        searchIMDB()
        searchBar.resignFirstResponder()
        searchBar.text = ""
        
    }
    
    
    func userTappedInView(recognizer: UITapGestureRecognizer)
    {
        
        self.searchBar.resignFirstResponder()
        
    }
    
    
   
    
    
    



}
