<commit_before>//
//  DetailViewController.swift
//  xkcd
//
//  Created by <NAME> on 2015-09-17.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController {

    @IBOutlet weak var imgView: UIImageView!
    
    var detailItem: Comic? {
        didSet {
            // Update the view.
            self.configureView()
        }
    }

    func configureView() {
        // Update the user interface for the detail item.
        if let detail: Comic = self.detailItem {
            if let url = NSURL(string: detail.imageLink) {
                if let data = NSData(contentsOfURL: url) {
                    if let image = UIImage(data: data) {
                        imgView?.image = image
                    }
                }
            }
        }
        
        imgView?.contentMode = UIViewContentMode.ScaleAspectFit
        
        self.title = detailItem?.number
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.configureView()
        <commit_msg>Added alt-text on long-press of the comic<commit_after>//
//  DetailViewController.swift
//  xkcd
//
//  Created by <NAME> on 2015-09-17.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController {

    @IBOutlet weak var imgView: UIImageView!
    
    var detailItem: Comic? {
        didSet {
            // Update the view.
            self.configureView()
        }
    }

    func configureView() {
        // Update the user interface for the detail item.
        if let detail: Comic = self.detailItem {
            if let url = NSURL(string: detail.imageLink) {
                if let data = NSData(contentsOfURL: url) {
                    if let image = UIImage(data: data) {
                        imgView?.image = image
                    }
                }
            }
        }
        
        imgView?.contentMode = UIViewContentMode.ScaleAspectFit
        
        self.title = detailItem?.number
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        var gestureRecognizer = UILongPressGestureRecognizer(target: self, action: "imageLongPressed:")
        imgView.addGestureRecognizer(gestureRecognizer)
        
        self.configureView()
        
    }
    
    func imageLongPressed(img: AnyObject) {
        showAltText()
    }
    
    func showAltText() {
        
        let encodedData = detailItem?.alt.dataUsingEncoding(NSUTF8StringEncoding)!
        let attributedOptions : [String: AnyObject] = [
            NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
            NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
        ]
        let attributedString = NSAttributedString(data: encodedData!, options: attributedOptions, documentAttributes: nil, error: nil)
        let decodedString = attributedString!.string
        
        let alertView = UIAlertController(title: nil, message: decodedString, preferredStyle: UIAlertControllerStyle.Alert)
        alertView.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
        
        self.presentViewController(alertView, animated: true, completion: nil)
        
{'fraction_non_alphanumeric': 0.0841642228739003, 'fraction_numerical': 0.007624633431085044, 'mean_word_length': 1.876053962900506, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2991657', 'n_tokens_mistral': 952, 'n_tokens_neox': 883, 'n_words': 234}