<commit_before>//
//  AddMealDataSource.swift
//  MetabolicCompass
//
//  Created by <NAME> on 6/6/16.
//  Copyright © 2016 <NAME>, <NAME>. All rights reserved.
//

import UIKit

public let typeCellIdentifier = "typeCellIdentifier"
public let whenCellIdentifier = "whenCellIdentifier"
public let durationCellIdentifier = "durationCellIdentifier"
public let pickerCellIdentifier = "pickerCellIdentifier"
public let datePickerCellIdentifier = "datePickerCellIdentifier"
public let startSleepCellIdentifier = "startSleepCellIdentifier"
public let endSleepCellIdentifier = "endSleepCellIdentifier"

class AddMealDataSource: NSObject, UITableViewDataSource, UITableViewDelegate, PickerTableViewCellDelegate, DatePickerTableViewCellDelegate {
    
    var addEventModel: AddEventModel? = nil
    var dataSourceCells: [String] = [typeCellIdentifier, whenCellIdentifier, durationCellIdentifier]//default cells types
    var sleepMode = false
    
    private var typeCell: TypeTableViewCell? = nil
    private var whenCell: WhenTableViewCell? = nil
    private var durationCell: DurationTableViewCell? = nil
    private var startSleepCell: StartSleepTableViewCell? = nil
    private var endSleepCell: EndSleepTableViewCell? = nil

    private var pickerIndexPath: NSIndexPath? = nil
    private let defaultCellHeight: CGFloat = 80.0
    private let defaultPickerHeight: CGFloat = 216.0
    
    //MARK: UITableViewDataSource
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSourceCells.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: UITableViewCell? = nil
        let cellIdentifier = dataSourceCells[indexPath.row]
        cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
        
        switch cellIdentifier {
            case startSleepCellIdentifier:
                self.startSleepCell = cell as? StartSleepTableViewCell
                self.startSleepCell?.timeLabel.text = addEventModel?.getStartSleepTimeString()
                self.startSleepCell?.dayLabel.text = addEventModel?.getStartSleepForDayLabel()
            case endSleepCellIdentifier:
                self.endSleepCell = cell as? EndSleepTableViewCell
                self.endSleepCell?.timeLabel.text = addEventModel?.getSleepEndTimeString()
                self.endSleepCell?.dayLabel.text = addEventModel?.getEndSleepForDayLabel()
            case typeCellIdentifier:
                self.typeCell = cell as? TypeTableViewCell
                self.typeCell?.typeLabel.text = addEventModel?.mealType.rawValue
            case whenCellIdentifier:
                self.whenCell = cell as? WhenTableViewCell
                self.whenCell?.timeLabel.text = addEventModel?.getTextForTimeLabel()
                self.whenCell?.dayLabel.text = addEventModel?.getTextForDayLabel()
            case durationCellIdentifier:
                self.durationCell = cell as? DurationTableViewCell
                self.durationCell?.durationLabel.attributedText = addEventModel?.getTextForTimeInterval()
            case pickerCellIdentifier:
                let pickerCell = cell as! PickerTableViewCell
                pickerCell.pickerCellDelegate = self
                let row = pickerCell.components.indexOf((addEventModel?.mealType.rawValue)!)
                pickerCell.pickerView.selectRow(row!, inComponent: 0, animated: false)
            case datePickerCellIdentifier:
                let datePickerCell = cell as! DatePickerTableViewCell
                datePickerCell.delegate = self
                if addEventModel!.datePickerRow(indexPath.row) {//date and time
                    datePickerCell.datePicker.datePickerMode = .DateAndTime
                    datePickerCell.datePicker.tag = indexPath.row
                    if sleepMode {
                        let startSleepPickerTag = addEventModel?.datePickerTags.first
                        switch indexPath.row {
                            case startSleepPickerTag!:
                                datePickerCell.datePicker.date = (addEventModel?.sleepStartDate)!
                            default:
                                datePickerCell.datePicker.date = (addEventModel?.sleepEndDate)!
                        }
                    } else {
                        datePickerCell.datePicker.date = (addEventModel?.eventDate)!
                    }
                } else if addEventModel!.countDownPickerRow(indexPath.row)  {//countdoun
                    datePickerCell.datePicker.datePickerMode = .CountDownTimer<commit_msg>Switched detailed events date pickers to use a 5 minute granularity<commit_after>//
//  AddMealDataSource.swift
//  MetabolicCompass
//
//  Created by <NAME> on 6/6/16.
//  Copyright © 2016 <NAME>, <NAME>. All rights reserved.
//

import UIKit

public let typeCellIdentifier = "typeCellIdentifier"
public let whenCellIdentifier = "whenCellIdentifier"
public let durationCellIdentifier = "durationCellIdentifier"
public let pickerCellIdentifier = "pickerCellIdentifier"
public let datePickerCellIdentifier = "datePickerCellIdentifier"
public let startSleepCellIdentifier = "startSleepCellIdentifier"
public let endSleepCellIdentifier = "endSleepCellIdentifier"

class AddMealDataSource: NSObject, UITableViewDataSource, UITableViewDelegate, PickerTableViewCellDelegate, DatePickerTableViewCellDelegate {
    
    var addEventModel: AddEventModel? = nil
    var dataSourceCells: [String] = [typeCellIdentifier, whenCellIdentifier, durationCellIdentifier]//default cells types
    var sleepMode = false
    
    private var typeCell: TypeTableViewCell? = nil
    private var whenCell: WhenTableViewCell? = nil
    private var durationCell: DurationTableViewCell? = nil
    private var startSleepCell: StartSleepTableViewCell? = nil
    private var endSleepCell: EndSleepTableViewCell? = nil

    private var pickerIndexPath: NSIndexPath? = nil
    private let defaultCellHeight: CGFloat = 80.0
    private let defaultPickerHeight: CGFloat = 216.0
    
    //MARK: UITableViewDataSource
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSourceCells.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: UITableViewCell? = nil
        let cellIdentifier = dataSourceCells[indexPath.row]
        cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
        
        switch cellIdentifier {
            case startSleepCellIdentifier:
                self.startSleepCell = cell as? StartSleepTableViewCell
                self.startSleepCell?.timeLabel.text = addEventModel?.getStartSleepTimeString()
                self.startSleepCell?.dayLabel.text = addEventModel?.getStartSleepForDayLabel()
            case endSleepCellIdentifier:
                self.endSleepCell = cell as? EndSleepTableViewCell
                self.endSleepCell?.timeLabel.text = addEventModel?.getSleepEndTimeString()
                self.endSleepCell?.dayLabel.text = addEventModel?.getEndSleepForDayLabel()
            case typeCellIdentifier:
                self.typeCell = cell as? TypeTableViewCell
                self.typeCell?.typeLabel.text = addEventModel?.mealType.rawValue
            case whenCellIdentifier:
                self.whenCell = cell as? WhenTableViewCell
                self.whenCell?.timeLabel.text = addEventModel?.getTextForTimeLabel()
                self.whenCell?.dayLabel.text = addEventModel?.getTextForDayLabel()
            case durationCellIdentifier:
                self.durationCell = cell as? DurationTableViewCell
                self.durationCell?.durationLabel.attributedText = addEventModel?.getTextForTimeInterval()
            case pickerCellIdentifier:
                let pickerCell = cell as! PickerTableViewCell
                pickerCell.pickerCellDelegate = self
                let row = pickerCell.components.indexOf((addEventModel?.mealType.rawValue)!)
                pickerCell.pickerView.selectRow(row!, inComponent: 0, animated: false)
            case datePickerCellIdentifier:
                let datePickerCell = cell as! DatePickerTableViewCell
                datePickerCell.delegate = self
                if addEventModel!.datePickerRow(indexPath.row) {//date and time
                    datePickerCell.datePicker.datePickerMode = .DateAndTime
                    datePickerCell.datePicker.minuteInterval = 5
                    datePickerCell.datePicker.tag = indexPath.row
                    if sleepMode {
                        let startSleepPickerTag = addEventModel?.datePickerTags.first
                        switch indexPath.row {
                            case startSleepPickerTag!:
                                datePickerCell.datePicker.date = (addEventModel?.sleepStartDate)!
                            default:
                                datePickerCell.datePicker.date = (addEventModel?.sleepEndDate)!
                        }
                    } else {
                        datePickerCell.datePicker.date = (addEventModel?.eventDate)!
                    }
                } else if addEventModel!.countDownPickerRow(indexPath.row)  {//countdoun
                    datePickerCell.datePicker.datePickerMode = .CountDownTimer
                    datePickerCell.datePicker.minuteInterval = 5
{'fraction_non_alphanumeric': 0.0676246830092984, 'fraction_numerical': 0.0036982248520710057, 'mean_word_length': 2.5409652076318743, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '7054042', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2247, 'n_words': 495}