<commit_before>//
//  ReadingListViewController.swift
//  seaCow
//
//  Created by <NAME> on 4/16/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

class ReadingListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    
    @IBOutlet weak var myTableView: UITableView!
    
    var readingList = NYTArticles()
    var allArticles: [ArticleData]?
    var selectedArticle: ArticleData?

    // A set of constant and variable strings for making up the URL for article searching using NYT's API
    let articleSearchBaseUrl = "http://api.nytimes.com/svc/mostpopular/v2"
    let articleSearchResourceType = "mostviewed" // mostemailed | mostshared | mostviewed
    let articleSearchSections = "all-sections"
    let articlesSearchNumOfDays = 1 // 1 | 7 | 30
    let articleSearchReturnFormat = ".json"
    let articleSearchAPIKey = "b772e34fc2a53d05fe60d6c63d0c0e4c:9:71573042"
    
    override func viewDidLoad() {
    
        
        super.viewDidLoad()
        
        var articleSearchUrl = articleSearchBaseUrl + "/" + articleSearchResourceType + "/" + articleSearchSections + "/" + "\(articlesSearchNumOfDays)" + articleSearchReturnFormat + "?" + "&API-Key=" + articleSearchAPIKey
        
        // load articles from the NYT API
        readingList.load(articleSearchUrl, loadCompletionHandler: {
            (nytArticles, errorString) -> Void in
            if let unwrappedErrorString = errorString {
                println(unwrappedErrorString)
            } else {
             
                println(self.readingList.articles.count)
                self.myTableView.reloadData()
                
            }
        })
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return allArticles!.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
        if(allArticles!.count > 0) {
            
        
            //cell.title?.text = readingList.articles[indexPath.row].title
            cell.title?.text = allArticles![indexPath.row].title
            //let url = NSURL(string: readingList.articles[indexPath.row].imageUrl)
            let url = NSURL(string: allArticles![indexPath.row].imageUrl)
            let data = NSData(contentsOfURL: url!)
            
            
            
            cell.backgroundImage.image = UIImage(data: data!)
            
        }
        
        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        selectedArticle = allArticles![indexPath.row]
        performSegueWithIdentifier("showArticle", sender: self)
    }
    
    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }
    
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        
        
    }
    
    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
        
        var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal , title: "Share", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
            
            
            return
        })
        
        shareAction.backgroundColor = UIColor.blueColor()
       
        var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default , title: "Delete", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
            println("test")
            
            return
        })
        
        return [deleteAction, shareAction]
        
    }
    <commit_msg>delete article from table view cell<commit_after>//
//  ReadingListViewController.swift
//  seaCow
//
//  Created by <NAME> on 4/16/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

class ReadingListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    
    @IBOutlet weak var myTableView: UITableView!
    
    var readingList = NYTArticles()
    var allArticles: [ArticleData]?
    var selectedArticle: ArticleData?

    // A set of constant and variable strings for making up the URL for article searching using NYT's API
    let articleSearchBaseUrl = "http://api.nytimes.com/svc/mostpopular/v2"
    let articleSearchResourceType = "mostviewed" // mostemailed | mostshared | mostviewed
    let articleSearchSections = "all-sections"
    let articlesSearchNumOfDays = 1 // 1 | 7 | 30
    let articleSearchReturnFormat = ".json"
    let articleSearchAPIKey = "b772e34fc2a53d05fe60d6c63d0c0e4c:9:71573042"
    
    override func viewDidLoad() {
    
        
        super.viewDidLoad()
        
        var articleSearchUrl = articleSearchBaseUrl + "/" + articleSearchResourceType + "/" + articleSearchSections + "/" + "\(articlesSearchNumOfDays)" + articleSearchReturnFormat + "?" + "&API-Key=" + articleSearchAPIKey
        
        // load articles from the NYT API
        readingList.load(articleSearchUrl, loadCompletionHandler: {
            (nytArticles, errorString) -> Void in
            if let unwrappedErrorString = errorString {
                println(unwrappedErrorString)
            } else {
             
                println(self.readingList.articles.count)
                self.myTableView.reloadData()
                
            }
        })
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return allArticles!.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
        if(allArticles!.count > 0) {
            
        
            //cell.title?.text = readingList.articles[indexPath.row].title
            cell.title?.text = allArticles![indexPath.row].title
            //let url = NSURL(string: readingList.articles[indexPath.row].imageUrl)
            let url = NSURL(string: allArticles![indexPath.row].imageUrl)
            let data = NSData(contentsOfURL: url!)
            
            
            
            cell.backgroundImage.image = UIImage(data: data!)
            
        }
        
        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        selectedArticle = allArticles![indexPath.row]
        performSegueWithIdentifier("showArticle", sender: self)
    }
    
    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }
    
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        
        
    }
    
    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
        
        var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal , title: "Share", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
            
            
            return
        })
        
        shareAction.backgroundColor = UIColor.blueColor()
       
        var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default , title: "Delete", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
            
            self.allArticles?.removeAtIndex(indexPath.row)
            self.myTableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
            
            return
        })
        
        return [deleteAction, shareAction]
        
    }
    
{'fraction_non_alphanumeric': 0.08639067922657412, 'fraction_numerical': 0.010659395141298959, 'mean_word_length': 2.4190677966101695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '1443236', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2163, 'n_words': 460}