<commit_before>//
//  HeaderImageSelectionViewController.swift
//  Ello
//
//  Created by <NAME> on 5/15/2015.
//  Copyright (c) 2015 Ello. All rights reserved.
//

public class HeaderImageSelectionViewController: BaseElloViewController, OnboardingStep {
    var onboardingViewController: OnboardingViewController?
    var onboardingHeader: OnboardingHeaderView!

    override public func viewDidLoad() {
        super.viewDidLoad()

        onboardingHeader = OnboardingHeaderView(frame: CGRect(
            x: 0,
            y: 0,
            width: view.frame.width,
            height: 0
            ))
        onboardingHeader.autoresizingMask = .FlexibleWidth
        let header = NSLocalizedString("Customize your profile.", comment: "Header Image Selection text")
        let message = NSLocalizedString("This is what other people will see when viewing your profile, make it look good!", comment: "Header Image Selection text")
        onboardingHeader.header = header
        onboardingHeader.message = message
        onboardingHeader.autoresizingMask = .FlexibleWidth | .FlexibleBottomMargin
        onboardingHeader.sizeToFit()
        view.addSubview(onboardingHeader)

        let chooseHeaderImage = UIImage(named: "choose-header-image")!
        let aspect = view.frame.width / chooseHeaderImage.size.width
        let chooseHeaderImageView = UIImageView(frame: CGRect(
            x: 0,
            y: onboardingHeader.frame.maxY + 23,
            width: view.frame.width,
            height: chooseHeaderImage.size.height * aspect
            ))
        chooseHeaderImageView.autoresizingMask = .FlexibleLeftMargin | .FlexibleRightMargin | .FlexibleBottomMargin
        chooseHeaderImageView.image = chooseHeaderImage
        view.addSubview(chooseHeaderImageView)

        let chooseHeaderButton = ElloButton(frame: CGRect(
            x: 0,
            y: chooseHeaderImageView.frame.maxY + 8,
            width: view.frame.width,
            height: 90
            ).inset(all: 15))
        chooseHeaderButton.autoresizingMask = .FlexibleLeftMargin | .FlexibleRightMargin | .FlexibleBottomMargin
        chooseHeaderButton.setTitle(NSLocalizedString("Choose Your Header", comment: "Choose your header button"), forState: .Normal)
        view.addSubview(chooseHeaderButton)
    }

}<commit_msg>implements image picker in 'HeaderSelection' screen<commit_after>//
//  HeaderImageSelectionViewController.swift
//  Ello
//
//  Created by <NAME> on 5/15/2015.
//  Copyright (c) 2015 Ello. All rights reserved.
//

public class HeaderImageSelectionViewController: BaseElloViewController, OnboardingStep {
    var onboardingViewController: OnboardingViewController?

    override public func viewDidLoad() {
        super.viewDidLoad()

        let onboardingHeader = OnboardingHeaderView(frame: CGRect(
            x: 0,
            y: 0,
            width: view.frame.width,
            height: 0
            ))
        onboardingHeader.autoresizingMask = .FlexibleWidth
        let header = NSLocalizedString("Customize your profile.", comment: "Header Image Selection text")
        let message = NSLocalizedString("This is what other people will see when viewing your profile, make it look good!", comment: "Header Image Selection text")
        onboardingHeader.header = header
        onboardingHeader.message = message
        onboardingHeader.autoresizingMask = .FlexibleWidth | .FlexibleBottomMargin
        onboardingHeader.sizeToFit()
        view.addSubview(onboardingHeader)

        let chooseHeaderImage = UIImage(named: "choose-header-image")!
        let aspect = view.frame.width / chooseHeaderImage.size.width
        let chooseHeaderImageView = UIImageView(frame: CGRect(
            x: 0,
            y: onboardingHeader.frame.maxY + 23,
            width: view.frame.width,
            height: chooseHeaderImage.size.height * aspect
            ))
        chooseHeaderImageView.autoresizingMask = .FlexibleLeftMargin | .FlexibleRightMargin | .FlexibleBottomMargin
        chooseHeaderImageView.image = chooseHeaderImage
        view.addSubview(chooseHeaderImageView)

        let chooseHeaderButton = ElloButton(frame: CGRect(
            x: 0,
            y: chooseHeaderImageView.frame.maxY + 8,
            width: view.frame.width,
            height: 90
            ).inset(all: 15))
        chooseHeaderButton.autoresizingMask = .FlexibleLeftMargin | .FlexibleRightMargin | .FlexibleBottomMargin
        chooseHeaderButton.setTitle(NSLocalizedString("Choose Your Header", comment: "Choose your header button"), forState: .Normal)
        chooseHeaderButton.addTarget(self, action: Selector("chooseHeaderTapped"), forControlEvents: .TouchUpInside)
        view.addSubview(chooseHeaderButton)
    }

    @objc
    func chooseHeaderTapped() {
        let alert = UIImagePickerController.alertControllerForImagePicker(openImagePicker)
        alert.map { self.presentViewController($0, animated: true, completion: nil) }
    }

    private func openImagePicker(imageController : UIImagePickerController) {
        imageController.delegate = self
        self.presentViewController(imageController, animated: true, completion: nil)
    }

    public func userSetCurrentImage(oriented: UIImage) {
        onboardingViewController?.goToNextStep()
    }

}

extension HeaderImageSelectionViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    public func imagePickerController(controller: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            let oriented = image.copyWithCorrectOrientation()
            userSetCurrentImage(oriented)
        }
        dismissViewControllerAnimated(true, completion: nil)
    }

    public func imagePickerControllerDidCancel(controller: UIImagePickerController) {
        dismissViewControllerAnimated(true, completion: nil)
    }

}
{'fraction_non_alphanumeric': 0.07955689828801611, 'fraction_numerical': 0.00788855320577375, 'mean_word_length': 3.0648021828103684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6988832', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1502, 'n_words': 356}