NCIntroViewController.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // NCIntroViewController.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.12.19.
  6. // Copyright © 2019 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2019 Marino Faggiana All rights reserved.
  8. //
  9. // Author Philippe Weidmann
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import UIKit
  26. class NCIntroViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  27. @IBOutlet weak var buttonLogin: UIButton!
  28. @IBOutlet weak var buttonSignUp: UIButton!
  29. @IBOutlet weak var buttonHost: UIButton!
  30. @IBOutlet weak var introCollectionView: UICollectionView!
  31. @IBOutlet weak var pageControl: UIPageControl!
  32. @objc var delegate: NCIntroViewController?
  33. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  34. private let titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
  35. private let images = [UIImage(named: "intro1"), UIImage(named: "intro2"), UIImage(named: "intro3"), UIImage(named: "intro4")]
  36. private var timerAutoScroll: Timer?
  37. private var textColor: UIColor = .white
  38. private var textColorOpponent: UIColor = .black
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. let isTooLight = NCBrandColor.shared.customer.isTooLight()
  42. let isTooDark = NCBrandColor.shared.customer.isTooDark()
  43. if isTooLight {
  44. textColor = .black
  45. textColorOpponent = .white
  46. } else if isTooDark {
  47. textColor = .white
  48. textColorOpponent = .black
  49. } else {
  50. textColor = .white
  51. textColorOpponent = .black
  52. }
  53. if #available(iOS 13.0, *) {
  54. let navBarAppearance = UINavigationBarAppearance()
  55. navBarAppearance.configureWithTransparentBackground()
  56. navBarAppearance.shadowColor = .clear
  57. navBarAppearance.shadowImage = UIImage()
  58. self.navigationController?.navigationBar.standardAppearance = navBarAppearance
  59. } else {
  60. self.navigationController?.navigationBar.isTranslucent = true
  61. self.navigationController?.navigationBar.shadowImage = UIImage()
  62. self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  63. self.navigationController?.navigationBar.backgroundColor = .clear
  64. self.navigationController?.navigationBar.barTintColor = NCBrandColor.shared.customer
  65. }
  66. self.navigationController?.navigationBar.tintColor = textColor
  67. self.pageControl.currentPageIndicatorTintColor = textColor
  68. self.pageControl.pageIndicatorTintColor = NCBrandColor.shared.nextcloudSoft
  69. self.buttonLogin.layer.cornerRadius = 20
  70. self.buttonLogin.setTitleColor(textColorOpponent, for: .normal)
  71. self.buttonLogin.backgroundColor = textColor
  72. self.buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
  73. self.buttonSignUp.layer.cornerRadius = 20
  74. self.buttonSignUp.setTitleColor(.white, for: .normal)
  75. self.buttonSignUp.backgroundColor = UIColor(red: 25.0 / 255.0, green: 89.0 / 255.0, blue: 141.0 / 255.0, alpha: 1)
  76. self.buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
  77. self.buttonHost.layer.cornerRadius = 20
  78. self.buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
  79. self.buttonHost.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
  80. self.introCollectionView.register(UINib(nibName: "NCIntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
  81. self.introCollectionView.dataSource = self
  82. self.introCollectionView.delegate = self
  83. self.introCollectionView.backgroundColor = NCBrandColor.shared.customer
  84. self.pageControl.numberOfPages = self.titles.count
  85. self.view.backgroundColor = NCBrandColor.shared.customer
  86. self.timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  87. }
  88. override var preferredStatusBarStyle: UIStatusBarStyle {
  89. if #available(iOS 13.0, *) {
  90. if traitCollection.userInterfaceStyle == .light {
  91. return .lightContent
  92. } else {
  93. return .darkContent
  94. }
  95. } else {
  96. return .lightContent
  97. }
  98. }
  99. override func viewWillDisappear(_ animated: Bool) {
  100. super.viewWillDisappear(animated)
  101. timerAutoScroll?.invalidate()
  102. }
  103. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  104. pageControl.currentPage = 0
  105. introCollectionView.collectionViewLayout.invalidateLayout()
  106. }
  107. @objc func autoScroll() {
  108. if(pageControl.currentPage + 1 >= titles.count) {
  109. pageControl.currentPage = 0
  110. }
  111. else {
  112. pageControl.currentPage += 1
  113. }
  114. introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
  115. }
  116. func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  117. return CGPoint.zero
  118. }
  119. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  120. return titles.count
  121. }
  122. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  123. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as! NCIntroCollectionViewCell
  124. cell.backgroundColor = NCBrandColor.shared.customer
  125. cell.titleLabel.textColor = textColor
  126. cell.titleLabel.text = titles[indexPath.row]
  127. cell.imageView.image = images[indexPath.row]
  128. return cell
  129. }
  130. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  131. return collectionView.bounds.size
  132. }
  133. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  134. timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  135. pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
  136. }
  137. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  138. timerAutoScroll?.invalidate()
  139. }
  140. @IBAction func login(_ sender: Any) {
  141. appDelegate.openLogin(viewController: navigationController, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
  142. }
  143. @IBAction func signup(_ sender: Any) {
  144. appDelegate.openLogin(viewController: navigationController, selector: NCGlobal.shared.introSignup, openLoginWeb: false)
  145. }
  146. @IBAction func host(_ sender: Any) {
  147. guard let url = URL(string: NCBrandOptions.shared.linkLoginHost) else { return }
  148. UIApplication.shared.open(url)
  149. }
  150. }
  151. extension UINavigationController {
  152. open override var childForStatusBarStyle: UIViewController? {
  153. return topViewController?.childForStatusBarStyle ?? topViewController
  154. }
  155. }