<commit_before>//
//  CustomProgressButton.swift
//  JiraTracker
//
//  Created by <NAME> on 10/23/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//


import Foundation
import UIKit

protocol CustomProgressButtonDelegate {
    func didTapCTAButton(_ sender: Any)
}

class CustomProgressButton : UIView {
    //MARK: - IBOutlets
    @IBOutlet private var contentView: UIView!
    @IBOutlet private var progressBarWidthConstraint: NSLayoutConstraint!
    @IBOutlet private var CTAButton: UIButton!
    @IBOutlet private var progressBar: UIView!
    
    //MARK: - Variables
    var delegate: CustomProgressButtonDelegate?
    
    //MARK: - Functions
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setUpView()
    }
    
    private func setUpView() {
        let view = viewFromNibForClass()
        view.frame = bounds
        
        addSubview(view)
        
        self.progressBar.backgroundColor = UIColor.gray
    }
    
    private func viewFromNibForClass() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
        
        return view
    }
    
    //MARK: - IBActions
    @IBAction func didTapCTAButton(_ sender: Any) {
        self.delegate?.didTapCTAButton(sender)
    }
    
    //MARK: - Progress
    func setProgressBar(progress: Float, animated: Bool) {
        self.setProgressBar(progress: progress, progressBarColor: self.progressBar.backgroundColor, buttonTitleColor: self.CTAButton.titleColor(for: .normal), animated: animated)
    }
    
    func setProgressBar(progress: Float, progressBarColor: UIColor?, buttonTitleColor: UIColor?, animated: Bool) {
        var progress = CGFloat(progress)
        if (progress < 0.0) {
            progress = 0.0
        } else if (progress > 1.0) {
            progress = 1.0
        }
        self.progressBarWidthConstraint.constant = progress * self.contentView.frame.width
        UIView.animate(withDuration: animated ? 1.0 : 0.0) {
            self.setNeedsLayout()
            self.layoutIfNeeded()
            if let progressBarColor = progressBarColor {
                self.progressBar.backgroundColor = progressBarColor
            }<commit_msg>Added current progress property to CustomProgressButton<commit_after>//
//  CustomProgressButton.swift
//  JiraTracker
//
//  Created by <NAME> on 10/23/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//


import Foundation
import UIKit

protocol CustomProgressButtonDelegate {
    func didTapCTAButton(_ sender: Any)
}

class CustomProgressButton : UIView {
    //MARK: - IBOutlets
    @IBOutlet private var contentView: UIView!
    @IBOutlet private var progressBarWidthConstraint: NSLayoutConstraint!
    @IBOutlet private var CTAButton: UIButton!
    @IBOutlet private var progressBar: UIView!
    
    //MARK: - Variables
    var delegate: CustomProgressButtonDelegate?
    
    var currentProgress: Float = 0.0
    
    //MARK: - Functions
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setUpView()
    }
    
    private func setUpView() {
        let view = viewFromNibForClass()
        view.frame = bounds
        
        addSubview(view)
        
        self.progressBar.backgroundColor = UIColor.gray
    }
    
    private func viewFromNibForClass() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
        
        return view
    }
    
    //MARK: - IBActions
    @IBAction func didTapCTAButton(_ sender: Any) {
        self.delegate?.didTapCTAButton(sender)
    }
    
    //MARK: - Progress
    func setProgressBar(progress: Float, animated: Bool) {
        self.setProgressBar(progress: progress, progressBarColor: self.progressBar.backgroundColor, buttonTitleColor: self.CTAButton.titleColor(for: .normal), animated: animated)
    }
    
    func setProgressBar(progress: Float, progressBarColor: UIColor?, buttonTitleColor: UIColor?, animated: Bool) {
        self.currentProgress = progress
        if (self.currentProgress < 0.0) {
            self.currentProgress = 0.0
        } else if (self.currentProgress > 1.0) {
            self.currentProgress = 1.0
        }
        self.progressBarWidthConstraint.constant = CGFloat(self.currentProgress) * self.contentView.frame.width
        UIView.animate(withDuration: animated ? 1.0 : 0.0) {
            self.setNeedsLayout()
            self.layoutIfNeeded()
            if let progressBarColor = progressBarColor {
                self.progressBar.backgroundColor = progressBarColor
            }
{'fraction_non_alphanumeric': 0.09524752475247525, 'fraction_numerical': 0.009108910891089108, 'mean_word_length': 2.49792243767313, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5394775', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1458, 'n_words': 348}