<commit_before>//
//  ElloTabBar.swift
//  Ello
//
//  Created by <NAME> on 11/21/14.
//  Copyright (c) 2014 Ello. All rights reserved.
//

import UIKit

public class ElloTabBar: UITabBar {
    struct Size {
        static let height = CGFloat(49)
    }

    private var redDotViews = [(Int, UIView)]()

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        privateInit()
    }

    convenience init() {
        self.init(frame: CGRectZero)
        privateInit()
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        privateInit()
    }

    private func privateInit() {
        self.backgroundColor = UIColor.whiteColor()
        self.translucent = false
        self.opaque = true
        self.barTintColor = UIColor.whiteColor()
        self.tintColor = UIColor.blackColor()
        self.clipsToBounds = true
        self.shadowImage = UIImage.imageWithColor(UIColor.whiteColor())
    }

    public func addRedDotAtIndex(index: Int) -> UIView {
        let redDot: UIView
        if let entryIndex = (redDotViews.indexOf { $0.0 == index }) {
            redDot = redDotViews[entryIndex].1
        }
        else {
            redDot = UIView()
            redDot.backgroundColor = UIColor.redColor()
            redDot.hidden = true
            let redDotEntry = (index, redDot)
            redDotViews.append(redDotEntry)
            addSubview(redDot)
        }

        positionRedDot(redDot, atIndex: index)
        return redDot
    }

    private func tabBarFrameAtIndex(index: Int) -> CGRect {
        let tabBarButtons = subviews.filter {
            $0 is UIControl
        }.sort {
            $0.frame.minX < $1.frame.minX
        }
        return tabBarButtons.safeValue(index)?.frame ?? CGRectZero
    }

    private func positionRedDot(redDot: UIView, atIndex index: Int) {
        let radius: CGFloat = 3
        let diameter = radius * 2
        let margin: CGFloat = 11
        let tabBarItemFrame = tabBarFrameAtIndex(index)
        let item = items?[index]
        let imageHalfWidth: CGFloat = (item?.selectedImage?.size.width ?? 0) / 2
        let x = tabBarItemFrame.midX - imageHalfWidth - margin
        let frame = CGRect(x: x, y: margin, width: diameter, height: diameter)

        redDot.layer.cornerRadius = radius
        redDot.frame = frame
    }

    public override func layoutSubviews() {
        super.layoutSubviews()
        for (index, redDot) in redDotViews {
            positionRedDot(redDot, atIndex: index)
        }
    }

}
<commit_msg>fixes the ElloTabBar redDot frames<commit_after>//
//  ElloTabBar.swift
//  Ello
//
//  Created by <NAME> on 11/21/14.
//  Copyright (c) 2014 Ello. All rights reserved.
//

import UIKit

public class ElloTabBar: UITabBar {
    struct Size {
        static let height = CGFloat(49)
    }

    private var redDotViews = [(Int, UIView)]()

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        privateInit()
    }

    convenience init() {
        self.init(frame: CGRectZero)
        privateInit()
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        privateInit()
    }

    private func privateInit() {
        self.backgroundColor = UIColor.whiteColor()
        self.translucent = false
        self.opaque = true
        self.barTintColor = UIColor.whiteColor()
        self.tintColor = UIColor.blackColor()
        self.clipsToBounds = true
        self.shadowImage = UIImage.imageWithColor(UIColor.whiteColor())
    }

    public func addRedDotAtIndex(index: Int) -> UIView {
        let redDot: UIView
        if let entryIndex = (redDotViews.indexOf { $0.0 == index }) {
            redDot = redDotViews[entryIndex].1
        }
        else {
            redDot = UIView()
            redDot.backgroundColor = UIColor.redColor()
            redDot.hidden = true
            let redDotEntry = (index, redDot)
            redDotViews.append(redDotEntry)
            addSubview(redDot)
        }

        positionRedDot(redDot, atIndex: index)
        return redDot
    }

    private func tabBarFrameAtIndex(index: Int) -> CGRect {
        let tabBarButtons = subviews.filter {
            $0 is UIControl
        }.sort {
            $0.frame.minX < $1.frame.minX
        }
        return tabBarButtons.safeValue(index)?.frame ?? CGRectZero
    }

    private func positionRedDot(redDot: UIView, atIndex index: Int) {
        let radius: CGFloat = 3
        let diameter = radius * 2
        let margins = CGPoint(x: 0, y: 10)
        let tabBarItemFrame = tabBarFrameAtIndex(index)
        let item = items?[index]
        let imageHalfWidth: CGFloat = (item?.selectedImage?.size.width ?? 0) / 2
        let x = tabBarItemFrame.midX + imageHalfWidth + margins.x
        let frame = CGRect(x: x, y: margins.y, width: diameter, height: diameter)

        redDot.layer.cornerRadius = radius
        redDot.frame = frame
    }

    public override func layoutSubviews() {
        super.layoutSubviews()
        for (index, redDot) in redDotViews {
            positionRedDot(redDot, atIndex: index)
        }
    }

}

{'fraction_non_alphanumeric': 0.09982520877840358, 'fraction_numerical': 0.00951641095358322, 'mean_word_length': 2.0673019654556284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5500140', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1555, 'n_words': 370}