<commit_before>//
//  RepoViewController.swift
//  GoGoGithub
//
//  Created by <NAME> on 4/4/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class RepoViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    

    @IBOutlet weak var searchBar: UISearchBar!
    
    var repos = [Repository]() {
        didSet {
            self.tableView.reloadData()
        }
    }
    
    var displayRepos : [Repository]? {
        didSet {
            self.tableView.reloadData()
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.searchBar.delegate = self
        update()
    }
    
    func update() {

        GitHub.shared.getRepos { (repositories) in
            //update tableView
            guard let repositories = repositories else { return }
                self.repos = repositories
                //self.tableView.reloadData()
            
        }
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        super.prepare(for: segue, sender: sender)
        
        if segue.identifier == RepoDetailViewController.identifier {
            
            segue.destination.transitioningDelegate = self
            
        }
    }
}

extension RepoViewController: UIViewControllerTransitioningDelegate {
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        return CustomTransition(duration: 1.0)
        
    }
}


//MARK: UITableViewDelegate

extension RepoViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return displayRepos?.count ?? repos.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "RepoCell", for: indexPath) as! RepoTableViewCell
        
        cell.repoNameLabel.text = displayRepos?[indexPath.row].name ?? repos[indexPath.row].name
        cell.descriptionLabel.text = displayRepos?[indexPath.row].description ?? repos[indexPath.row].description
        cell.languageLabel.text = displayRepos?[indexPath.row].language ??
            repos[indexPath.row].language
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.performSegue(withIdentifier: RepoDetailViewController.identifier, sender: nil)
    }
}

extension RepoViewController: UISearchBarDelegate {
    <commit_msg>wednesday branch in working condition<commit_after>//
//  RepoViewController.swift
//  GoGoGithub
//
//  Created by <NAME> on 4/4/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class RepoViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    

    @IBOutlet weak var searchBar: UISearchBar!
    
    var repos = [Repository]() {
        didSet {
            self.tableView.reloadData()
        }
    }
    
    var displayRepos : [Repository]? {
        didSet {
            self.tableView.reloadData()
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.searchBar.delegate = self
        update()
    }
    
    func update() {

        GitHub.shared.getRepos { (repositories) in
            //update tableView
            guard let repositories = repositories else { return }
                self.repos = repositories
                //self.tableView.reloadData()
            
        }
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        super.prepare(for: segue, sender: sender)
        
        if segue.identifier == RepoDetailViewController.identifier {
            
            segue.destination.transitioningDelegate = self
            
        }
    }
}

//MARK: UIViewControllerTransitioningDelegate

extension RepoViewController: UIViewControllerTransitioningDelegate {
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        return CustomTransition(duration: 1.0)
        
    }
}


//MARK: UITableViewDelegate

extension RepoViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return displayRepos?.count ?? repos.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "RepoCell", for: indexPath) as! RepoTableViewCell
        
        cell.repoNameLabel.text = displayRepos?[indexPath.row].name ?? repos[indexPath.row].name
        cell.descriptionLabel.text = displayRepos?[indexPath.row].description ?? repos[indexPath.row].description
        cell.languageLabel.text = displayRepos?[indexPath.row].language ??
            repos[indexPath.row].language
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.performSegue(withIdentifier: RepoDetailViewController.identifier, sender: nil)
    }
}

//MARK: UISearchBarDelegate

extension RepoViewController: UISearchBarDelegate {
    
{'fraction_non_alphanumeric': 0.08661971830985915, 'fraction_numerical': 0.0035211267605633804, 'mean_word_length': 2.445118253486962, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '7549453', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1509, 'n_words': 320}