EventsNavigator.swift 2.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
//  EventsNavigator.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 20.09.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation
import UIKit

public class EventsNavigator: Navigator {
    
    // MARK: - Variables
    
16
    public let networkManager = NetworkManager<AMIVApiEvents>()
domenicw's avatar
domenicw committed
17
    
18
19
20
21
22
23
24
25
26
    public var rootViewController: UIViewController {
        return self.navigationController
    }
    
    private var navigationController: UINavigationController
    
    // MARK: - Initializers
    
    public init() {
domenicw's avatar
domenicw committed
27
28
        let events = EventsViewController(model: .create(with: nil))
        self.navigationController = UINavigationController(rootViewController: events)
domenicw's avatar
domenicw committed
29
        self.navigationController.navigationBar.tintColor = .amivRed
domenicw's avatar
domenicw committed
30
        events.delegate = self
domenicw's avatar
domenicw committed
31
        
domenicw's avatar
domenicw committed
32
        self.refreshData(events)
domenicw's avatar
domenicw committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    }
    
    // MARK: - Navigation
    
    private func goToEventDetailView(model: GenericInfoViewControllerModel) {
        let info = GenericInfoViewController(model: model)
        info.delegate = self
        self.navigationController.pushViewController(info, animated: true)
    }
    
}

extension EventsNavigator: EventsViewControllerDelegate {
    
domenicw's avatar
domenicw committed
47
    public func didSelectEvent(_ viewController: EventsViewController, section: Int, index: Int) {
domenicw's avatar
domenicw committed
48
49
50
51
52
53
54
        debugPrint("didSelect section: \(section) and index: \(index)")
        
        // TODO: - Retrieve event, convert into GenericInfoViewControllerModel and show Detail View
        // let model = ...
        self.goToEventDetailView(model: .createTestModel())
    }
    
domenicw's avatar
domenicw committed
55
    public func refreshData(_ viewController: EventsViewController) {
domenicw's avatar
domenicw committed
56
        debugPrint("Refreshing Events Data")
domenicw's avatar
domenicw committed
57
58
59
60
        
        self.networkManager.getEvents { (response, error) in
            if let response = response {
                DispatchQueue.main.async {
domenicw's avatar
domenicw committed
61
                    viewController.model = .create(with: response)
domenicw's avatar
domenicw committed
62
63
64
                }
            }
        }
domenicw's avatar
domenicw committed
65
66
67
68
69
70
    }
    
}

extension EventsNavigator: GenericInfoViewControllerDelegate {
    
domenicw's avatar
domenicw committed
71
    public func buttonTapped(_ viewController: GenericInfoViewController) {
domenicw's avatar
domenicw committed
72
73
74
        debugPrint("Info View button tapped")
        
        // TODO: - Sign up for event
75
76
77
    }
    
}