<commit_before>//
//  Toast.swift
//  KeyboardKit
//
//  Created by <NAME> on 2016-08-22.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

open class Toast: NSObject, Alerter {
    
    
    // MARK: - Public functions
    
    public func alert(message: String, in view: UIView, withDuration duration: Double) {
        let label = createLabel(withMessage: message)
        let container = createContainer(forLabel: label, inView: view)

        style(label: label)
        style(containerView: container)
        
        let interval = TimeInterval(duration)
        UIView.animate(withDuration: duration, animations: { () -> Void in
            container.alpha = 0
        }, completion: { (Bool) -> Void in
            container.removeFromSuperview()
        }) 
    }
    
    open func style(containerView view: UIView) {
        CGRect.zero
    }
    
    open func style(label: UILabel) {
    }
    
    
    
    // MARK: - Private functions
    
    private func createContainer(forLabel label: UILabel, inView view: UIView) -> UIView {
        let container = UIView()
        container.frame = label.frame.insetBy(dx: -20, dy: -10)
        view.addSubview(container)
        container.layer.cornerRadius = 10
        container.center = view.center
        container.frame.origin.y -= 20
        container.backgroundColor = UIColor.white
        container.addSubview(label)
        return container
    }
    
    private func createLabel(withMessage message: String) -> UILabel {
        let label = UILabel()
        label.text = message
        label.textColor = UIColor.black
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 14)
        label.autoresizingMask = .flexibleHeight
        label.lineBreakMode = .byWordWrapping
        label.textAlignment = .center<commit_msg>Remove accidently added line<commit_after>//
//  Toast.swift
//  KeyboardKit
//
//  Created by <NAME> on 2016-08-22.
//  Copyright © 2016 <NAME>idi. All rights reserved.
//

import UIKit

open class Toast: NSObject, Alerter {
    
    
    // MARK: - Public functions
    
    public func alert(message: String, in view: UIView, withDuration duration: Double) {
        let label = createLabel(withMessage: message)
        let container = createContainer(forLabel: label, inView: view)

        style(label: label)
        style(containerView: container)
        
        let interval = TimeInterval(duration)
        UIView.animate(withDuration: duration, animations: { () -> Void in
            container.alpha = 0
        }, completion: { (Bool) -> Void in
            container.removeFromSuperview()
        }) 
    }
    
    open func style(containerView view: UIView) {
    }
    
    open func style(label: UILabel) {
    }
    
    
    
    // MARK: - Private functions
    
    private func createContainer(forLabel label: UILabel, inView view: UIView) -> UIView {
        let container = UIView()
        container.frame = label.frame.insetBy(dx: -20, dy: -10)
        view.addSubview(container)
        container.layer.cornerRadius = 10
        container.center = view.center
        container.frame.origin.y -= 20
        container.backgroundColor = UIColor.white
        container.addSubview(label)
        return container
    }
    
    private func createLabel(withMessage message: String) -> UILabel {
        let label = UILabel()
        label.text = message
        label.textColor = UIColor.black
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 14)
        label.autoresizingMask = .flexibleHeight
        label.lineBreakMode = .byWordWrapping
        label.textAlignment = .center
{'fraction_non_alphanumeric': 0.09608056614044638, 'fraction_numerical': 0.0130647795318454, 'mean_word_length': 2.173575129533679, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4537769', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1036, 'n_words': 261}