<commit_before>//
//  LoginViewController.swift
//  iEMI
//
//  Created by <NAME> on 2/2/15.
//  Copyright (c) 2015 Rowies. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController, UITextFieldDelegate {
    
    @IBOutlet private weak var scrollView: UIScrollView!
    @IBOutlet private weak var licensePlateTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    @IBOutlet private weak var loginButton: UIButton!
    @IBOutlet private weak var loadingSpinner: UIActivityIndicatorView!
    @IBOutlet private weak var errorLabel: UILabel!
    
    let service: LoginService = LoginEMIService()
    let licensePlate = LicensePlate()
    let settings = Settings()
    
    private let kShowTabBarViewControllerSegue: String = "showTabBarViewController"
    
    //MARK: - View controller lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        self.showLoadingUI(false)
        self.licensePlateTextField.text = self.licensePlate.currentLicensePlate
        self.passwordTextField.text = ""

        if  (self.licensePlate.currentLicensePlate != nil) {

            if (settings.autoLogin) {
               self.getSessionCookie()
            } else {
                self.passwordTextField.becomeFirstResponder()
            }
        }
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"keyboardWillHide", name: UIKeyboardWillHideNotification, object: nil)
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
    }
    
    func showLoadingUI(loading:Bool) {
        
        if loading {
            self.loginButton.enabled = false
            self.licensePlateTextField.enabled = false
            self.passwordTextField.enabled = false
            self.loadingSpinner.hidden = false
            self.loadingSpinner.startAnimating()
            self.errorLabel.hidden = true
        } else {
            self.loginButton.enabled = true
            self.licensePlateTextField.enabled = true
            self.passwordTextField.enabled = true
            self.loadingSpinner.stopAnimating()
            self.errorLabel.hidden = true
        }
    }
    
    //MARK: - Keyboard show/hide notifications
    
    func keyboardWillShow() {
        
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0)
        self.scrollView.setContentOffset(CGPointMake(0, 50), animated: true)
    }
    
    func keyboardWillHide() {
        
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0)
        self.scrollView.setContentOffset(CGPointMake(0, 0), animated: true)
    }
    
    //MARK: - UITextFieldDelegate
    
    func textFieldDidBeginEditing(textField: UITextField) {
        self.errorLabel.hidden = true
    }
    
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        
        if textField == self.licensePlateTextField {
            self.passwordTextField.becomeFirstResponder()
        }
        if textField == self.passwordTextField {
            textField.resignFirstResponder()
            self.loginTouched()<commit_msg>using CGPointZer and UIEdgeInsetsZero<commit_after>//
//  LoginViewController.swift
//  iEMI
//
//  Created by <NAME> on 2/2/15.
//  Copyright (c) 2015 Rowies. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController, UITextFieldDelegate {
    
    @IBOutlet private weak var scrollView: UIScrollView!
    @IBOutlet private weak var licensePlateTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    @IBOutlet private weak var loginButton: UIButton!
    @IBOutlet private weak var loadingSpinner: UIActivityIndicatorView!
    @IBOutlet private weak var errorLabel: UILabel!
    
    let service: LoginService = LoginEMIService()
    let licensePlate = LicensePlate()
    let settings = Settings()
    
    private let kShowTabBarViewControllerSegue: String = "showTabBarViewController"
    
    //MARK: - View controller lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        self.showLoadingUI(false)
        self.licensePlateTextField.text = self.licensePlate.currentLicensePlate
        self.passwordTextField.text = ""

        if  (self.licensePlate.currentLicensePlate != nil) {

            if (settings.autoLogin) {
               self.getSessionCookie()
            } else {
                self.passwordTextField.becomeFirstResponder()
            }
        }
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"keyboardWillHide", name: UIKeyboardWillHideNotification, object: nil)
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
    }
    
    func showLoadingUI(loading:Bool) {
        
        if loading {
            self.loginButton.enabled = false
            self.licensePlateTextField.enabled = false
            self.passwordTextField.enabled = false
            self.loadingSpinner.hidden = false
            self.loadingSpinner.startAnimating()
            self.errorLabel.hidden = true
        } else {
            self.loginButton.enabled = true
            self.licensePlateTextField.enabled = true
            self.passwordTextField.enabled = true
            self.loadingSpinner.stopAnimating()
            self.errorLabel.hidden = true
        }
    }
    
    //MARK: - Keyboard show/hide notifications
    
    func keyboardWillShow() {
        
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0)
        self.scrollView.setContentOffset(CGPointMake(0, 50), animated: true)
    }
    
    func keyboardWillHide() {
        
        self.scrollView.contentInset = UIEdgeInsetsZero
        self.scrollView.setContentOffset(CGPointZero, animated: true)
    }
    
    //MARK: - UITextFieldDelegate
    
    func textFieldDidBeginEditing(textField: UITextField) {
        self.errorLabel.hidden = true
    }
    
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        
        if textField == self.licensePlateTextField {
            self.passwordTextField.becomeFirstResponder()
        }
        if textField == self.passwordTextField {
            textField.resignFirstResponder()
            self.loginTouched()
{'fraction_non_alphanumeric': 0.08107367844426185, 'fraction_numerical': 0.005204053683922213, 'mean_word_length': 2.5763956904995102, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4798591', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1963, 'n_words': 388}