<commit_before>//
//  ProfileLayout.swift
//  Yep
//
//  Created by NIX on 15/4/8.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit

class ProfileLayout: UICollectionViewFlowLayout {

    let leftEdgeInset: CGFloat = YepConfig.Profile.leftEdgeInset

    override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
        let layoutAttributes = super.layoutAttributesForElementsInRect(rect) as! [UICollectionViewLayoutAttributes]
        let contentInset = collectionView!.contentInset
        let contentOffset = collectionView!.contentOffset

        let minY = -contentInset.top

        if contentOffset.y < minY {
            let deltaY = abs(contentOffset.y - minY)

            for (index, attributes) in enumerate(layoutAttributes) {
                if index == 0 {
                    var frame = attributes.frame
                    frame.size.height = max(minY, CGRectGetWidth(collectionView!.bounds) * profileAvatarAspectRatio + deltaY)
                    frame.origin.y = CGRectGetMinY(frame) - deltaY
                    attributes.frame = frame

                    break
                }
            }
        }

        // 先按照每个 item 的 centerY 分组
        var rowCollections = [CGFloat: [UICollectionViewLayoutAttributes]]()
        for (index, attributes) in enumerate(layoutAttributes) {
            let centerY = CGRectGetMidY(attributes.frame)

            if let rowCollection = rowCollections[centerY] {
                var rowCollection = rowCollection
                rowCollection.append(attributes)
                rowCollections[centerY] = rowCollection

            } else {
                rowCollections[centerY] = [attributes]
            }
        }

        // 再调整每一行的 item 的 frame
        for (key, rowCollection) in rowCollections {
            let rowItemsCount = rowCollection.count

            // 每一行总的 InteritemSpacing
            let aggregateInteritemSpacing = minimumInteritemSpacing * CGFloat(rowItemsCount - 1)

            // 每一行所有 items 的宽度
            var aggregateItemsWidth: CGFloat = 0
            for attributes in rowCollection {<commit_msg>lock cover in Profile when scroll up<commit_after>//
//  ProfileLayout.swift
//  Yep
//
//  Created by NIX on 15/4/8.
//  Copyright (c) 2015年 Catch Inc. All rights reserved.
//

import UIKit

class ProfileLayout: UICollectionViewFlowLayout {

    let leftEdgeInset: CGFloat = YepConfig.Profile.leftEdgeInset

    override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
        let layoutAttributes = super.layoutAttributesForElementsInRect(rect) as! [UICollectionViewLayoutAttributes]
        let contentInset = collectionView!.contentInset
        let contentOffset = collectionView!.contentOffset

        let minY = -contentInset.top

        if contentOffset.y < minY {
            let deltaY = abs(contentOffset.y - minY)

            for (index, attributes) in enumerate(layoutAttributes) {
                if index == 0 {
                    var frame = attributes.frame
                    frame.size.height = max(minY, CGRectGetWidth(collectionView!.bounds) * profileAvatarAspectRatio + deltaY)
                    frame.origin.y = CGRectGetMinY(frame) - deltaY
                    attributes.frame = frame

                    break
                }
            }

        } else {
            let coverHeight = CGRectGetWidth(collectionView!.bounds) * profileAvatarAspectRatio
            let coverHideHeight = coverHeight - 64

            if contentOffset.y > coverHideHeight {

                let deltaY = abs(contentOffset.y - minY)

                for (index, attributes) in enumerate(layoutAttributes) {
                    if index == 0 {
                        var frame = attributes.frame
                        frame.origin.y = deltaY - coverHideHeight
                        attributes.frame = frame

                        break
                    }
                }
            }
        }

        // 先按照每个 item 的 centerY 分组
        var rowCollections = [CGFloat: [UICollectionViewLayoutAttributes]]()
        for (index, attributes) in enumerate(layoutAttributes) {
            let centerY = CGRectGetMidY(attributes.frame)

            if let rowCollection = rowCollections[centerY] {
                var rowCollection = rowCollection
                rowCollection.append(attributes)
                rowCollections[centerY] = rowCollection

            } else {
                rowCollections[centerY] = [attributes]
            }
        }

        // 再调整每一行的 item 的 frame
        for (key, rowCollection) in rowCollections {
            let rowItemsCount = rowCollection.count

            // 每一行总的 InteritemSpacing
            let aggregateInteritemSpacing = minimumInteritemSpacing * CGFloat(rowItemsCount - 1)

            // 每一行所有 items 的宽度
            var aggregateItemsWidth: CGFloat = 0
            for attributes in rowCollection {
{'fraction_non_alphanumeric': 0.071645415907711, 'fraction_numerical': 0.005059704513256426, 'mean_word_length': 1.8451352907311456, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2132651', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1270, 'n_words': 305}