<commit_before>//
//  MOHUD.swift
//  OnTheMap
//
//  Created by Moath_Othman on 6/27/15.
//  Copyright (c) 2015 Moba. All rights reserved.
//

import UIKit

@objc class MOHUD: UIViewController {
    static var me:MOHUD?
    //MARK: Outlets
    @IBOutlet weak var loaderContainer: UIVisualEffectView!
    @IBOutlet weak var errorLabel: UILabel!
    @IBOutlet weak var statusLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    //MARK: variables
    var statusString: String = ""
    var failureString: String = ""
    var titleString: String = ""

    override func viewWillAppear(animated: Bool) {
        if MOHUD.me != nil {
            self.commonSetup(MOHUD.me!)
        }
    }
    //MARK: Constructor
    class func ME(_me:MOHUD?) -> MOHUD?{
        dismiss() // if any there dismiss it
        me = _me
        if let me = _me {
            //            me.commonSetup(me)
            return me
        }
        return nil
    }//0x7ff102d7e410
    //MARK: Factory
    class func MakeProgressHUD() {
         ME(self.make(.progress) as? MOHUD)
    }
    class func MakeSuccessHUD() {
         ME(self.make(.success) as? MOHUD)
    }
    class func MakeFailureHUD() {
        ME(self.make(.failure) as? MOHUD)
    }
    class func MakeSubtitleHUD() {
        ME(self.make(.subtitle) as? MOHUD)
    }
    //MARK: Subtitle
    class func showSubtitle(title title:String, subtitle:String) {
        MakeSubtitleHUD()
        MOHUD.me?.statusString = subtitle
        MOHUD.me?.titleString = title
        MOHUD.me?.show()
    }
    class func showSubtitle(title title:String, subtitle:String, period: NSTimeInterval) {
        MakeSubtitleHUD()
        MOHUD.me?.statusString = subtitle
        MOHUD.me?.titleString = title
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Fail
    class func showWithError(errorString:String) {
        MakeFailureHUD()
        MOHUD.me?.failureString = errorString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: 2)
    }
    class func showWithError(errorString:String, period: NSTimeInterval) {
        MakeFailureHUD()
        MOHUD.me?.failureString = errorString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Success
    class func showSuccess(successString: String) {
        MakeSuccessHUD()
        MOHUD.me?.statusString = successString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: 2)
    }
    class func showSuccess(successString: String, period: NSTimeInterval) {
        MakeSuccessHUD()
        MOHUD.me?.statusString = successString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Default show
    class func show() {
        MakeProgressHUD()
        MOHUD.me?.show()
    }
    class func show(periodOfTime period: NSTimeInterval) {
        MakeProgressHUD()
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }

    class func show(status: String) {
        MakeProgressHUD()
        MOHUD.me?.statusString = status
        MOHUD.me?.show()
    }
    class func show(status: String, period: NSTimeInterval) {
        MakeProgressHUD()
        MOHUD.me?.statusString = status
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Show/hide and timer
    private func show() {
        MOHUD.me?.view.alpha = 0;
        //NOTE: Keywindow should be shown first 
        if let keywindow = UIApplication.sharedApplication().keyWindow {
            keywindow.addSubview(self.view)
            UIView.animateWithDuration(1.55, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                MOHUD.me?.view.alpha = 1;
                }) { (finished) -> Void in

            }
        }
    }

    class func dismiss() {
        if let _me = me {
            UIView.animateWithDuration(0.45, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                _me.view.alpha = 0;
                }) { (finished) -> Void in
                    _me.view.removeFromSuperview()

            }
        }
    }
    private var hideTimer: NSTimer?
    private func hide(afterDelay delay: NSTimeInterval) {
        hideTimer?.invalidate()
        hideTimer = NSTimer.scheduledTimerWithTimeInterval(delay, target: self.classForCoder, selector: Selector("dismiss"), userInfo: nil, repeats: false)
    }

    @IBAction private func hideHud(sender: AnyObject) {
        MOHUD.dismiss()
    }
}


//MARK: Scenses organizing
struct MOStoryBoardID {
    static let progress = "Default"
    static let subtitle = "subtitle"
    static let success = "success"
    static let failure = "failure"
}

enum MOSceneType {
    case progress,success,failure,subtitle
}

extension MOHUD {
    class func make(type : MOSceneType) -> AnyObject {
        let mainStoryBoard: UIStoryboard = UIStoryboard(name: "MOHUD", bundle: nil)<commit_msg>Update MOHUD.swift<commit_after>//
//  MOHUD.swift
//  OnTheMap
//
//  Created by Moath_Othman on 6/27/15.
//  Copyright (c) 2015 Moba. All rights reserved.
//

import UIKit

public class MOHUD: UIViewController {
    static var me:MOHUD?
    //MARK: Outlets
    @IBOutlet weak var loaderContainer: UIVisualEffectView!
    @IBOutlet weak var errorLabel: UILabel!
    @IBOutlet weak var statusLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    //MARK: variables
    var statusString: String = ""
    var failureString: String = ""
    var titleString: String = ""

    override public func viewWillAppear(animated: Bool) {
        if MOHUD.me != nil {
            self.commonSetup(MOHUD.me!)
        }
    }
    //MARK: Constructor
    class func ME(_me:MOHUD?) -> MOHUD?{
        dismiss() // if any there dismiss it
        me = _me
        if let me = _me {
            //            me.commonSetup(me)
            return me
        }
        return nil
    }//0x7ff102d7e410
    //MARK: Factory
    class func MakeProgressHUD() {
         ME(self.make(.progress) as? MOHUD)
    }
    class func MakeSuccessHUD() {
         ME(self.make(.success) as? MOHUD)
    }
    class func MakeFailureHUD() {
        ME(self.make(.failure) as? MOHUD)
    }
    class func MakeSubtitleHUD() {
        ME(self.make(.subtitle) as? MOHUD)
    }
     // MARK: - Public
    //MARK: Subtitle
    public class func showSubtitle(title title:String, subtitle:String) {
        MakeSubtitleHUD()
        MOHUD.me?.statusString = subtitle
        MOHUD.me?.titleString = title
        MOHUD.me?.show()
    }
    public class func showSubtitle(title title:String, subtitle:String, period: NSTimeInterval) {
        MakeSubtitleHUD()
        MOHUD.me?.statusString = subtitle
        MOHUD.me?.titleString = title
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Fail
    public class func showWithError(errorString:String) {
        MakeFailureHUD()
        MOHUD.me?.failureString = errorString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: 2)
    }
    public class func showWithError(errorString:String, period: NSTimeInterval) {
        MakeFailureHUD()
        MOHUD.me?.failureString = errorString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Success
    public class func showSuccess(successString: String) {
        MakeSuccessHUD()
        MOHUD.me?.statusString = successString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: 2)
    }
    public class func showSuccess(successString: String, period: NSTimeInterval) {
        MakeSuccessHUD()
        MOHUD.me?.statusString = successString
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Default show
    public class func show() {
        MakeProgressHUD()
        MOHUD.me?.show()
    }
    public class func show(periodOfTime period: NSTimeInterval) {
        MakeProgressHUD()
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }

    public class func show(status: String) {
        MakeProgressHUD()
        MOHUD.me?.statusString = status
        MOHUD.me?.show()
    }
    public class func show(status: String, period: NSTimeInterval) {
        MakeProgressHUD()
        MOHUD.me?.statusString = status
        MOHUD.me?.show()
        MOHUD.me?.hide(afterDelay: period)
    }
    //MARK: Show/hide and timer
    private func show() {
        MOHUD.me?.view.alpha = 0;
        //NOTE: Keywindow should be shown first 
        if let keywindow = UIApplication.sharedApplication().keyWindow {
            keywindow.addSubview(self.view)
            UIView.animateWithDuration(1.55, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                MOHUD.me?.view.alpha = 1;
                }) { (finished) -> Void in

            }
        }
    }

    class func dismiss() {
        if let _me = me {
            UIView.animateWithDuration(0.45, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                _me.view.alpha = 0;
                }) { (finished) -> Void in
                    _me.view.removeFromSuperview()

            }
        }
    }
    private var hideTimer: NSTimer?
    private func hide(afterDelay delay: NSTimeInterval) {
        hideTimer?.invalidate()
        hideTimer = NSTimer.scheduledTimerWithTimeInterval(delay, target: self.classForCoder, selector: Selector("dismiss"), userInfo: nil, repeats: false)
    }

    @IBAction private func hideHud(sender: AnyObject) {
        MOHUD.dismiss()
    }
}


//MARK: Scenses organizing
struct MOStoryBoardID {
    static let progress = "Default"
    static let subtitle = "subtitle"
    static let success = "success"
    static let failure = "failure"
}

enum MOSceneType {
    case progress,success,failure,subtitle
}

extension MOHUD {
    class func make(type : MOSceneType) -> AnyObject {
        let mainStoryBoard: UIStoryboard = UIStoryboard(name: "MOHUD", bundle: NSBundle(forClass: MOHUD.self))
{'fraction_non_alphanumeric': 0.10956470239857861, 'fraction_numerical': 0.0069094857368473, 'mean_word_length': 2.272609819121447, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1020682', 'n_tokens_mistral': 3270, 'n_tokens_neox': 3160, 'n_words': 712}