JobsNavigator.swift 2.43 KB
Newer Older
domenicw's avatar
domenicw committed
1
2
3
4
5
6
7
8
9
10
//
//  JobsNavigator.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 18.09.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation
import UIKit
domenicw's avatar
domenicw committed
11
import QuickLook
domenicw's avatar
domenicw committed
12
13
14
15
16

public class JobsNavigator: Navigator {
    
    // MARK: - Variables
    
domenicw's avatar
domenicw committed
17
18
    private var quickLookDataSource: QuickLookDataSource?
    
domenicw's avatar
domenicw committed
19
20
21
22
23
24
25
26
27
    public var rootViewController: UIViewController {
        return self.navigationController
    }
    
    private var navigationController: UINavigationController
    
    // MARK: - Initializers
    
    public init() {
28
29
        let jobs = JobsViewController()
        self.navigationController = UINavigationController(rootViewController: jobs)
domenicw's avatar
domenicw committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
        self.navigationController.navigationBar.tintColor = .amivRed
        jobs.delegate = self
    }
    
    // MARK: - Navigation
    
    private func goToJobsDetailView(model: GenericInfoViewControllerModel) {
        let info = GenericInfoViewController(model: model)
        info.delegate = self
        self.navigationController.pushViewController(info, animated: true)
    }
    
}

extension JobsNavigator: JobsViewControllerDelegate {
    
domenicw's avatar
domenicw committed
46
    public func didSelectJob(_ viewController: JobsViewController, section: Int, index: Int) {
domenicw's avatar
domenicw committed
47
48
49
50
51
52
53
        debugPrint("didSelect section: \(section) and index: \(index)")
        
        // TODO: - Retrieve job, convert into GenericInfoViewControllerModel and show Detail View
        // let model = ...
        self.goToJobsDetailView(model: .createTestModel())
    }
    
domenicw's avatar
domenicw committed
54
    public func refreshData(_ viewController: JobsViewController) {
domenicw's avatar
domenicw committed
55
56
57
58
59
60
61
        debugPrint("Refreshing Jobs Data")
    }
    
}

extension JobsNavigator: GenericInfoViewControllerDelegate {
    
domenicw's avatar
domenicw committed
62
    public func buttonTapped(_ viewController: GenericInfoViewController) {
domenicw's avatar
domenicw committed
63
64
65
66
67
68
69
70
71
72
73
74
75
        debugPrint("Info View button tapped")
        
        // TODO: - Show job description pdf using QLPreviewController
        // https://www.hackingwithswift.com/example-code/libraries/how-to-preview-files-using-quick-look-and-qlpreviewcontroller
        
        #warning("replace with actual pdf data")
        
        let url = Bundle.main.url(forResource: "Dienstverschiebungsgesuch", withExtension: "pdf")!
        let quickLook = QLPreviewController()
        let dataSource = QuickLookDataSource(urls: [url])
        self.quickLookDataSource = dataSource
        quickLook.dataSource = dataSource
        self.navigationController.present(quickLook, animated: true, completion: nil)
domenicw's avatar
domenicw committed
76
77
78
    }
    
}