NCIntroViewController.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
  34. private let images = [UIImage(named: "intro1"), UIImage(named: "intro2"), UIImage(named: "intro3"), UIImage(named: "intro4")]
  35. private var timerAutoScroll: Timer?
  36. private var textColor: UIColor = .white
  37. private var textColorOpponent: UIColor = .black
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. let isTooLight = NCBrandColor.shared.customer.isTooLight()
  41. let isTooDark = NCBrandColor.shared.customer.isTooDark()
  42. if isTooLight {
  43. textColor = .black
  44. textColorOpponent = .white
  45. } else if isTooDark {
  46. textColor = .white
  47. textColorOpponent = .black
  48. } else {
  49. textColor = .white
  50. textColorOpponent = .black
  51. }
  52. if #available(iOS 13.0, *) {
  53. let navBarAppearance = UINavigationBarAppearance()
  54. navBarAppearance.configureWithTransparentBackground()
  55. navBarAppearance.shadowColor = .clear
  56. navBarAppearance.shadowImage = UIImage()
  57. self.navigationController?.navigationBar.standardAppearance = navBarAppearance
  58. } else {
  59. self.navigationController?.navigationBar.isTranslucent = true
  60. self.navigationController?.navigationBar.shadowImage = UIImage()
  61. self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  62. self.navigationController?.navigationBar.backgroundColor = .clear
  63. self.navigationController?.navigationBar.barTintColor = NCBrandColor.shared.customer
  64. }
  65. self.navigationController?.navigationBar.tintColor = textColor
  66. self.pageControl.currentPageIndicatorTintColor = textColor
  67. self.pageControl.pageIndicatorTintColor = NCBrandColor.shared.nextcloudSoft
  68. self.buttonLogin.layer.cornerRadius = 20
  69. self.buttonLogin.setTitleColor(textColorOpponent, for: .normal)
  70. self.buttonLogin.backgroundColor = textColor
  71. self.buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
  72. self.buttonSignUp.layer.cornerRadius = 20
  73. self.buttonSignUp.setTitleColor(.white, for: .normal)
  74. self.buttonSignUp.backgroundColor = UIColor(red: 25.0 / 255.0, green: 89.0 / 255.0, blue: 141.0 / 255.0, alpha: 1)
  75. self.buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
  76. self.buttonHost.layer.cornerRadius = 20
  77. self.buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
  78. self.buttonHost.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
  79. self.introCollectionView.register(UINib(nibName: "NCIntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
  80. self.introCollectionView.dataSource = self
  81. self.introCollectionView.delegate = self
  82. self.introCollectionView.backgroundColor = NCBrandColor.shared.customer
  83. self.pageControl.numberOfPages = self.titles.count
  84. self.view.backgroundColor = NCBrandColor.shared.customer
  85. self.timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  86. }
  87. override var preferredStatusBarStyle: UIStatusBarStyle {
  88. if #available(iOS 13.0, *) {
  89. if traitCollection.userInterfaceStyle == .light {
  90. return .lightContent
  91. } else {
  92. return .darkContent
  93. }
  94. } else {
  95. return .lightContent
  96. }
  97. }
  98. override func viewWillDisappear(_ animated: Bool) {
  99. super.viewWillDisappear(animated)
  100. timerAutoScroll?.invalidate()
  101. }
  102. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  103. pageControl.currentPage = 0
  104. introCollectionView.collectionViewLayout.invalidateLayout()
  105. }
  106. @objc func autoScroll() {
  107. if(pageControl.currentPage + 1 >= titles.count) {
  108. pageControl.currentPage = 0
  109. }
  110. else {
  111. pageControl.currentPage += 1
  112. }
  113. introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
  114. }
  115. func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  116. return CGPoint.zero
  117. }
  118. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  119. return titles.count
  120. }
  121. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  122. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as! NCIntroCollectionViewCell
  123. cell.backgroundColor = NCBrandColor.shared.customer
  124. cell.titleLabel.textColor = textColor
  125. cell.titleLabel.text = titles[indexPath.row]
  126. cell.imageView.image = images[indexPath.row]
  127. return cell
  128. }
  129. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  130. return collectionView.bounds.size
  131. }
  132. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  133. timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  134. pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
  135. }
  136. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  137. timerAutoScroll?.invalidate()
  138. }
  139. @IBAction func login(_ sender: Any) {
  140. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_login), openLoginWeb: false)
  141. }
  142. @IBAction func signup(_ sender: Any) {
  143. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_signup), openLoginWeb: false)
  144. }
  145. @IBAction func host(_ sender: Any) {
  146. let appDelegate = UIApplication.shared.delegate as? AppDelegate
  147. let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as? NCBrowserWeb
  148. browserWebVC?.urlBase = NCBrandOptions.shared.linkLoginHost
  149. if let browserWebVC = browserWebVC {
  150. appDelegate?.window.rootViewController?.present(browserWebVC, animated: true)
  151. }
  152. }
  153. }
  154. extension UINavigationController {
  155. open override var childForStatusBarStyle: UIViewController? {
  156. return topViewController?.childForStatusBarStyle ?? topViewController
  157. }
  158. }