IntroView.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // IntroView.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 15.11.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 IntroView: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  23. @IBOutlet weak var backgroundView: UIView!
  24. @IBOutlet weak var buttonLogin: UIButton!
  25. @IBOutlet weak var buttonSignUp: UIButton!
  26. @IBOutlet weak var buttonHost: UIButton!
  27. @IBOutlet weak var introCollectionView: UICollectionView!
  28. @IBOutlet weak var pageControl: UIPageControl!
  29. @objc var delegate: CCSplit?
  30. private let titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
  31. private let images = [UIImage(named: "intro1"), UIImage(named: "intro2"), UIImage(named: "intro3"), UIImage(named: "intro4")]
  32. private var timerAutoScroll: Timer?
  33. @objc func autoScroll() {
  34. if(pageControl.currentPage + 1 >= titles.count) {
  35. pageControl.currentPage = 0
  36. }
  37. else {
  38. pageControl.currentPage += 1
  39. }
  40. introCollectionView.scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .centeredHorizontally, animated: true)
  41. }
  42. override func layoutSubviews() {
  43. pageControl.currentPage = 0
  44. introCollectionView.collectionViewLayout.invalidateLayout()
  45. }
  46. func collectionView(_ collectionView: UICollectionView, targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  47. return CGPoint.zero
  48. }
  49. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  50. return titles.count
  51. }
  52. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  53. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "introCell", for: indexPath) as! IntroCollectionViewCell
  54. cell.backgroundColor = NCBrandColor.sharedInstance.customer
  55. cell.titleLabel.textColor = NCBrandColor.sharedInstance.customerText
  56. cell.titleLabel.text = titles[indexPath.row]
  57. cell.imageView.image = images[indexPath.row]
  58. return cell
  59. }
  60. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  61. return collectionView.bounds.size
  62. }
  63. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  64. timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(IntroView.autoScroll)), userInfo: nil, repeats: true)
  65. pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
  66. }
  67. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  68. timerAutoScroll?.invalidate()
  69. }
  70. override func removeFromSuperview() {
  71. super.removeFromSuperview()
  72. timerAutoScroll?.invalidate()
  73. }
  74. @objc class func instanceFromNib() -> IntroView {
  75. let view = UINib(nibName: "IntroView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! IntroView
  76. view.buttonLogin.layer.cornerRadius = 20
  77. view.buttonLogin.setTitleColor(.black, for: .normal)
  78. view.buttonLogin.backgroundColor = NCBrandColor.sharedInstance.customerText
  79. view.buttonLogin.setTitle(NSLocalizedString("_log_in_", comment: ""), for: .normal)
  80. view.buttonSignUp.layer.cornerRadius = 20
  81. view.buttonSignUp.setTitleColor(.white, for: .normal)
  82. view.buttonSignUp.backgroundColor = UIColor(red: 25.0 / 255.0, green: 89.0 / 255.0, blue: 141.0 / 255.0, alpha: 1)
  83. view.buttonSignUp.setTitle(NSLocalizedString("_sign_up_", comment: ""), for: .normal)
  84. view.buttonHost.layer.cornerRadius = 20
  85. view.buttonHost.setTitle(NSLocalizedString("_host_your_own_server", comment: ""), for: .normal)
  86. view.buttonHost.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 0.7), for: .normal)
  87. view.introCollectionView.register(UINib(nibName: "IntroCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "introCell")
  88. view.introCollectionView.dataSource = view
  89. view.introCollectionView.delegate = view
  90. view.introCollectionView.backgroundColor = NCBrandColor.sharedInstance.customer
  91. view.pageControl.numberOfPages = view.titles.count
  92. view.backgroundView.backgroundColor = NCBrandColor.sharedInstance.customer
  93. view.timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: view, selector: (#selector(IntroView.autoScroll)), userInfo: nil, repeats: true)
  94. return view
  95. }
  96. @IBAction func login(_ sender: Any) {
  97. delegate?.introFinishSelector(Int(k_intro_login))
  98. UIView.animate(withDuration: 1.7) {
  99. self.alpha = 0
  100. }
  101. }
  102. @IBAction func signup(_ sender: Any) {
  103. delegate?.introFinishSelector(Int(k_intro_signup))
  104. UIView.animate(withDuration: 1.7) {
  105. self.alpha = 0
  106. }
  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. }