IntroViewController.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. //
  8. // This program is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. import UIKit
  22. class IntroViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  23. @IBOutlet weak var buttonLogin: UIButton!
  24. @IBOutlet weak var buttonSignUp: UIButton!
  25. @IBOutlet weak var buttonHost: UIButton!
  26. @IBOutlet weak var introCollectionView: UICollectionView!
  27. @IBOutlet weak var pageControl: UIPageControl!
  28. @objc var delegate: IntroViewController?
  29. private let titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
  30. private let images = [UIImage(named: "intro1"), UIImage(named: "intro2"), UIImage(named: "intro3"), UIImage(named: "intro4")]
  31. private var timerAutoScroll: Timer?
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.customerText
  35. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.customer
  36. self.pageControl.currentPageIndicatorTintColor = NCBrandColor.sharedInstance.customerText
  37. self.pageControl.pageIndicatorTintColor = NCBrandColor.sharedInstance.nextcloudSoft
  38. self.buttonLogin.layer.cornerRadius = 20
  39. self.buttonLogin.setTitleColor(.black, for: .normal)
  40. self.buttonLogin.backgroundColor = NCBrandColor.sharedInstance.customerText
  41. self.buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
  42. self.buttonSignUp.layer.cornerRadius = 20
  43. self.buttonSignUp.setTitleColor(.white, for: .normal)
  44. self.buttonSignUp.backgroundColor = UIColor(red: 25.0 / 255.0, green: 89.0 / 255.0, blue: 141.0 / 255.0, alpha: 1)
  45. self.buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
  46. self.buttonHost.layer.cornerRadius = 20
  47. self.buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
  48. self.buttonHost.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 0.7), for: .normal)
  49. self.introCollectionView.register(UINib(nibName: "IntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
  50. self.introCollectionView.dataSource = self
  51. self.introCollectionView.delegate = self
  52. self.introCollectionView.backgroundColor = NCBrandColor.sharedInstance.customer
  53. self.pageControl.numberOfPages = self.titles.count
  54. self.view.backgroundColor = NCBrandColor.sharedInstance.customer
  55. self.timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(IntroViewController.autoScroll)), userInfo: nil, repeats: true)
  56. }
  57. override func viewWillDisappear(_ animated: Bool) {
  58. super.viewWillDisappear(animated)
  59. timerAutoScroll?.invalidate()
  60. }
  61. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  62. pageControl.currentPage = 0
  63. introCollectionView.collectionViewLayout.invalidateLayout()
  64. }
  65. @objc func autoScroll() {
  66. if(pageControl.currentPage + 1 >= titles.count) {
  67. pageControl.currentPage = 0
  68. }
  69. else {
  70. pageControl.currentPage += 1
  71. }
  72. introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
  73. }
  74. func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  75. return CGPoint.zero
  76. }
  77. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  78. return titles.count
  79. }
  80. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  81. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as! IntroCollectionViewCell
  82. cell.backgroundColor = NCBrandColor.sharedInstance.customer
  83. cell.titleLabel.textColor = NCBrandColor.sharedInstance.customerText
  84. cell.titleLabel.text = titles[indexPath.row]
  85. cell.imageView.image = images[indexPath.row]
  86. return cell
  87. }
  88. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  89. return collectionView.bounds.size
  90. }
  91. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  92. timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(IntroViewController.autoScroll)), userInfo: nil, repeats: true)
  93. pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
  94. }
  95. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  96. timerAutoScroll?.invalidate()
  97. }
  98. @IBAction func login(_ sender: Any) {
  99. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_login), openLoginWeb: false)
  100. }
  101. @IBAction func signup(_ sender: Any) {
  102. (UIApplication.shared.delegate as! AppDelegate).openLoginView(navigationController, selector: Int(k_intro_signup), openLoginWeb: false)
  103. }
  104. @IBAction func host(_ sender: Any) {
  105. let appDelegate = UIApplication.shared.delegate as? AppDelegate
  106. let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as? NCBrowserWeb
  107. browserWebVC?.urlBase = NCBrandOptions.sharedInstance.linkLoginHost
  108. if let browserWebVC = browserWebVC {
  109. appDelegate?.window.rootViewController?.present(browserWebVC, animated: true)
  110. }
  111. }
  112. }