<commit_before>//
//  RequestViewController.swift
//  Schnell
//
//  Created by <NAME> on 26/01/2016.
//  Copyright © 2016 Parse. All rights reserved.
//

import UIKit
import MapKit

class RequestViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet weak var map: MKMapView!

    var reqLocation = CLLocationCoordinate2DMake(0, 0)
    var reqRider    = "(None)"

    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
//        locationManager.startUpdatingLocation()

        setMapCentre()
    }

    @IBAction func riderPressed(sender: AnyObject) {
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

    func setMapCentre() {
        let span    = MKCoordinateSpanMake(0.01, 0.01)
        let region  = MKCoordinateRegionMake(reqLocation, span)

        self.map.setRegion(region, animated: true)
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}<commit_msg>Pressing the take rider button now marks the request as in progress and starts navigation.<commit_after>//
//  RequestViewController.swift
//  Schnell
//
//  Created by <NAME> on 26/01/2016.
//  Copyright © 2016 Parse. All rights reserved.
//

import UIKit
import MapKit
import Parse

class RequestViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet weak var map: MKMapView!

    var reqLocation = CLLocationCoordinate2DMake(0, 0)
    var reqRider    = "(None)"

    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        setMapCentre()
    }

    @IBAction func riderPressed(sender: AnyObject) {
        let query = PFQuery(className: "RideRequest")

        query.whereKey("username", equalTo: reqRider)

        query.findObjectsInBackgroundWithBlock({
            (objects, error) -> Void in

            if error == nil {
                let objects = objects as [PFObject]!

                for object in objects {
                    object["driverResponded"] = PFUser.currentUser()?.username
                    object.saveInBackground()
                }

                let reqCLLoc = CLLocation(latitude: self.reqLocation.latitude, longitude: self.reqLocation.longitude)

                CLGeocoder().reverseGeocodeLocation(reqCLLoc, completionHandler: {
                    (places, error) -> Void in

                    if error == nil {
                        if places!.count > 0 {
                            if let dest = places![0] as? CLPlacemark {
                                let mkpDest = MKPlacemark(placemark: dest)
                                let mapItem = MKMapItem(placemark: mkpDest)

                                mapItem.name = self.reqRider

                                let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]

                                mapItem.openInMapsWithLaunchOptions(launchOptions)
                            }
                            else {
                                print("Cannot downcast")
                            }
                        }
                        else {
                            print("No placemarks returned")
                        }
                    }
                    else {
                        print(error?.localizedDescription)
                    }
                })
            }
            else {
                print(error?.localizedDescription)
            }
        })
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

    func setMapCentre() {
        let span    = MKCoordinateSpanMake(0.01, 0.01)
        let region  = MKCoordinateRegionMake(reqLocation, span)

        self.map.setRegion(region, animated: true)

        let ann = MKPointAnnotation()
        ann.coordinate = reqLocation
        ann.title = "'\(reqRider) Location"
        self.map.addAnnotation(ann)
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
{'fraction_non_alphanumeric': 0.07859565130660283, 'fraction_numerical': 0.008777179333732297, 'mean_word_length': 1.8456299659477866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5036466', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1245, 'n_words': 332}