<commit_before>import UIKit

class VAlert:UIView
{
    private static let kHeight:CGFloat = 80
    private weak var layoutTop:NSLayoutConstraint!
    private weak var timer:Timer?
    private let kAnimationDuration:TimeInterval = 0.25
    private let kTimeOut:TimeInterval = 3.5
    private let kFontSize:CGFloat = 16
    private let kLabelTop:CGFloat = 20
    private let kLabelMargin:CGFloat = 9
    
    class func messageFail(message:String)
    {
        VAlert.message(message:message, color:UIColor.colourFail)
    }
    
    class func messageSuccess(message:String)
    {
        VAlert.message(message:message, color:UIColor.colourSuccess)
    }
    
    private class func message(message:String, color:UIColor)
    {
        DispatchQueue.main.async
        {
            let alert:VAlert = VAlert(
                message:message,
                color:color)
            
            let rootView:UIView = UIApplication.shared.keyWindow!.rootViewController!.view
            rootView.addSubview(alert)
            
            alert.layoutTop = NSLayoutConstraint.topToTop(
                view:alert,
                toView:rootView,
                constant:-kHeight)
            NSLayoutConstraint.equalsHorizontal(
                view:alert,
                toView:rootView)
            NSLayoutConstraint.height(
                view:alert,
                constant:kHeight)
            
            rootView.layoutIfNeeded()
            alert.animate(open:true)
        }
    }
    
    private convenience init(message:String, color:UIColor)
    {
        self.init()
        clipsToBounds = true
        backgroundColor = color
        translatesAutoresizingMaskIntoConstraints = false
        
        let label:UILabel = UILabel()
        label.isUserInteractionEnabled = false
        label.translatesAutoresizingMaskIntoConstraints = false
        label.font = UIFont.medium(size:kFontSize)
        label.textColor = UIColor.white
        label.textAlignment = NSTextAlignment.center
        label.numberOfLines = 0
        label.backgroundColor = UIColor.clear
        label.text = message
        
        let button:UIButton = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.backgroundColor = UIColor.clear
        button.addTarget(
            self,
            action:#selector(actionButton(sender:)),
            for:UIControlEvents.touchUpInside)
        
        addSubview(label)
        addSubview(button)
        
        NSLayoutConstraint.topToTop(
            view:label,
            toView:self,
            constant:kLabelTop)
        NSLayoutConstraint.bottomToBottom(
            view:label,
            toView:self)
        NSLayoutConstraint.equalsHorizontal(
            view:label,
            toView:self,
            margin:kLabelMargin)
    }
    
    func alertTimeOut(sender timer:Timer?)
    {
        timer?.invalidate()
        animate(open:false)
    }
    
    //MARK: selectors
    
    func actionButton(sender button:UIButton)
    {
        button.isUserInteractionEnabled = false
        timer?.invalidate()
        alertTimeOut(sender:timer)
    }
    
    //MARK: private
    
    private func scheduleTimer()
    {
        self.timer = Timer.scheduledTimer(
            timeInterval:kTimeOut,
            target:self,
            selector:#selector(alertTimeOut(sender:)),
            userInfo:nil,
            repeats:false)
    }
    
    private func animate(open:Bool)
    {
        if open
        {<commit_msg>Update selectors for swift 4<commit_after>import UIKit

class VAlert:UIView
{
    private static let kHeight:CGFloat = 80
    private weak var layoutTop:NSLayoutConstraint!
    private weak var timer:Timer?
    private let kAnimationDuration:TimeInterval = 0.25
    private let kTimeOut:TimeInterval = 3.5
    private let kFontSize:CGFloat = 16
    private let kLabelTop:CGFloat = 20
    private let kLabelMargin:CGFloat = 9
    
    class func messageFail(message:String)
    {
        VAlert.message(message:message, color:UIColor.colourFail)
    }
    
    class func messageSuccess(message:String)
    {
        VAlert.message(message:message, color:UIColor.colourSuccess)
    }
    
    private class func message(message:String, color:UIColor)
    {
        DispatchQueue.main.async
        {
            let alert:VAlert = VAlert(
                message:message,
                color:color)
            
            let rootView:UIView = UIApplication.shared.keyWindow!.rootViewController!.view
            rootView.addSubview(alert)
            
            alert.layoutTop = NSLayoutConstraint.topToTop(
                view:alert,
                toView:rootView,
                constant:-kHeight)
            NSLayoutConstraint.equalsHorizontal(
                view:alert,
                toView:rootView)
            NSLayoutConstraint.height(
                view:alert,
                constant:kHeight)
            
            rootView.layoutIfNeeded()
            alert.animate(open:true)
        }
    }
    
    private convenience init(message:String, color:UIColor)
    {
        self.init()
        clipsToBounds = true
        backgroundColor = color
        translatesAutoresizingMaskIntoConstraints = false
        
        let label:UILabel = UILabel()
        label.isUserInteractionEnabled = false
        label.translatesAutoresizingMaskIntoConstraints = false
        label.font = UIFont.medium(size:kFontSize)
        label.textColor = UIColor.white
        label.textAlignment = NSTextAlignment.center
        label.numberOfLines = 0
        label.backgroundColor = UIColor.clear
        label.text = message
        
        let button:UIButton = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.backgroundColor = UIColor.clear
        button.addTarget(
            self,
            action:#selector(selectorActionButton(sender:)),
            for:UIControlEvents.touchUpInside)
        
        addSubview(label)
        addSubview(button)
        
        NSLayoutConstraint.topToTop(
            view:label,
            toView:self,
            constant:kLabelTop)
        NSLayoutConstraint.bottomToBottom(
            view:label,
            toView:self)
        NSLayoutConstraint.equalsHorizontal(
            view:label,
            toView:self,
            margin:kLabelMargin)
    }
    
    //MARK: selectors
    
    @objc
    private func selectorActionButton(sender button:UIButton)
    {
        button.isUserInteractionEnabled = false
        timer?.invalidate()
        selectorAlertTimeOut(sender:timer)
    }
    
    @objc
    private func selectorAlertTimeOut(sender timer:Timer?)
    {
        timer?.invalidate()
        animate(open:false)
    }
    
    //MARK: private
    
    private func scheduleTimer()
    {
        self.timer = Timer.scheduledTimer(
            timeInterval:kTimeOut,
            target:self,
            selector:#selector(selectorAlertTimeOut(sender:)),
            userInfo:nil,
            repeats:false)
    }
    
    private func animate(open:Bool)
    {
        if open
        {
{'fraction_non_alphanumeric': 0.07225878728469402, 'fraction_numerical': 0.0037809830555944547, 'mean_word_length': 1.8973630831643002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5912484', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1892, 'n_words': 328}