-
-
Notifications
You must be signed in to change notification settings - Fork 624
/
Copy pathAppViewController.swift
executable file
·110 lines (85 loc) · 3.45 KB
/
AppViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import UIKit
import RxSwift
import Action
class AppViewController: UIViewController, UINavigationControllerDelegate {
var allowAnimations = true
var auctionID = AppSetup.sharedState.auctionID
@IBOutlet var countdownManager: ListingsCountdownManager!
@IBOutlet var offlineBlockingView: UIView!
@IBOutlet weak var registerToBidButton: ActionButton!
var provider: Networking!
lazy var _apiPinger: APIPingManager = {
return APIPingManager(provider: self.provider)
}()
lazy var reachability: Observable<Bool> = {
[connectedToInternetOrStubbing(), self.apiPinger].combineLatestAnd()
}()
lazy var apiPinger: Observable<Bool> = {
self._apiPinger.letOnline
}()
var registerToBidCommand = { () -> CocoaAction in
appDelegate().registerToBidCommand()
}
class func instantiate(from storyboard: UIStoryboard) -> AppViewController {
return storyboard.viewController(withID: .AppViewController) as! AppViewController
}
var sale = Variable(Sale(id: "", name: "", isAuction: true, startDate: Date(), endDate: Date(), artworkCount: 0, state: ""))
override func viewDidLoad() {
super.viewDidLoad()
registerToBidButton.rx.action = registerToBidCommand()
countdownManager.setFonts()
countdownManager.provider = provider
reachability
.bindTo(offlineBlockingView.rx_hidden)
.addDisposableTo(rx_disposeBag)
auctionRequest(provider, auctionID: auctionID)
.bindTo(sale)
.addDisposableTo(rx_disposeBag)
sale
.asObservable()
.mapToOptional()
.bindTo(countdownManager.sale)
.addDisposableTo(rx_disposeBag)
for controller in childViewControllers {
if let nav = controller as? UINavigationController {
nav.delegate = self
}
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// This is the embed segue
guard let navigtionController = segue.destination as? UINavigationController else { return }
guard let listingsViewController = navigtionController.topViewController as? ListingsViewController else { return }
listingsViewController.provider = provider
}
deinit {
countdownManager.invalidate()
}
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
let hide = (viewController as? SaleArtworkZoomViewController != nil)
countdownManager.setLabelsHiddenIfSynced(hide)
registerToBidButton.isHidden = hide
}
}
extension AppViewController {
@IBAction func longPressForAdmin(_ sender: UIGestureRecognizer) {
if sender.state != .began {
return
}
let passwordVC = PasswordAlertViewController.alertView { [weak self] in
self?.performSegue(.ShowAdminOptions)
return
}
self.present(passwordVC, animated: true) {}
}
func auctionRequest(_ provider: Networking, auctionID: String) -> Observable<Sale> {
let auctionEndpoint: ArtsyAPI = ArtsyAPI.auctionInfo(auctionID: auctionID)
return provider.request(auctionEndpoint)
.filterSuccessfulStatusCodes()
.mapJSON()
.mapTo(object: Sale.self)
.logError()
.retry()
.throttle(1, scheduler: MainScheduler.instance)
}
}