<commit_before>//
//  HallsSelectionViewController.swift
//  PennMobile
//
//  Created by <NAME> on 2017/11/5.
//  Copyright © 2017年 PennLabs. All rights reserved.
//

import UIKit

protocol HallSelectionDelegate: class {
    func saveSelection(for halls: [LaundryHall])
}

class HallSelectionViewController: UIViewController, ShowsAlert, Trackable, IndicatorEnabled {
    
    weak var delegate: HallSelectionDelegate?
    
    fileprivate let maxNumHalls = 3
    
    var chosenHalls = [LaundryHall]()
    
    // Views
    fileprivate lazy var selectionView: HallSelectionView = {
        let hsv = HallSelectionView(frame: .zero)
        hsv.delegate = self
        return hsv
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        // set up navbar
        navigationItem.title = "\(chosenHalls.count)/\(maxNumHalls) Chosen"
        self.navigationController?.navigationBar.tintColor = UIColor.navRed
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .done, target: self, action: #selector(handleCancel))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save", style: .done, target: self, action: #selector(handleSave))
        
        view.backgroundColor = .white
        
        view.addSubview(selectionView)
        selectionView.anchorToTop(nil, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor)
        if #available(iOS 11.0, *) {
            selectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
        } else {
            selectionView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 0).isActive = true
        }
        
        trackScreen("Hall Selection")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationItem.title = "\(chosenHalls.count)/\(maxNumHalls) Chosen"
        selectionView.prepare(with: chosenHalls)
    }
}

extension HallSelectionViewController: HallSelectionViewDelegate {
    func updateSelectedHalls(for halls: [LaundryHall]) {
        navigationItem.title = "\(halls.count)/\(selectionView.maxNumHalls) Chosen"<commit_msg>refactoring<commit_after>//
//  HallsSelectionViewController.swift
//  PennMobile
//
//  Created by <NAME> on 2017/11/5.
//  Copyright © 2017年 PennLabs. All rights reserved.
//

import UIKit

protocol HallSelectionDelegate: class {
    func saveSelection(for halls: [LaundryHall])
}

class HallSelectionViewController: UIViewController, ShowsAlert, Trackable {
    
    weak var delegate: HallSelectionDelegate?
    
    fileprivate let maxNumHalls = 3
    
    var chosenHalls = [LaundryHall]()
    
    // Views
    fileprivate lazy var selectionView: HallSelectionView = {
        let hsv = HallSelectionView(frame: .zero)
        hsv.delegate = self
        return hsv
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.title = "\(chosenHalls.count)/\(maxNumHalls) Chosen"
        self.navigationController?.navigationBar.tintColor = UIColor.navRed
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .done, target: self, action: #selector(handleCancel))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save", style: .done, target: self, action: #selector(handleSave))
        
        view.backgroundColor = .white
        
        view.addSubview(selectionView)
        selectionView.anchorToTop(nil, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor)
        if #available(iOS 11.0, *) {
            selectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
        } else {
            selectionView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 0).isActive = true
        }
        
        trackScreen("Hall Selection")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationItem.title = "\(chosenHalls.count)/\(maxNumHalls) Chosen"
        selectionView.prepare(with: chosenHalls)
    }
}

extension HallSelectionViewController: HallSelectionViewDelegate {
    func updateSelectedHalls(for halls: [LaundryHall]) {
        navigationItem.title = "\(halls.count)/\(selectionView.maxNumHalls) Chosen"
{'fraction_non_alphanumeric': 0.10054719562243503, 'fraction_numerical': 0.007751937984496124, 'mean_word_length': 3.134778510838831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5453263', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1235, 'n_words': 259}