<commit_before>//
//  ViewController.swift
//  STLocationRequest
//
//  Created by <NAME> on 12/03/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import CoreLocation
import STLocationRequest

/// Example application ViewController to present the STLocationRequestController
class ViewController: UIViewController {
    
    // MARK: - IBOutlets
    
    /// Storyboard IBOutlet for the Request Location Button
    @IBOutlet weak var requestLocationButton: UIButton!
    
    // MARK: - Properties
    
    /// Initialize CLLocationManager
    let locationManager = CLLocationManager()
    
    // MARK: - View-Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Intialize the locationManager
        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.distanceFilter = kCLDistanceFilterNone
    }
    
    // MARK: - IBActions
    
    /// requestLocationButtonTouched Method
    @IBAction func requestLocationButtonTouched(_ sender: UIButton) {
        if CLLocationManager.locationServicesEnabled() {
            if CLLocationManager.authorizationStatus() == .denied {
                // Location Services are denied
                print("Location Services are denied")
            } else {
                if CLLocationManager.authorizationStatus() == .notDetermined{
                    // The user has never been asked about his location show the locationRequest Screen
                    // Just play around with the setMapViewAlphaValue and setBackgroundViewColor parameters, to match with your design of your app
                    // Also you can initialize an STLocationRequest Object and set all attributes
                    // and at the end call presentLocationRequestController
                    self.presentLocationRequestController()
                } else {
                    // The user has already allowed your app to use location services
                    self.locationManager.startUpdatingLocation()
                }
            }
        } else {
            // Location Services are disabled
            print("Location Services are disabled")
        }
    }
    
    // MARK: - Present STLocationRequestController
    
    /// Initialize and present STLocationRequestController
    func presentLocationRequestController(){
        var configuration = STLocationRequestController.Configuration()
        configuration.titleText = "We need your location for some awesome features"
        configuration.allowButtonTitle = "Alright"
        configuration.notNowButtonTitle = "Not now"
        configuration.mapViewAlpha = 0.9
        configuration.backgroundColor = UIColor.lightGray
        configuration.authorizeType = .requestWhenInUseAuthorization
        let locationRequestController = STLocationRequestController(configuration: configuration)
        locationRequestController.delegate = self
        locationRequestController.present(onViewController: self)
    }

}

// MARK: - STLocationRequestControllerDelegate

extension ViewController: STLocationRequestControllerDelegate {
    
    /// STLocationRequest Delegate Methods
    func locationRequestControllerDidChange(_ event: STLocationRequestController.Event) {
        switch event {
        case .locationRequestAuthorized:
            print("The user accepted the use of location services")
            self.locationManager.startUpdatingLocation()
            break
        case .locationRequestDenied:
            print("The user denied the use of location services")
            break
        case .notNowButtonTapped:
            print("The Not now button was tapped")
            break
        case .didPresented:
            print("STLocationRequestController did presented")
            break
        case .didDisappear:
            print("STLocationRequestController did disappear")
            break
        }
    }
    
}

// MARK: - CLLocationManagerDelegate

extension ViewController: CLLocationManagerDelegate {
    
    /// CLLocationManagerDelegate DidFailWithError Methods
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("Error. The Location couldn't be found. \(error)")
    }
    
    /// CLLocationManagerDelegate didUpdateLocations Methods
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        self.locationManager.stopUpdatingLocation()<commit_msg>Updated example Application<commit_after>//
//  ViewController.swift
//  STLocationRequest
//
//  Created by <NAME> on 12/03/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import CoreLocation
import STLocationRequest

/// Example application ViewController to present the STLocationRequestController
class ViewController: UIViewController {
    
    // MARK: - IBOutlets
    
    /// Storyboard IBOutlet for the Request Location Button
    @IBOutlet weak var requestLocationButton: UIButton!
    
    // MARK: - Properties
    
    /// Initialize CLLocationManager
    let locationManager = CLLocationManager()
    
    // MARK: - View-Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Intialize the locationManager
        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.distanceFilter = kCLDistanceFilterNone
    }
    
    // MARK: - IBActions
    
    /// requestLocationButtonTouched Method
    @IBAction func requestLocationButtonTouched(_ sender: UIButton) {
        if CLLocationManager.locationServicesEnabled() {
            if CLLocationManager.authorizationStatus() == .denied {
                // Location Services are denied
                print("Location Services are denied")
            } else {
                if CLLocationManager.authorizationStatus() == .notDetermined{
                    // The user has never been asked about his location show the locationRequest Screen
                    // Just play around with the setMapViewAlphaValue and setBackgroundViewColor parameters, to match with your design of your app
                    // Also you can initialize an STLocationRequest Object and set all attributes
                    // and at the end call presentLocationRequestController
                    self.presentLocationRequestController()
                } else {
                    // The user has already allowed your app to use location services
                    self.locationManager.startUpdatingLocation()
                }
            }
        } else {
            // Location Services are disabled
            print("Location Services are disabled")
        }
    }
    
    // MARK: - Present STLocationRequestController
    
    /// Initialize and present STLocationRequestController
    func presentLocationRequestController(){
        // Initialize STLocationRequestController with Configuration
        let locationRequestController = STLocationRequestController { (config) in
            config.titleText = "We need your location for some awesome features"
            config.allowButtonTitle = "Alright"
            config.notNowButtonTitle = "Not now"
            config.mapViewAlpha = 0.9
            config.backgroundColor = UIColor.lightGray
            config.authorizeType = .requestWhenInUseAuthorization
        }
        // Set onChange
        locationRequestController.onChange = { (event) in
            switch event {
            case .locationRequestAuthorized:
                print("The user accepted the use of location services")
                self.locationManager.startUpdatingLocation()
                break
            case .locationRequestDenied:
                print("The user denied the use of location services")
                break
            case .notNowButtonTapped:
                print("The Not now button was tapped")
                break
            case .didPresented:
                print("STLocationRequestController did presented")
                break
            case .didDisappear:
                print("STLocationRequestController did disappear")
                break
            }
        }
        // Present STLocationRequestController
        locationRequestController.present(onViewController: self)
        
    }

}

// MARK: - CLLocationManagerDelegate

extension ViewController: CLLocationManagerDelegate {
    
    /// CLLocationManagerDelegate DidFailWithError Methods
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("Error. The Location couldn't be found. \(error)")
    }
    
    /// CLLocationManagerDelegate didUpdateLocations Methods
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        self.locationManager.stopUpdatingLocation()
{'fraction_non_alphanumeric': 0.06312143894536923, 'fraction_numerical': 0.003128142107027148, 'mean_word_length': 2.298452468680914, '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': '405491', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1973, 'n_words': 584}