NCIntroViewController.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.sharedInstance.customer.isTooLight()
  41. let isTooDark = NCBrandColor.sharedInstance.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. self.navigationController?.navigationBar.tintColor = textColor
  53. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.customer
  54. self.pageControl.currentPageIndicatorTintColor = textColor
  55. self.pageControl.pageIndicatorTintColor = NCBrandColor.sharedInstance.nextcloudSoft
  56. self.buttonLogin.layer.cornerRadius = 20
  57. self.buttonLogin.setTitleColor(textColorOpponent, for: .normal)
  58. self.buttonLogin.backgroundColor = textColor
  59. self.buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
  60. self.buttonSignUp.layer.cornerRadius = 20
  61. self.buttonSignUp.setTitleColor(.white, for: .normal)
  62. self.buttonSignUp.backgroundColor = UIColor(red: 25.0 / 255.0, green: 89.0 / 255.0, blue: 141.0 / 255.0, alpha: 1)
  63. self.buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
  64. self.buttonHost.layer.cornerRadius = 20
  65. self.buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
  66. self.buttonHost.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
  67. self.introCollectionView.register(UINib(nibName: "NCIntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
  68. self.introCollectionView.dataSource = self
  69. self.introCollectionView.delegate = self
  70. self.introCollectionView.backgroundColor = NCBrandColor.sharedInstance.customer
  71. self.pageControl.numberOfPages = self.titles.count
  72. self.view.backgroundColor = NCBrandColor.sharedInstance.customer
  73. self.timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  74. }
  75. override func viewWillDisappear(_ animated: Bool) {
  76. super.viewWillDisappear(animated)
  77. timerAutoScroll?.invalidate()
  78. }
  79. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  80. pageControl.currentPage = 0
  81. introCollectionView.collectionViewLayout.invalidateLayout()
  82. }
  83. @objc func autoScroll() {
  84. if(pageControl.currentPage + 1 >= titles.count) {
  85. pageControl.currentPage = 0
  86. }
  87. else {
  88. pageControl.currentPage += 1
  89. }
  90. introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
  91. }
  92. func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  93. return CGPoint.zero
  94. }
  95. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  96. return titles.count
  97. }
  98. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  99. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as! NCIntroCollectionViewCell
  100. cell.backgroundColor = NCBrandColor.sharedInstance.customer
  101. cell.titleLabel.textColor = textColor
  102. cell.titleLabel.text = titles[indexPath.row]
  103. cell.imageView.image = images[indexPath.row]
  104. return cell
  105. }
  106. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  107. return collectionView.bounds.size
  108. }
  109. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  110. timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)
  111. pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
  112. }
  113. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  114. timerAutoScroll?.invalidate()
  115. }
  116. @IBAction func login(_ sender: Any) {
  117. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_login), openLoginWeb: false)
  118. }
  119. @IBAction func signup(_ sender: Any) {
  120. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_signup), openLoginWeb: false)
  121. }
  122. @IBAction func host(_ sender: Any) {
  123. let appDelegate = UIApplication.shared.delegate as? AppDelegate
  124. let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as? NCBrowserWeb
  125. browserWebVC?.urlBase = NCBrandOptions.sharedInstance.linkLoginHost
  126. if let browserWebVC = browserWebVC {
  127. appDelegate?.window.rootViewController?.present(browserWebVC, animated: true)
  128. }
  129. }
  130. }