<commit_before>//
//  EventCell.swift
//  Eurofurence
//
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import UIKit
import ReactiveSwift

class EventCell: UITableViewCell {

	@IBOutlet weak var bannerImageView: UIImageView!
	@IBOutlet weak var endTimeLabel: UILabel!
	@IBOutlet weak var favoriteLabel: UILabel!
	@IBOutlet weak var startTimeLabel: UILabel!
	@IBOutlet weak var subTitleLabel: UILabel!
	@IBOutlet weak var titleLabel: UILabel!

	var defaultHeightConstraint: NSLayoutConstraint!
	var zeroHeightConstraint: NSLayoutConstraint!

	weak private var _event: Event?

	var event: Event? {
		get {
			return _event
		}
		set(event) {
			_event = event
			if let event = event {
				startTimeLabel.text = DateFormatters.hourMinute.string(from: event.StartDateTimeUtc)
				endTimeLabel.text = DateFormatters.hourMinute.string(from: event.EndDateTimeUtc)
				if let eventFavorite = event.EventFavorite {
					favoriteLabel.reactive.isHidden <~ eventFavorite.IsFavorite.map({ !$0 })
				} else {
					favoriteLabel.isHidden = true
				}
				if let _ = event.BannerImage {
					zeroHeightConstraint.isActive = false
					defaultHeightConstraint.isActive = true
					bannerImageView.updateConstraints()
				} else {
					zeroHeightConstraint.isActive = true
					defaultHeightConstraint.isActive = false
					bannerImageView.updateConstraints()
				}
			} else {
				startTimeLabel.text = nil
				endTimeLabel.text = nil
			}
			titleLabel.text = event?.Title
			subTitleLabel.text = event?.SubTitle
		}
	}

	override func awakeFromNib() {
		bannerImageView.constraints.forEach({ (constraint) in
			if constraint.identifier == "HeightConstraint" {
				self.defaultHeightConstraint = constraint
			}
		})
		zeroHeightConstraint = NSLayoutConstraint(item: bannerImageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0, constant: 0)
		zeroHeightConstraint?.isActive = false
		bannerImageView.addConstraint(zeroHeightConstraint)
	}
<commit_msg>Load banner on EventCell if present #31<commit_after>//
//  EventCell.swift
//  Eurofurence
//
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import UIKit
import ReactiveSwift

class EventCell: UITableViewCell {

	@IBOutlet weak var bannerImageView: UIImageView!
	@IBOutlet weak var endTimeLabel: UILabel!
	@IBOutlet weak var favoriteLabel: UILabel!
	@IBOutlet weak var startTimeLabel: UILabel!
	@IBOutlet weak var subTitleLabel: UILabel!
	@IBOutlet weak var titleLabel: UILabel!

	let imageService: ImageServiceProtocol = try! ServiceResolver.container.resolve()

	weak private var _event: Event?

	var event: Event? {
		get {
			return _event
		}
		set(event) {
			_event = event
			if let event = event {
				startTimeLabel.text = DateFormatters.hourMinute.string(from: event.StartDateTimeUtc)
				endTimeLabel.text = DateFormatters.hourMinute.string(from: event.EndDateTimeUtc)
				if let eventFavorite = event.EventFavorite {
					favoriteLabel.reactive.isHidden <~ eventFavorite.IsFavorite.map({ !$0 })
				} else {
					favoriteLabel.isHidden = true
				}
				if let bannerImage = event.BannerImage {
					imageService.retrieve(for: bannerImage).startWithResult({ [unowned self] (result) in
						switch result {
						case let .success(image):
							DispatchQueue.main.async {
								self.bannerImageView.image = image
							}
							break
						case .failure:
							break
						}
					})
				} else {
					let zeroHeightConstraint = NSLayoutConstraint(item: bannerImageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0, constant: 0)
					zeroHeightConstraint.isActive = true
					bannerImageView.addConstraint(zeroHeightConstraint)
					bannerImageView.updateConstraints()
				}
			} else {
				startTimeLabel.text = nil
				endTimeLabel.text = nil
			}
			titleLabel.text = event?.Title
			subTitleLabel.text = event?.SubTitle
		}
	}

{'fraction_non_alphanumeric': 0.08923548964459217, 'fraction_numerical': 0.004091025313219126, 'mean_word_length': 3.7475728155339807, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2351214', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1174, 'n_words': 283}