IntroView.swift 5.4 KB

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