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

import UIKit
import WebKit

class FriendsDataSource: NSObject, UICollectionViewDataSource {

    typealias StreamContentReady = () -> ()

    enum CellIdentifier: String {
        case Header = "StreamHeaderCell"
        case Footer = "StreamFooterCell"
        case Image = "StreamImageCell"
        case Text = "StreamTextCell"
        case Comment = "StreamCommentCell"
        case Unknown = "StreamUnknownCell"
    }

    var indexFile:String?
    var contentReadyClosure:StreamContentReady?
    var streamCellItems:[StreamCellItem]?
    let testWebView:UIWebView
    let sizeCalculator:StreamTextCellSizeCalculator

    init(testWebView: UIWebView) {
        self.testWebView = testWebView
        self.sizeCalculator = StreamTextCellSizeCalculator(webView: testWebView)
        super.init()
    }

    func addActivities(activities:[Activity], completion:StreamContentReady) {
        self.contentReadyClosure = completion
        self.streamCellItems = self.createStreamCellItems(activities)
    }

    func updateHeightForIndexPath(indexPath:NSIndexPath?, height:CGFloat) {
        if let indexPath = indexPath {
            streamCellItems?[indexPath.item].cellHeight = height
        }
    }

    func heightForIndexPath(indexPath:NSIndexPath) -> CGFloat {
        return streamCellItems?[indexPath.item].cellHeight ?? 0.0
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return streamCellItems?.count ?? 0
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        if let streamCellItem = streamCellItems?[indexPath.item] {
            let activity = streamCellItem.activity
            switch activity.subjectType {<commit_msg>Retrieve post and cells from Friends Data Source<commit_after>//
//  FriendsDataSource.swift
//  Ello
//
//  Created by <NAME> on 11/22/14.
//  Copyright (c) 2014 Ello. All rights reserved.
//

import UIKit
import WebKit

class FriendsDataSource: NSObject, UICollectionViewDataSource {

    typealias StreamContentReady = () -> ()

    enum CellIdentifier: String {
        case Header = "StreamHeaderCell"
        case Footer = "StreamFooterCell"
        case Image = "StreamImageCell"
        case Text = "StreamTextCell"
        case Comment = "StreamCommentCell"
        case Unknown = "StreamUnknownCell"
    }

    var indexFile:String?
    var contentReadyClosure:StreamContentReady?
    var streamCellItems:[StreamCellItem]?
    let testWebView:UIWebView
    let sizeCalculator:StreamTextCellSizeCalculator

    init(testWebView: UIWebView) {
        self.testWebView = testWebView
        self.sizeCalculator = StreamTextCellSizeCalculator(webView: testWebView)
        super.init()
    }
    
    func postForIndexPath(indexPath:NSIndexPath) -> Post? {
        if indexPath.item >= streamCellItems?.count {
            return nil
        }
        return streamCellItems?[indexPath.item].activity.subject as? Post
    }
    
    func cellItemsForPost(post:Post) -> [StreamCellItem]? {
        return streamCellItems?.filter({ (item) -> Bool in
            if let cellPost = item.activity.subject as? Post {
                return post.postId == cellPost.postId
            }
            else {
                return false
            }
        })
    }

    func addActivities(activities:[Activity], completion:StreamContentReady) {
        self.contentReadyClosure = completion
        self.streamCellItems = self.createStreamCellItems(activities)
    }

    func updateHeightForIndexPath(indexPath:NSIndexPath?, height:CGFloat) {
        if let indexPath = indexPath {
            streamCellItems?[indexPath.item].cellHeight = height
        }
    }

    func heightForIndexPath(indexPath:NSIndexPath) -> CGFloat {
        return streamCellItems?[indexPath.item].cellHeight ?? 0.0
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return streamCellItems?.count ?? 0
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        if let streamCellItem = streamCellItems?[indexPath.item] {
            let activity = streamCellItem.activity
            switch activity.subjectType {
{'fraction_non_alphanumeric': 0.08420583648919581, 'fraction_numerical': 0.0057919358431721985, 'mean_word_length': 2.9664310954063606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4933894', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1226, 'n_words': 263}