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

import Foundation
import UIKit

protocol WebLinkDelegate: NSObjectProtocol {
    func webLinkTapped(type: ElloURI, data: String)
}

protocol UserDelegate: NSObjectProtocol {
    func userTapped(cell: UICollectionViewCell) -> Void
}

class StreamViewController: BaseElloViewController {

    @IBOutlet weak var collectionView: UICollectionView!
    var pulsingCircle : PulsingCircle?
    var scrolling = false
    var streamables:[Streamable]?
    var dataSource:StreamDataSource!
    var navBarShowing = true

    var streamKind:StreamKind = StreamKind.Friend {
        didSet { setupCollectionViewLayout() }
    }
    var imageViewerDelegate:StreamImageViewer?
    var updatedStreamImageCellHeightNotification:NotificationObserver?
    weak var postTappedDelegate : PostTappedDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        initialSetup()
    }

    // If we ever create an init() method that doesn't use nib/storyboards,
    // we'll need to call this.  Called from awakeFromNib and init.
    private func initialSetup() {
        setupImageViewDelegate()
        setupDataSource()
        addNotificationObservers()
    }

    deinit {
        removeNotificationObservers()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setupCollectionView()
        setupPulsingCircle()
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        if let pulsingCircle = self.pulsingCircle {
            let (width, height) = (self.view.frame.size.width, self.view.frame.size.height)
            let center = CGPoint(x: width / 2, y: height / 2)
            pulsingCircle.center = center
        }
    }

    class func instantiateFromStoryboard(storyboard: UIStoryboard = UIStoryboard.iPhone()) -> StreamViewController {
        return storyboard.controllerWithID(.Stream) as StreamViewController
    }

// MARK: Public Functions

    func doneLoading() {
        if let circle = pulsingCircle {
            circle.stopPulse() { finished in
                circle.removeFromSuperview()
            }
            pulsingCircle = nil
        }
    }

    func imageCellHeightUpdated(cell:StreamImageCell) {
        if let indexPath = collectionView.indexPathForCell(cell) {
            self.updateCellHeight(indexPath, height: cell.calculatedHeight)
        }
    }

    func addStreamCellItems(items: [StreamCellItem]) {
        self.dataSource.addStreamCellItems(items)
        self.collectionView.reloadData()
    }

    func addStreamables(streamables:[Streamable]) {
        self.dataSource.addStreamables(streamables, startingIndexPath:nil) { (cellCount) -> () in
            self.collectionView.reloadData()
        }
<<<<<<< HEAD
=======
        // loves
        // reposts
        // omnibar button
        let streamService = StreamService()
        streamService.loadMoreCommentsForPost(post.postId,
            success: { (streamables) -> () in
                self.dataSource.addStreamables(streamables, completion: { (indexPaths) -> () in
                    self.collectionView.dataSource = self.dataSource
                    self.collectionView.insertItemsAtIndexPaths(indexPaths)
                    }, startingIndexPath:nil)
            }) { (error, statusCode) -> () in
                println("failed to load comments")
        }
>>>>>>> Add user tapped and avatar button to cell headers.
    }

// MARK: Private Functions

    private func setupPulsingCircle() {
        pulsingCircle = PulsingCircle.fill(self.view)
        self.view.addSubview(pulsingCircle!)
        pulsingCircle!.pulse()
    }

    private func addNotificationObservers() {
        updatedStreamImageCellHeightNotification = NotificationObserver(notification: updateStreamImageCellHeightNotification) { streamTextCell in
            self.imageCellHeightUpdated(streamTextCell)
        }<commit_msg>Remove a method from a merge conflict.<commit_after>//
//  StreamViewController.swift
//  Ello
//
//  Created by <NAME> on 11/21/14.
//  Copyright (c) 2014 Ello. All rights reserved.
//

import Foundation
import UIKit

protocol WebLinkDelegate: NSObjectProtocol {
    func webLinkTapped(type: ElloURI, data: String)
}

protocol UserDelegate: NSObjectProtocol {
    func userTapped(cell: UICollectionViewCell) -> Void
}

class StreamViewController: BaseElloViewController {

    @IBOutlet weak var collectionView: UICollectionView!
    var pulsingCircle : PulsingCircle?
    var scrolling = false
    var streamables:[Streamable]?
    var dataSource:StreamDataSource!
    var navBarShowing = true

    var streamKind:StreamKind = StreamKind.Friend {
        didSet { setupCollectionViewLayout() }
    }
    var imageViewerDelegate:StreamImageViewer?
    var updatedStreamImageCellHeightNotification:NotificationObserver?
    weak var postTappedDelegate : PostTappedDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        initialSetup()
    }

    // If we ever create an init() method that doesn't use nib/storyboards,
    // we'll need to call this.  Called from awakeFromNib and init.
    private func initialSetup() {
        setupImageViewDelegate()
        setupDataSource()
        addNotificationObservers()
    }

    deinit {
        removeNotificationObservers()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setupCollectionView()
        setupPulsingCircle()
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        if let pulsingCircle = self.pulsingCircle {
            let (width, height) = (self.view.frame.size.width, self.view.frame.size.height)
            let center = CGPoint(x: width / 2, y: height / 2)
            pulsingCircle.center = center
        }
    }

    class func instantiateFromStoryboard(storyboard: UIStoryboard = UIStoryboard.iPhone()) -> StreamViewController {
        return storyboard.controllerWithID(.Stream) as StreamViewController
    }

// MARK: Public Functions

    func doneLoading() {
        if let circle = pulsingCircle {
            circle.stopPulse() { finished in
                circle.removeFromSuperview()
            }
            pulsingCircle = nil
        }
    }

    func imageCellHeightUpdated(cell:StreamImageCell) {
        if let indexPath = collectionView.indexPathForCell(cell) {
            self.updateCellHeight(indexPath, height: cell.calculatedHeight)
        }
    }

    func addStreamCellItems(items: [StreamCellItem]) {
        self.dataSource.addStreamCellItems(items)
        self.collectionView.reloadData()
    }

    func addStreamables(streamables:[Streamable]) {
        self.dataSource.addStreamables(streamables, startingIndexPath:nil) { (cellCount) -> () in
            self.collectionView.reloadData()
        }
    }

// MARK: Private Functions

    private func setupPulsingCircle() {
        pulsingCircle = PulsingCircle.fill(self.view)
        self.view.addSubview(pulsingCircle!)
        pulsingCircle!.pulse()
    }

    private func addNotificationObservers() {
        updatedStreamImageCellHeightNotification = NotificationObserver(notification: updateStreamImageCellHeightNotification) { streamTextCell in
            self.imageCellHeightUpdated(streamTextCell)
        }
{'fraction_non_alphanumeric': 0.08659821669818968, 'fraction_numerical': 0.0032423669278573357, 'mean_word_length': 2.7635993899339093, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 21, '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': '3430296', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1983, 'n_words': 434}