<commit_before>//
//  CalendarViewController.swift
//  TOZ_iOS
//  Copyright © 2017 intive. All rights reserved.
//

import UIKit
import Foundation

class CalendarViewController: UIViewController {

    @IBOutlet weak var prevButton: UIButton!
    @IBOutlet weak var nextButton: UIButton!
    @IBOutlet weak var currentDateLabel: UILabel!
    var pageController: UIPageViewController!
    var weekPages = [WeekViewController]()
    private var indexPage = 0
    var reservations: [ReservationItem] = []
    var calendarHelper = CalendarHelper()
    var weekScheduleOperation: GetScheduleWeekOperation!
    var currentWeekController: WeekViewController!
    var weekdayArray: [WeekdayItem]! {
        didSet {
            if weekdayArray.isEmpty {
                currentDateLabel.text = ""
            } else {
                let dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "MM"
                let month = dateFormatter.monthSymbols[Int(weekdayArray[0].month)! - 1]
                currentDateLabel.text = month + " " + weekdayArray[0].year
            }
        }
    }

    @IBAction func nextWeek(_ sender: Any) {
        weekdayArray = calendarHelper.nextWeek()
        currentWeekController = nextWeekController()
        retrieveReservationsinWeek(when: .forward)
    }

    @IBAction func previousWeek(_ sender: Any) {
        weekdayArray = calendarHelper.previousWeek()
        currentWeekController = nextWeekController()
        retrieveReservationsinWeek(when: .reverse)
    }

    func nextWeekController() -> WeekViewController {
        indexPage -= 1
        indexPage = abs(indexPage)

        return weekPages[indexPage]
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        pageController.dataSource = self
        // swiftlint:disable:next force_cast
        let weekAfter: WeekViewController = self.storyboard?.instantiateViewController(withIdentifier: "WeekViewController") as! WeekViewController
        // swiftlint:disable:next force_cast
        let weekBefore: WeekViewController = self.storyboard?.instantiateViewController(withIdentifier: "WeekViewController") as! WeekViewController

        weekPages.append(weekBefore)
        weekPages.append(weekAfter)
        weekBefore.delegate = self
        weekAfter.delegate = self

        weekdayArray = calendarHelper.weekdayItemArray()
        currentWeekController = weekBefore

        retrieveReservationsinWeek(when: .forward)
    }

    override func viewDidLayoutSubviews() {
        prevButton.setTitleColor(Color.Calendar.PreviousButton.text, for: .normal)
        prevButton.backgroundColor = Color.Calendar.PreviousButton.background
        nextButton.setTitleColor(Color.Calendar.NextButton.text, for: .normal)
        nextButton.backgroundColor = Color.Calendar.NextButton.background

        prevButton.layer.cornerRadius = prevButton.bounds.height * 0.5
        nextButton.layer.cornerRadius = nextButton.bounds.height * 0.5
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // swiftlint:disable:next force_cast
        pageController = segue.destination as! UIPageViewController
    }

    func retrieveReservationsinWeek(when direction: UIPageViewControllerNavigationDirection?, refreshOnly: Bool = false) {
        weekScheduleOperation = GetScheduleWeekOperation(fromDate: weekdayArray[0].dataLabel, toDate: weekdayArray[6].dataLabel)
        weekScheduleOperation.resultCompletion = { result in
            switch result {
            case .success(let listOfReservation):
                DispatchQueue.main.async {
                    self.currentWeekController.weekdayArray = self.weekdayArray
                    self.currentWeekController.reservations = listOfReservation
                    if refreshOnly == false {
                        self.pageController.setViewControllers([self.currentWeekController], direction: direction!, animated: true)
                    }
                }
            case .failure(let error):
                print ("\(error)")
            }
        }

        weekScheduleOperation.start()
    }
}

extension CalendarViewController: WeekViewControllerDelegate {
    func weekViewController(_ controller: WeekViewController, didUpdate reservations: [ReservationItem]) {
        self.reservations = controller.reservations
        retrieveReservationsinWeek(when: nil, refreshOnly: true)
    }
}

extension CalendarViewController: UIPageViewControllerDataSource {

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

        return nil
    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

        return nil
    }

}
<commit_msg>add set animation off to remove sticking paging<commit_after>//
//  CalendarViewController.swift
//  TOZ_iOS
//  Copyright © 2017 intive. All rights reserved.
//

import UIKit
import Foundation

class CalendarViewController: UIViewController {

    @IBOutlet weak var prevButton: UIButton!
    @IBOutlet weak var nextButton: UIButton!
    @IBOutlet weak var currentDateLabel: UILabel!
    var pageController: UIPageViewController!
    var weekPages = [WeekViewController]()
    private var indexPage = 0
    var reservations: [ReservationItem] = []
    var calendarHelper = CalendarHelper()
    var weekScheduleOperation: GetScheduleWeekOperation!
    var currentWeekController: WeekViewController!
    var weekdayArray: [WeekdayItem]! {
        didSet {
            if weekdayArray.isEmpty {
                currentDateLabel.text = ""
            } else {
                let dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "MM"
                let month = dateFormatter.monthSymbols[Int(weekdayArray[0].month)! - 1]
                currentDateLabel.text = month + " " + weekdayArray[0].year
            }
        }
    }

    @IBAction func nextWeek(_ sender: Any) {
        weekdayArray = calendarHelper.nextWeek()
        currentWeekController = nextWeekController()
        retrieveReservationsinWeek(when: .forward)
    }

    @IBAction func previousWeek(_ sender: Any) {
        weekdayArray = calendarHelper.previousWeek()
        currentWeekController = nextWeekController()
        retrieveReservationsinWeek(when: .reverse)
    }

    func nextWeekController() -> WeekViewController {
        indexPage -= 1
        indexPage = abs(indexPage)

        return weekPages[indexPage]
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        pageController.dataSource = self
        // swiftlint:disable:next force_cast
        let weekAfter: WeekViewController = self.storyboard?.instantiateViewController(withIdentifier: "WeekViewController") as! WeekViewController
        // swiftlint:disable:next force_cast
        let weekBefore: WeekViewController = self.storyboard?.instantiateViewController(withIdentifier: "WeekViewController") as! WeekViewController

        weekPages.append(weekBefore)
        weekPages.append(weekAfter)
        weekBefore.delegate = self
        weekAfter.delegate = self

        weekdayArray = calendarHelper.weekdayItemArray()
        currentWeekController = weekBefore

        retrieveReservationsinWeek(when: .forward)
    }

    override func viewDidLayoutSubviews() {
        prevButton.setTitleColor(Color.Calendar.PreviousButton.text, for: .normal)
        prevButton.backgroundColor = Color.Calendar.PreviousButton.background
        nextButton.setTitleColor(Color.Calendar.NextButton.text, for: .normal)
        nextButton.backgroundColor = Color.Calendar.NextButton.background

        prevButton.layer.cornerRadius = prevButton.bounds.height * 0.5
        nextButton.layer.cornerRadius = nextButton.bounds.height * 0.5
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // swiftlint:disable:next force_cast
        pageController = segue.destination as! UIPageViewController
    }

    func retrieveReservationsinWeek(when direction: UIPageViewControllerNavigationDirection?, refreshOnly: Bool = false) {
        weekScheduleOperation = GetScheduleWeekOperation(fromDate: weekdayArray[0].dataLabel, toDate: weekdayArray[6].dataLabel)
        weekScheduleOperation.resultCompletion = { result in
            switch result {
            case .success(let listOfReservation):
                DispatchQueue.main.async {
                    self.currentWeekController.weekdayArray = self.weekdayArray
                    self.currentWeekController.reservations = listOfReservation
                    if refreshOnly == false {
                        self.pageController.setViewControllers([self.currentWeekController], direction: direction!, animated: false)
                    }
                }
            case .failure(let error):
                print ("\(error)")
            }
        }

        weekScheduleOperation.start()
    }
}

extension CalendarViewController: WeekViewControllerDelegate {
    func weekViewController(_ controller: WeekViewController, didUpdate reservations: [ReservationItem]) {
        self.reservations = controller.reservations
        retrieveReservationsinWeek(when: nil, refreshOnly: true)
    }
}

extension CalendarViewController: UIPageViewControllerDataSource {

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

        return nil
    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

        return nil
    }

}

{'fraction_non_alphanumeric': 0.07686788972020088, 'fraction_numerical': 0.0030747155888080353, 'mean_word_length': 2.947411003236246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7132436', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2342, 'n_words': 509}