<commit_before>//
//  SearchViewController.swift
//  jphacks
//
//  Created by 内村祐之 on 2015/11/28.
//  Copyright © 2015年 at. All rights reserved.
//
import Foundation
import UIKit
import CoreLocation

class SearchViewController: BaseViewController {
    
    @IBOutlet weak var startLocationButton: UIButton!
    @IBOutlet weak var targetLocationButton: UIButton!
    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var toiletToggle: SpotOptionButton!
    @IBOutlet weak var nightSpotsToggle: SpotOptionButton!
    @IBOutlet weak var monumentsToggle: SpotOptionButton!
    @IBOutlet weak var structureToggle: SpotOptionButton!
    @IBOutlet weak var convinienceToggle: SpotOptionButton!
    @IBOutlet weak var theatersToggle: SpotOptionButton!

    var splashImageView: UIImageView!

    let locationManager = CLLocationManager()
    

    
    
    @IBAction func GoToMapView(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "MapView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! MapViewController

        controller.spots = SpotManager.sharedController.sightseeingSpotRepository.spots
    
        var viaLocations: [CLLocationCoordinate2D] = []
        if let spot = SpotManager.startSpot {
            viaLocations.append(CLLocationCoordinate2D(latitude: spot.latitude, longitude: spot.longitude))
        } else {
            viaLocations.append(locationManager.location!.coordinate)
        }
        if let spot = SpotManager.targetSpot {
            viaLocations.append(CLLocationCoordinate2D(latitude: spot.latitude, longitude: spot.longitude))
        }
        controller.viaLocations = viaLocations
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 位置情報に関して権限をもらう
        locationManager.delegate = self
        let status = CLLocationManager.authorizationStatus()
        if(status == CLAuthorizationStatus.NotDetermined) {
            locationManager.requestAlwaysAuthorization()
        }
        
        let header = SearchHeaderView()
        header.setup(CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.height, self.view.bounds.width, 50))
        self.view.addSubview(header)
        
        searchButton.layer.cornerRadius = 60
        
        
        let frame = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y, width: self.view.frame.size.width + 100, height: self.view.frame.size.height + 100)
        self.splashImageView = UIImageView(frame: frame)
        self.splashImageView.center = self.view.center
        self.splashImageView.image = UIImage(named: "Loading")
        self.view.addSubview(self.splashImageView)
    }
    
    override func viewWillAppear(animated: Bool) {
        startLocationButton.setTitle(SpotManager.startSpot?.name ?? "(現在地)", forState: .Normal)
        targetLocationButton.setTitle(SpotManager.targetSpot?.name ?? "(タップして設定)", forState: .Normal)
    }
    
    override func viewDidAppear(animated: Bool) {
        UIView.animateWithDuration(0.3,
            delay: 1.0,
            options: UIViewAnimationOptions.CurveEaseOut,
            animations: { () in
                self.splashImageView.transform = CGAffineTransformMakeScale(0.9, 0.9)
            }, completion: nil
        )
        
        UIView.animateWithDuration(0.2,
            delay: 1.3,
            options: UIViewAnimationOptions.CurveEaseOut,
            animations: { () in
                self.splashImageView.transform = CGAffineTransformMakeScale(1.2, 1.2)
                self.splashImageView.alpha = 0
            }, completion: { (Bool) in
                self.splashImageView.removeFromSuperview()
        })        
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    @IBAction func SetStartLocation(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "SpotSetView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! SpotSetViewController
        controller.completion = {(spot:Spot?) -> Void in
            SpotManager.startSpot = spot
        }
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
    @IBAction func SetTargetLocation(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "SpotSetView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! SpotSetViewController
        controller.completion = {(spot:Spot?) -> Void in
            SpotManager.targetSpot = spot
        }
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
}


extension SearchViewController: CLLocationManagerDelegate {
    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        switch (status) {
        case .NotDetermined:
            print("NotDetermined")
        case .Restricted:
            print("Restricted")
        case .Denied:
            print("Denied")
        case .AuthorizedAlways:
            print("AuthorizedAlways")
            locationManager.desiredAccuracy = kCLLocationAccuracyBest// 取得精度の設定.
            locationManager.distanceFilter = 1// 取得頻度の設定.
            locationManager.startUpdatingLocation()
        case .AuthorizedWhenInUse:
            print("AuthorizedWhenInUse")
        }
    }
    
    // 位置情報がupdateされた時
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print("\(manager.location?.coordinate.latitude),\(manager.location?.coordinate.longitude)")
    }
    
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print(error)
    }
}

<commit_msg>未設定でも落ちない<commit_after>//
//  SearchViewController.swift
//  jphacks
//
//  Created by 内村祐之 on 2015/11/28.
//  Copyright © 2015年 at. All rights reserved.
//
import Foundation
import UIKit
import CoreLocation

class SearchViewController: BaseViewController {
    
    @IBOutlet weak var startLocationButton: UIButton!
    @IBOutlet weak var targetLocationButton: UIButton!
    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var toiletToggle: SpotOptionButton!
    @IBOutlet weak var nightSpotsToggle: SpotOptionButton!
    @IBOutlet weak var monumentsToggle: SpotOptionButton!
    @IBOutlet weak var structureToggle: SpotOptionButton!
    @IBOutlet weak var convinienceToggle: SpotOptionButton!
    @IBOutlet weak var theatersToggle: SpotOptionButton!

    var splashImageView: UIImageView!

    let locationManager = CLLocationManager()
    

    
    
    @IBAction func GoToMapView(sender: AnyObject) {
        var viaLocations: [CLLocationCoordinate2D] = []
        if let spot = SpotManager.startSpot {
            viaLocations.append(CLLocationCoordinate2D(latitude: spot.latitude, longitude: spot.longitude))
        } else {
            if let coordinate = locationManager.location?.coordinate {
                viaLocations.append(coordinate)
            } else {
                let alertViewController = UIAlertController(title: "現在地", message: "位置情報を取得できません", preferredStyle: UIAlertControllerStyle.Alert)
                self.presentViewController(alertViewController, animated: true, completion: { dispatch_after(2, dispatch_get_main_queue(), {self.dismissViewControllerAnimated(true, completion: nil)}) })
                return
            }
        }
        if let spot = SpotManager.targetSpot {
            viaLocations.append(CLLocationCoordinate2D(latitude: spot.latitude, longitude: spot.longitude))
        } else {
            let alertViewController = UIAlertController(title: "未入力", message: "目的地を設定", preferredStyle: UIAlertControllerStyle.Alert)
            self.presentViewController(alertViewController, animated: true, completion: { dispatch_after(2, dispatch_get_main_queue(), {self.dismissViewControllerAnimated(true, completion: nil)}) })
            return
        }
        
        
        
        let storyboard = UIStoryboard(name: "MapView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! MapViewController
        controller.spots = SpotManager.sharedController.sightseeingSpotRepository.spots
        controller.viaLocations = viaLocations
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 位置情報に関して権限をもらう
        locationManager.delegate = self
        let status = CLLocationManager.authorizationStatus()
        if(status == CLAuthorizationStatus.NotDetermined) {
            locationManager.requestAlwaysAuthorization()
        }
        
        let header = SearchHeaderView()
        header.setup(CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.height, self.view.bounds.width, 50))
        self.view.addSubview(header)
        
        searchButton.layer.cornerRadius = 60
        
        
        let frame = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y, width: self.view.frame.size.width + 100, height: self.view.frame.size.height + 100)
        self.splashImageView = UIImageView(frame: frame)
        self.splashImageView.center = self.view.center
        self.splashImageView.image = UIImage(named: "Loading")
        self.view.addSubview(self.splashImageView)
    }
    
    override func viewWillAppear(animated: Bool) {
        startLocationButton.setTitle(SpotManager.startSpot?.name ?? "(現在地)", forState: .Normal)
        targetLocationButton.setTitle(SpotManager.targetSpot?.name ?? "(タップして設定)", forState: .Normal)
    }
    
    override func viewDidAppear(animated: Bool) {
        UIView.animateWithDuration(0.3,
            delay: 1.0,
            options: UIViewAnimationOptions.CurveEaseOut,
            animations: { () in
                self.splashImageView.transform = CGAffineTransformMakeScale(0.9, 0.9)
            }, completion: nil
        )
        
        UIView.animateWithDuration(0.2,
            delay: 1.3,
            options: UIViewAnimationOptions.CurveEaseOut,
            animations: { () in
                self.splashImageView.transform = CGAffineTransformMakeScale(1.2, 1.2)
                self.splashImageView.alpha = 0
            }, completion: { (Bool) in
                self.splashImageView.removeFromSuperview()
        })        
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    @IBAction func SetStartLocation(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "SpotSetView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! SpotSetViewController
        controller.completion = {(spot:Spot?) -> Void in
            SpotManager.startSpot = spot
        }
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
    @IBAction func SetTargetLocation(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "SpotSetView", bundle: nil)
        let controller = storyboard.instantiateInitialViewController() as! SpotSetViewController
        controller.completion = {(spot:Spot?) -> Void in
            SpotManager.targetSpot = spot
        }
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
}


extension SearchViewController: CLLocationManagerDelegate {
    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        switch (status) {
        case .NotDetermined:
            print("NotDetermined")
        case .Restricted:
            print("Restricted")
        case .Denied:
            print("Denied")
        case .AuthorizedAlways:
            print("AuthorizedAlways")
            locationManager.desiredAccuracy = kCLLocationAccuracyBest// 取得精度の設定.
            locationManager.distanceFilter = 1// 取得頻度の設定.
            locationManager.startUpdatingLocation()
        case .AuthorizedWhenInUse:
            print("AuthorizedWhenInUse")
        }
    }
    
    // 位置情報がupdateされた時
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print("\(manager.location?.coordinate.latitude),\(manager.location?.coordinate.longitude)")
    }
    
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print(error)
    }
}


{'fraction_non_alphanumeric': 0.08863243837337102, 'fraction_numerical': 0.00706547338671691, 'mean_word_length': 2.7655926692284956, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1374246', 'n_tokens_mistral': 3677, 'n_tokens_neox': 3461, 'n_words': 676}