<commit_before>//
//  RecipientsViewController+Extension.swift
//  Digipost
//
//  Created by <NAME> on 2015-04-09.
//  Copyright (c) 2015 Posten. All rights reserved.
//

import Foundation
import UIKit

extension RecipientViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        if self.recipientSearchController.active {
            return self.recipients.count
        } else {
            return self.addedRecipients.count
        }
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
        cell.accessoryType = UITableViewCellAccessoryType.None
        cell.textLabel?.font = UIFont(name: "HelveticaNeue-Light", size: 14)

        if recipientSearchController.active {
            if let recipient = recipients[indexPath.row].name {
                cell.textLabel?.text = recipient

                for r in addedRecipients {
                    if r.name == recipient && r.digipostAddress == recipients[indexPath.row].digipostAddress {
                        cell.accessoryType = UITableViewCellAccessoryType.Checkmark
                    }
                }
            }
        } else {
            if let recipient = addedRecipients[indexPath.row].name {
                cell.textLabel?.text = recipient
            }
        }
        
        return cell
    }
}

extension RecipientViewController: UITableViewDelegate {
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if recipientSearchController.active {
            addedRecipients.append(recipients[indexPath.row])
            tableView.deselectRowAtIndexPath(indexPath, animated: true)
            tableView.reloadData()
        } else {
            tableView.deselectRowAtIndexPath(indexPath, animated: false)
        }
    }
}

extension RecipientViewController: UISearchResultsUpdating {
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        recipients.removeAll(keepCapacity: false)
        
        if recipientSearchController.searchBar.text == "" {
            tableView.reloadData()
        }
        
        APIClient.sharedClient.getRecipients(recipientSearchController.searchBar.text, success: { (responseDictionary) -> Void in
            self.recipients = Recipient.recipients(jsonDict: responseDictionary)
            self.tableView.reloadData()
            
            }) { (error) -> () in
                println(error)
        }
    }
}

extension RecipientViewController: UITableViewDelegate {
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if recipientSearchController.active == false {
            addedRecipients.removeAtIndex(indexPath.row)
            tableView.reloadData()
        }
    }
}<commit_msg>improve funcitonality in recepientcontroller<commit_after>//
//  RecipientsViewController+Extension.swift
//  Digipost
//
//  Created by <NAME> on 2015-04-09.
//  Copyright (c) 2015 Posten. All rights reserved.
//

import Foundation
import UIKit

extension RecipientViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        if self.recipientSearchController.active {
            return self.recipients.count
        } else {
            return self.addedRecipients.count
        }
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
        cell.accessoryType = UITableViewCellAccessoryType.None
        cell.textLabel?.font = UIFont(name: "HelveticaNeue-Light", size: 14)

        if recipientSearchController.active {
            if countElements(recipients) >= 0 {
                if let recipient = recipients[indexPath.row].name {
                    cell.textLabel?.text = recipient
                    for r in addedRecipients {
                        if r.name == recipient && r.digipostAddress == recipients[indexPath.row].digipostAddress {
                            cell.accessoryType = UITableViewCellAccessoryType.Checkmark
                        }
                    }
                }
            }
            
        } else {
            if let recipient = addedRecipients[indexPath.row].name {
                cell.textLabel?.text = recipient
            }
        }
        
        return cell
    }
}

extension RecipientViewController: UITableViewDelegate {
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if recipientSearchController.active {
            addedRecipients.append(recipients[indexPath.row])
        }
        
        tableView.deselectRowAtIndexPath(indexPath, animated: false)

    }
    
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if recipientSearchController.active == false {
            addedRecipients.removeAtIndex(indexPath.row)
        }
    }
}

extension RecipientViewController: UISearchResultsUpdating {
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        recipients.removeAll(keepCapacity: false)
        
        if recipientSearchController.searchBar.text == "" {
            tableView.reloadData()
        }
        
        if (recipientSearchController.searchBar.text != nil) {
            APIClient.sharedClient.getRecipients(recipientSearchController.searchBar.text, success: { (responseDictionary) -> Void in
                self.recipients = Recipient.recipients(jsonDict: responseDictionary)
                
                }) { (error) -> () in
                    println(error)
            }
        }
        
    }
}
{'fraction_non_alphanumeric': 0.07824521198232116, 'fraction_numerical': 0.00474709445081028, 'mean_word_length': 2.3062770562770565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '522665', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1525, 'n_words': 285}