<commit_before>//
//  AddFriendsViewController.swift
//  Yep
//
//  Created by NIX on 15/5/19.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit
import AddressBook
import Proposer

class AddFriendsViewController: UIViewController {

    @IBOutlet weak var addFriendsTableView: UITableView!

    let addFriendSearchCellIdentifier = "AddFriendSearchCell"
    let addFriendMoreCellIdentifier = "AddFriendMoreCell"
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = NSLocalizedString("Add Friends", comment: "")


        addFriendsTableView.rowHeight = 60

        addFriendsTableView.registerNib(UINib(nibName: addFriendSearchCellIdentifier, bundle: nil), forCellReuseIdentifier: addFriendSearchCellIdentifier)
        addFriendsTableView.registerNib(UINib(nibName: addFriendMoreCellIdentifier, bundle: nil), forCellReuseIdentifier: addFriendMoreCellIdentifier)
    }

    // MARK: Navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showSearchedUsers" {
            if let searchText = sender as? String {
                let vc = segue.destinationViewController as! SearchedUsersViewController
                vc.searchText = searchText.trimming(.WhitespaceAndNewline)
            }
        }
    }
}

extension AddFriendsViewController: UITableViewDataSource, UITableViewDelegate {

    enum Section: Int {
        case Search = 0
        case More

        static var caseCount: Int {
            var max: Int = 0
            while let _ = self(rawValue: ++max) {}
            return max
        }
    }

    enum More: Int, Printable {
        case Contacts
        case FaceToFace

        static var caseCount: Int {
            var max: Int = 0
            while let _ = self(rawValue: ++max) {}
            return max
        }

        var description: String {
            switch self {

            case .Contacts:
                return NSLocalizedString("Friends in Contacts", comment: "")

            case .FaceToFace:
                return NSLocalizedString("Face to Face", comment: "")
            }
        }
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return Section.caseCount
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {

        case Section.Search.rawValue:
            return 1

        case Section.More.rawValue:
            return More.caseCount

        default:
            return 0
        }
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        switch indexPath.section {

        case Section.Search.rawValue:
            let cell = tableView.dequeueReusableCellWithIdentifier(addFriendSearchCellIdentifier) as! AddFriendSearchCell

            cell.searchTextField.returnKeyType = .Search
            cell.searchTextField.delegate = self

            return cell

        case Section.More.rawValue:
            let cell = tableView.dequeueReusableCellWithIdentifier(addFriendMoreCellIdentifier) as! AddFriendMoreCell

            cell.annotationLabel.text = More(rawValue: indexPath.row)?.description

            return cell

        default:
            return UITableViewCell()
        }
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)

        if indexPath.section == Section.More.rawValue {

            switch indexPath.row {

            case More.Contacts.rawValue:

                let propose: Propose = {
                    proposeToAccess(.Contacts, agreed: {
                        self.performSegueWithIdentifier("showFriendsInContacts", sender: nil)

                    }, rejected: {
                        self.alertCanNotAccessContacts()
                    })
                }

                showProposeMessageIfNeedForContactsAndTryPropose(propose)

            case More.FaceToFace.rawValue:
                break
                
            default:
                break
            }
        }
    }
}

extension AddFriendsViewController: UITextFieldDelegate {
    func textFieldShouldReturn(textField: UITextField) -> Bool {

        let text = textField.text

        textField.resignFirstResponder()

        performSegueWithIdentifier("showSearchedUsers", sender: text)

        return true
    }
}
<commit_msg>comment FaceToFace<commit_after>//
//  AddFriendsViewController.swift
//  Yep
//
//  Created by NIX on 15/5/19.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit
import AddressBook
import Proposer

class AddFriendsViewController: UIViewController {

    @IBOutlet weak var addFriendsTableView: UITableView!

    let addFriendSearchCellIdentifier = "AddFriendSearchCell"
    let addFriendMoreCellIdentifier = "AddFriendMoreCell"
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = NSLocalizedString("Add Friends", comment: "")


        addFriendsTableView.rowHeight = 60

        addFriendsTableView.registerNib(UINib(nibName: addFriendSearchCellIdentifier, bundle: nil), forCellReuseIdentifier: addFriendSearchCellIdentifier)
        addFriendsTableView.registerNib(UINib(nibName: addFriendMoreCellIdentifier, bundle: nil), forCellReuseIdentifier: addFriendMoreCellIdentifier)
    }

    // MARK: Navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showSearchedUsers" {
            if let searchText = sender as? String {
                let vc = segue.destinationViewController as! SearchedUsersViewController
                vc.searchText = searchText.trimming(.WhitespaceAndNewline)
            }
        }
    }
}

extension AddFriendsViewController: UITableViewDataSource, UITableViewDelegate {

    enum Section: Int {
        case Search = 0
        case More

        static var caseCount: Int {
            var max: Int = 0
            while let _ = self(rawValue: ++max) {}
            return max
        }
    }

    enum More: Int, Printable {
        case Contacts
        //case FaceToFace

        static var caseCount: Int {
            var max: Int = 0
            while let _ = self(rawValue: ++max) {}
            return max
        }

        var description: String {
            switch self {

            case .Contacts:
                return NSLocalizedString("Friends in Contacts", comment: "")

            //case .FaceToFace:
            //    return NSLocalizedString("Face to Face", comment: "")
            }
        }
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return Section.caseCount
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {

        case Section.Search.rawValue:
            return 1

        case Section.More.rawValue:
            return More.caseCount

        default:
            return 0
        }
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        switch indexPath.section {

        case Section.Search.rawValue:
            let cell = tableView.dequeueReusableCellWithIdentifier(addFriendSearchCellIdentifier) as! AddFriendSearchCell

            cell.searchTextField.returnKeyType = .Search
            cell.searchTextField.delegate = self

            return cell

        case Section.More.rawValue:
            let cell = tableView.dequeueReusableCellWithIdentifier(addFriendMoreCellIdentifier) as! AddFriendMoreCell

            cell.annotationLabel.text = More(rawValue: indexPath.row)?.description

            return cell

        default:
            return UITableViewCell()
        }
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)

        if indexPath.section == Section.More.rawValue {

            switch indexPath.row {

            case More.Contacts.rawValue:

                let propose: Propose = {
                    proposeToAccess(.Contacts, agreed: {
                        self.performSegueWithIdentifier("showFriendsInContacts", sender: nil)

                    }, rejected: {
                        self.alertCanNotAccessContacts()
                    })
                }

                showProposeMessageIfNeedForContactsAndTryPropose(propose)

            //case More.FaceToFace.rawValue:
            //    break
                
            default:
                break
            }
        }
    }
}

extension AddFriendsViewController: UITextFieldDelegate {
    func textFieldShouldReturn(textField: UITextField) -> Bool {

        let text = textField.text

        textField.resignFirstResponder()

        performSegueWithIdentifier("showSearchedUsers", sender: text)

        return true
    }
}

{'fraction_non_alphanumeric': 0.0718311415626036, 'fraction_numerical': 0.003536302353851254, 'mean_word_length': 2.1121045392022006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '136333', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2274, 'n_words': 521}