<commit_before>//
//  PackageTableViewCell.swift
//  Pakete
//
//  Created by <NAME> on 12/03/2016.
//  Copyright © 2016 Pakete. All rights reserved.
//

import UIKit
import RxSwift

class PackageTableViewCell: UITableViewCell {

    static let reuseIdentifier = "PackageCell"

    let nameLabel = UILabel()
    let statusLabel = UILabel()
    let statusImageView = UIImageView()

    private var activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
    private var didSetupConstraints = false
    private var viewModel: PackageViewModel!
    private let updating: Variable<Bool> = Variable(false)

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        self.accessoryType = .DisclosureIndicator
        self.layer.rasterizationScale = UIScreen.mainScreen().scale
        self.layer.shouldRasterize = true

        self.statusImageView.translatesAutoresizingMaskIntoConstraints = false
        self.statusImageView.layer.cornerRadius = 18.0
        self.statusImageView.contentMode = .Center
        self.contentView.addSubview(self.statusImageView)

        self.activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
        self.contentView.addSubview(self.activityIndicatorView)

        self.nameLabel.translatesAutoresizingMaskIntoConstraints = false
        self.nameLabel.font = UIFont.systemFontOfSize(16.0)
        self.nameLabel.adjustFontToRealIPhoneSize = true
        self.nameLabel.numberOfLines = 0
        self.contentView.addSubview(self.nameLabel)

        self.statusLabel.translatesAutoresizingMaskIntoConstraints = false
        self.statusLabel.font = UIFont.systemFontOfSize(14.0)
        self.statusLabel.textColor = .grayColor()
        self.statusLabel.numberOfLines = 0
        self.statusLabel.adjustFontToRealIPhoneSize = true
        self.contentView.addSubview(self.statusLabel)

        self.updating.asObservable()
            .bindTo(self.activityIndicatorView.rx_animating)
            .addDisposableTo(rx_disposeBag)

        self.updating.asObservable()
            .bindTo(self.statusImageView.rx_hidden)
            .addDisposableTo(rx_disposeBag)
    }

    override func updateConstraints() {
        if !self.didSetupConstraints {
            NSLayoutConstraint.activateConstraints([
                NSLayoutConstraint(item: self.statusImageView, attribute: .CenterY, relatedBy: .Equal, toItem: self.contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Left, relatedBy: .Equal, toItem: self.contentView, attribute: .Left, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36.0),

                NSLayoutConstraint(item: self.activityIndicatorView, attribute: .CenterY, relatedBy: .Equal, toItem: self.statusImageView, attribute: .CenterY, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.activityIndicatorView, attribute: .CenterX, relatedBy: .Equal, toItem: self.statusImageView, attribute: .CenterX, multiplier: 1.0, constant: 0.0),

                NSLayoutConstraint(item: self.nameLabel, attribute: .Top, relatedBy: .Equal, toItem: self.contentView, attribute: .Top, multiplier: 1.0, constant: 10.0),
                NSLayoutConstraint(item: self.nameLabel, attribute: .Leading, relatedBy: .Equal, toItem: self.statusImageView, attribute: .Trailing, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.nameLabel, attribute: .Trailing, relatedBy: .Equal, toItem: self.contentView, attribute: .Trailing, multiplier: 1.0, constant: -10.0),

                NSLayoutConstraint(item: self.statusLabel, attribute: .Top, relatedBy: .Equal, toItem: self.nameLabel, attribute: .Bottom, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Leading, relatedBy: .Equal, toItem: self.statusImageView, attribute: .Trailing, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Trailing, relatedBy: .Equal, toItem: self.contentView, attribute: .Trailing, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Bottom, relatedBy: .Equal, toItem: self.contentView, attribute: .Bottom, multiplier: 1.0, constant: -10.0)
            ])
            self.didSetupConstraints = true
        }

        super.updateConstraints()
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        self.activityIndicatorView.stopAnimating()
        self.accessoryType = .DisclosureIndicator
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func configure(withViewModel viewModel: PackageViewModel) {
        self.viewModel = viewModel
        self.viewModel.package.asObservable()
            .subscribe({ [unowned self] _ in
                self.reloadData()
            })
            .addDisposableTo(rx_disposeBag)
    }

}

extension PackageTableViewCell {<commit_msg>reset disposebag for cells<commit_after>//
//  PackageTableViewCell.swift
//  Pakete
//
//  Created by <NAME> on 12/03/2016.
//  Copyright © 2016 Pakete. All rights reserved.
//

import UIKit
import RxSwift

class PackageTableViewCell: UITableViewCell {

    static let reuseIdentifier = "PackageCell"

    let nameLabel = UILabel()
    let statusLabel = UILabel()
    let statusImageView = UIImageView()

    private var activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
    private var didSetupConstraints = false
    private var viewModel: PackageViewModel!
    private let updating: Variable<Bool> = Variable(false)

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        self.accessoryType = .DisclosureIndicator
        self.layer.rasterizationScale = UIScreen.mainScreen().scale
        self.layer.shouldRasterize = true

        self.statusImageView.translatesAutoresizingMaskIntoConstraints = false
        self.statusImageView.layer.cornerRadius = 18.0
        self.statusImageView.contentMode = .Center
        self.contentView.addSubview(self.statusImageView)

        self.activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
        self.contentView.addSubview(self.activityIndicatorView)

        self.nameLabel.translatesAutoresizingMaskIntoConstraints = false
        self.nameLabel.font = UIFont.systemFontOfSize(16.0)
        self.nameLabel.adjustFontToRealIPhoneSize = true
        self.nameLabel.numberOfLines = 0
        self.contentView.addSubview(self.nameLabel)

        self.statusLabel.translatesAutoresizingMaskIntoConstraints = false
        self.statusLabel.font = UIFont.systemFontOfSize(14.0)
        self.statusLabel.textColor = .grayColor()
        self.statusLabel.numberOfLines = 0
        self.statusLabel.adjustFontToRealIPhoneSize = true
        self.contentView.addSubview(self.statusLabel)

        self.updating.asObservable()
            .bindTo(self.activityIndicatorView.rx_animating)
            .addDisposableTo(rx_disposeBag)

        self.updating.asObservable()
            .bindTo(self.statusImageView.rx_hidden)
            .addDisposableTo(rx_disposeBag)
    }

    override func updateConstraints() {
        if !self.didSetupConstraints {
            NSLayoutConstraint.activateConstraints([
                NSLayoutConstraint(item: self.statusImageView, attribute: .CenterY, relatedBy: .Equal, toItem: self.contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Left, relatedBy: .Equal, toItem: self.contentView, attribute: .Left, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36.0),
                NSLayoutConstraint(item: self.statusImageView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36.0),

                NSLayoutConstraint(item: self.activityIndicatorView, attribute: .CenterY, relatedBy: .Equal, toItem: self.statusImageView, attribute: .CenterY, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.activityIndicatorView, attribute: .CenterX, relatedBy: .Equal, toItem: self.statusImageView, attribute: .CenterX, multiplier: 1.0, constant: 0.0),

                NSLayoutConstraint(item: self.nameLabel, attribute: .Top, relatedBy: .Equal, toItem: self.contentView, attribute: .Top, multiplier: 1.0, constant: 10.0),
                NSLayoutConstraint(item: self.nameLabel, attribute: .Leading, relatedBy: .Equal, toItem: self.statusImageView, attribute: .Trailing, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.nameLabel, attribute: .Trailing, relatedBy: .Equal, toItem: self.contentView, attribute: .Trailing, multiplier: 1.0, constant: -10.0),

                NSLayoutConstraint(item: self.statusLabel, attribute: .Top, relatedBy: .Equal, toItem: self.nameLabel, attribute: .Bottom, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Leading, relatedBy: .Equal, toItem: self.statusImageView, attribute: .Trailing, multiplier: 1.0, constant: 15.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Trailing, relatedBy: .Equal, toItem: self.contentView, attribute: .Trailing, multiplier: 1.0, constant: 0.0),
                NSLayoutConstraint(item: self.statusLabel, attribute: .Bottom, relatedBy: .Equal, toItem: self.contentView, attribute: .Bottom, multiplier: 1.0, constant: -10.0)
            ])
            self.didSetupConstraints = true
        }

        super.updateConstraints()
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        self.activityIndicatorView.stopAnimating()
        self.accessoryType = .DisclosureIndicator
        self.rx_disposeBag = DisposeBag()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func configure(withViewModel viewModel: PackageViewModel) {
        self.viewModel = viewModel
        self.viewModel.package.asObservable()
            .subscribe({ [unowned self] _ in
                self.reloadData()
            })
            .addDisposableTo(rx_disposeBag)
    }

}

extension PackageTableViewCell {
{'fraction_non_alphanumeric': 0.09933258212706943, 'fraction_numerical': 0.014388489208633094, 'mean_word_length': 3.23568281938326, 'pattern_counts': {'":': 0, '<': 7, '<?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': '501191', 'n_tokens_mistral': 3394, 'n_tokens_neox': 3146, 'n_words': 701}