<commit_before>//
//  SpringIndicator.swift
//  SpringIndicator
//
//  Created by <NAME> on 2015/03/06.
//  Copyright (c) 2015年 kyohei_ito. All rights reserved.
//

import UIKit

@IBDesignable
public class SpringIndicator: UIView {
    public class Refresher: UIControl {
        private let ObserverOffsetKeyPath = "contentOffset"
        private let ScaleAnimationKey = "scaleAnimation"
        private let DefaultContentHeight: CGFloat = 60
        
        private var initialInsetTop: CGFloat = 0
        public private(set) var indicator = SpringIndicator(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        public private(set) var refreshing: Bool = false
        public var targetView: UIScrollView?
        public var refreshingInsetTop: CGFloat {
            return initialInsetTop + (refreshing ? bounds.height : 0)
        }
        
        public convenience override init() {
            self.init(frame: CGRect.zeroRect)
        }
        
        override init(var frame: CGRect) {
            super.init(frame: frame)
            
            setupIndicator()
        }
        
        public required init(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            
            setupIndicator()
        }
        
        public override func layoutSubviews() {
            super.layoutSubviews()
            
            backgroundColor = UIColor.clearColor()
            userInteractionEnabled = false
            autoresizingMask = .FlexibleWidth | .FlexibleBottomMargin
            
            if let scrollView = superview as? UIScrollView {
                frame.size.height = DefaultContentHeight
                frame.size.width = scrollView.bounds.width
                center.x = scrollView.center.x
                
                initialInsetTop = scrollView.contentInset.top
                
                addObserver(scrollView)
            }
        }
        
        public override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
            if let scrollView = object as? UIScrollView {
                if scrollView.superview?.superview == nil {
                    scrollView.removeObserver(self, forKeyPath: ObserverOffsetKeyPath, context: nil)
                    targetView = nil
                    
                    return
                }
                
                var offsetY = initialInsetTop + scrollView.contentOffset.y
                frame.origin.y = offsetY
                
                if indicator.isSpinning() {
                    return
                }
                
                if refreshing && scrollView.dragging == false {
                    refreshStart(scrollView)
                    
                    return
                }<commit_msg>check target count<commit_after>//
//  SpringIndicator.swift
//  SpringIndicator
//
//  Created by <NAME> on 2015/03/06.
//  Copyright (c) 2015年 kyohei_ito. All rights reserved.
//

import UIKit

@IBDesignable
public class SpringIndicator: UIView {
    public class Refresher: UIControl {
        private let ObserverOffsetKeyPath = "contentOffset"
        private let ScaleAnimationKey = "scaleAnimation"
        private let DefaultContentHeight: CGFloat = 60
        
        private var initialInsetTop: CGFloat = 0
        public private(set) var indicator = SpringIndicator(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        public private(set) var refreshing: Bool = false
        public var targetView: UIScrollView?
        public var refreshingInsetTop: CGFloat {
            return initialInsetTop + (refreshing ? bounds.height : 0)
        }
        
        public convenience override init() {
            self.init(frame: CGRect.zeroRect)
        }
        
        override init(var frame: CGRect) {
            super.init(frame: frame)
            
            setupIndicator()
        }
        
        public required init(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            
            setupIndicator()
        }
        
        public override func layoutSubviews() {
            super.layoutSubviews()
            
            backgroundColor = UIColor.clearColor()
            userInteractionEnabled = false
            autoresizingMask = .FlexibleWidth | .FlexibleBottomMargin
            
            if let scrollView = superview as? UIScrollView {
                frame.size.height = DefaultContentHeight
                frame.size.width = scrollView.bounds.width
                center.x = scrollView.center.x
                
                initialInsetTop = scrollView.contentInset.top
                
                addObserver(scrollView)
            }
        }
        
        public override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
            if let scrollView = object as? UIScrollView {
                if scrollView.superview?.superview == nil {
                    scrollView.removeObserver(self, forKeyPath: ObserverOffsetKeyPath, context: nil)
                    targetView = nil
                    
                    return
                }
                
                var offsetY = initialInsetTop + scrollView.contentOffset.y
                frame.origin.y = offsetY
                
                if allTargets().count <= 0 {
                    return
                }
                
                if indicator.isSpinning() {
                    return
                }
                
                if refreshing && scrollView.dragging == false {
                    refreshStart(scrollView)
                    
                    return
                }
{'fraction_non_alphanumeric': 0.06777625257378174, 'fraction_numerical': 0.007721345229924502, 'mean_word_length': 1.463651732882502, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '6067474', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1394, 'n_words': 344}