-
-
Notifications
You must be signed in to change notification settings - Fork 991
Expand file tree
/
Copy pathNCIntroViewController.swift
More file actions
186 lines (151 loc) · 7.78 KB
/
NCIntroViewController.swift
File metadata and controls
186 lines (151 loc) · 7.78 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// SPDX-FileCopyrightText: Nextcloud GmbH
// SPDX-FileCopyrightText: 2019 Marino Faggiana
// SPDX-FileCopyrightText: 2019 Philippe Weidmann
// SPDX-License-Identifier: GPL-3.0-or-later
import UIKit
class NCIntroViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var buttonLogin: UIButton!
@IBOutlet weak var buttonSignUp: UIButton!
@IBOutlet weak var buttonHost: UIButton!
@IBOutlet weak var introCollectionView: UICollectionView!
@IBOutlet weak var pageControl: UIPageControl!
weak var delegate: NCIntroViewController?
// Controller
var controller: NCMainTabBarController?
private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
private let titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
private let images = [UIImage(named: "intro1"), UIImage(named: "intro2"), UIImage(named: "intro3"), UIImage(named: "intro4")]
private var timer: Timer?
private var textColor: UIColor = .white
private var textColorOpponent: UIColor = .black
private var activeLoginProvider: NCLoginProvider?
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
let isTooLight = NCBrandColor.shared.customer.isTooLight()
let isTooDark = NCBrandColor.shared.customer.isTooDark()
if isTooLight {
textColor = .black
textColorOpponent = .white
} else if isTooDark {
textColor = .white
textColorOpponent = .black
} else {
textColor = .white
textColorOpponent = .black
}
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithTransparentBackground()
navBarAppearance.shadowColor = .clear
navBarAppearance.shadowImage = UIImage()
self.navigationController?.navigationBar.standardAppearance = navBarAppearance
self.navigationController?.view.backgroundColor = NCBrandColor.shared.customer
self.navigationController?.navigationBar.tintColor = textColor
if !NCManageDatabase.shared.getAllTableAccount().isEmpty {
let navigationItemCancel = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .plain, target: self, action: #selector(actionCancel(_:)))
navigationItemCancel.tintColor = textColor
navigationItem.leftBarButtonItem = navigationItemCancel
}
pageControl.currentPageIndicatorTintColor = textColor
pageControl.pageIndicatorTintColor = .lightGray
buttonLogin.layer.cornerRadius = 8
buttonLogin.setTitleColor(NCBrandColor.shared.customer, for: .normal)
buttonLogin.backgroundColor = textColor
buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
buttonSignUp.layer.cornerRadius = 8
buttonSignUp.setTitleColor(textColor, for: .normal)
buttonSignUp.backgroundColor = textColor.withAlphaComponent(0.2)
buttonSignUp.titleLabel?.adjustsFontSizeToFitWidth = true
buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
buttonHost.layer.cornerRadius = 20
buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
buttonHost.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
introCollectionView.register(UINib(nibName: "NCIntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
introCollectionView.dataSource = self
introCollectionView.delegate = self
introCollectionView.backgroundColor = NCBrandColor.shared.customer
pageControl.numberOfPages = self.titles.count
view.backgroundColor = NCBrandColor.shared.customer
self.timer = Timer.scheduledTimer(timeInterval: 4, target: self, selector: (#selector(self.autoScroll(_:))), userInfo: nil, repeats: true)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
if traitCollection.userInterfaceStyle == .light {
return .lightContent
} else {
return .darkContent
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
timer?.invalidate()
timer = nil
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil) { _ in
self.pageControl?.currentPage = 0
self.introCollectionView?.collectionViewLayout.invalidateLayout()
}
}
@objc func autoScroll(_ sender: Any?) {
if pageControl.currentPage + 1 >= titles.count {
pageControl.currentPage = 0
} else {
pageControl.currentPage += 1
}
introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
}
func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
return CGPoint.zero
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return titles.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = (collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as? NCIntroCollectionViewCell)!
cell.backgroundColor = NCBrandColor.shared.customer
cell.indexPath = indexPath
cell.titleLabel.textColor = textColor
cell.titleLabel.text = titles[indexPath.row]
cell.imageView.image = images[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return collectionView.bounds.size
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
timer = Timer.scheduledTimer(timeInterval: 4, target: self, selector: (#selector(autoScroll(_:))), userInfo: nil, repeats: true)
pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
timer?.invalidate()
timer = nil
}
// MARK: - Action
@objc func actionCancel(_ sender: Any?) {
dismiss(animated: true) { }
}
@IBAction func login(_ sender: Any) {
if let viewController = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin {
viewController.controller = self.controller
self.navigationController?.pushViewController(viewController, animated: true)
}
}
@IBAction func signupWithProvider(_ sender: Any) {
let loginProvider = NCLoginProvider()
loginProvider.controller = self.controller
loginProvider.initialURLString = NCBrandOptions.shared.linkloginPreferredProviders
loginProvider.presentingViewController = self
loginProvider.startAuthentication()
self.activeLoginProvider = loginProvider
}
@IBAction func host(_ sender: Any) {
guard let url = URL(string: NCBrandOptions.shared.linkLoginHost) else { return }
UIApplication.shared.open(url)
}
}
extension UINavigationController {
open override var childForStatusBarStyle: UIViewController? {
return topViewController?.childForStatusBarStyle ?? topViewController
}
}