CCIntro.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // CCIntro.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 05/11/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCIntro.h"
  24. #import "NCBridgeSwift.h"
  25. @interface CCIntro ()
  26. {
  27. int titlePositionY;
  28. int descPositionY;
  29. int titleIconPositionY;
  30. int buttonPosition;
  31. }
  32. @end
  33. @implementation CCIntro
  34. - (id)initWithDelegate:(id <CCIntroDelegate>)delegate delegateView:(UIView *)delegateView
  35. {
  36. self = [super init];
  37. if (self) {
  38. self.delegate = delegate;
  39. self.rootView = delegateView;
  40. }
  41. return self;
  42. }
  43. - (UIStatusBarStyle)preferredStatusBarStyle
  44. {
  45. return UIStatusBarStyleLightContent;
  46. }
  47. - (void)introWillFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  48. {
  49. [self.delegate introFinishSelector:0];
  50. }
  51. - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  52. {
  53. [self.delegate introFinishSelector:0];
  54. }
  55. - (void)login:(id)sender
  56. {
  57. [self.delegate introFinishSelector:0];
  58. }
  59. - (void)signUp:(id)sender
  60. {
  61. [self.delegate introFinishSelector:0];
  62. }
  63. - (void)show
  64. {
  65. [self showIntro];
  66. }
  67. - (void)showIntro
  68. {
  69. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  70. CGFloat height = self.rootView.bounds.size.height;
  71. CGFloat width = self.rootView.bounds.size.width;
  72. if (height <= 480) {
  73. titleIconPositionY = 20;
  74. } else {
  75. titleIconPositionY = 100;
  76. }
  77. titlePositionY = height / 2 + 40.0;
  78. descPositionY = height / 2;
  79. buttonPosition = height / 2 + 120.0;
  80. // Button
  81. UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.rootView.bounds.size.width, 100.0)];
  82. buttonView.userInteractionEnabled = YES ;
  83. UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  84. buttonLogin.frame = CGRectMake(50.0, 0.0, width - 100.0, 40.0);
  85. [buttonLogin setTitle:@"Login" forState:UIControlStateNormal];
  86. buttonLogin.titleLabel.font = [UIFont systemFontOfSize:20];
  87. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  88. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchDown];
  89. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  90. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  91. [buttonSignUp setTitle:@"Sign up with provider" forState:UIControlStateNormal];
  92. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:20];
  93. buttonSignUp.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  94. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  95. [buttonView addSubview:buttonLogin];
  96. [buttonView addSubview:buttonSignUp];
  97. // Pages
  98. EAIntroPage *page1 = [EAIntroPage page];
  99. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  100. page1.titleIconPositionY = titleIconPositionY;
  101. page1.title = NSLocalizedStringFromTable(@"_intro_1_title_", @"Intro", nil);
  102. page1.titlePositionY = titlePositionY;
  103. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  104. page1.titleFont = [UIFont systemFontOfSize:20];
  105. page1.desc = NSLocalizedStringFromTable(@"_intro_1_text_", @"Intro", nil);
  106. page1.descPositionY = descPositionY;
  107. page1.descColor = [[NCBrandColor sharedInstance] customerText];
  108. page1.descFont = [UIFont systemFontOfSize:14];
  109. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  110. page1.showTitleView = YES;
  111. EAIntroPage *page2 = [EAIntroPage page];
  112. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  113. page2.titleIconPositionY = titleIconPositionY;
  114. page2.title = NSLocalizedStringFromTable(@"_intro_2_title_", @"Intro", nil);
  115. page2.titlePositionY = titlePositionY;
  116. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  117. page2.titleFont = [UIFont systemFontOfSize:20];
  118. page2.desc = NSLocalizedStringFromTable(@"_intro_2_text_", @"Intro", nil);
  119. page2.descPositionY = descPositionY;
  120. page2.descColor = [[NCBrandColor sharedInstance] customerText];
  121. page2.descFont = [UIFont systemFontOfSize:14];
  122. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  123. page2.showTitleView = YES;
  124. EAIntroPage *page3 = [EAIntroPage page];
  125. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  126. page3.titleIconPositionY = titleIconPositionY;
  127. page3.title = NSLocalizedStringFromTable(@"_intro_3_title_", @"Intro", nil);
  128. page3.titlePositionY = titlePositionY;
  129. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  130. page3.titleFont = [UIFont systemFontOfSize:20];
  131. page3.desc = NSLocalizedStringFromTable(@"_intro_3_text_", @"Intro", nil);
  132. page3.descPositionY = descPositionY;
  133. page3.descColor = [[NCBrandColor sharedInstance] customerText];
  134. page3.descFont = [UIFont systemFontOfSize:14];
  135. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  136. page3.showTitleView = YES;
  137. // INTRO
  138. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3]];
  139. intro.tapToNext = NO;
  140. intro.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
  141. intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  142. intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  143. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  144. // intro.skipButton.enabled = NO;
  145. intro.swipeToExit = NO ;
  146. intro.skipButton = nil ;
  147. intro.titleView = buttonView;
  148. intro.titleViewY = buttonPosition;
  149. intro.swipeToExit = NO;
  150. /*
  151. page1.onPageDidAppear = ^{
  152. intro.skipButton.enabled = YES;
  153. [UIView animateWithDuration:0.3f animations:^{
  154. intro.skipButton.alpha = 1.f;
  155. }];
  156. };
  157. page2.onPageDidDisappear = ^{
  158. intro.skipButton.enabled = NO;
  159. [UIView animateWithDuration:0.3f animations:^{
  160. intro.skipButton.alpha = 0.f;
  161. }];
  162. };
  163. */
  164. [intro setDelegate:self];
  165. [intro showInView:self.rootView animateDuration:0];
  166. }
  167. @end