IntroViewController.swift 6.7 KB

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