CCIntro.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. int selector;
  32. }
  33. @end
  34. @implementation CCIntro
  35. - (id)initWithDelegate:(id <CCIntroDelegate>)delegate delegateView:(UIView *)delegateView
  36. {
  37. self = [super init];
  38. if (self) {
  39. self.delegate = delegate;
  40. self.rootView = delegateView;
  41. }
  42. return self;
  43. }
  44. - (UIStatusBarStyle)preferredStatusBarStyle
  45. {
  46. return UIStatusBarStyleLightContent;
  47. }
  48. - (void)introWillFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  49. {
  50. [self.delegate introFinishSelector:selector];
  51. }
  52. - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  53. {
  54. }
  55. - (void)login:(id)sender
  56. {
  57. selector = k_intro_login;
  58. [self.intro hideWithFadeOutDuration:0.7];
  59. }
  60. - (void)signUp:(id)sender
  61. {
  62. selector = k_intro_signup;
  63. [self.intro hideWithFadeOutDuration:0.7];
  64. }
  65. - (void)show
  66. {
  67. [self showIntro];
  68. }
  69. - (void)showIntro
  70. {
  71. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  72. CGFloat height = self.rootView.bounds.size.height;
  73. CGFloat width = self.rootView.bounds.size.width;
  74. if (height <= 568) {
  75. titleIconPositionY = 20;
  76. } else {
  77. titleIconPositionY = 100;
  78. }
  79. titlePositionY = height / 2 + 40.0;
  80. descPositionY = height / 2;
  81. buttonPosition = height / 2 + 120.0;
  82. // Button
  83. UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.rootView.bounds.size.width, 100.0)];
  84. buttonView.userInteractionEnabled = YES ;
  85. UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  86. buttonLogin.frame = CGRectMake(50.0, 0.0, width - 100.0, 40.0);
  87. buttonLogin.layer.cornerRadius = 3;
  88. buttonLogin.clipsToBounds = YES;
  89. [buttonLogin setTitle:[NSLocalizedStringFromTable(@"_log_in_", @"Intro", nil) uppercaseString] forState:UIControlStateNormal];
  90. buttonLogin.titleLabel.font = [UIFont systemFontOfSize:14];
  91. [buttonLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  92. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  93. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchDown];
  94. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  95. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  96. buttonSignUp.layer.cornerRadius = 3;
  97. buttonSignUp.clipsToBounds = YES;
  98. [buttonSignUp setTitle:[NSLocalizedStringFromTable(@"_sign_up_", @"Intro", nil) uppercaseString] forState:UIControlStateNormal];
  99. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:14];
  100. [buttonSignUp setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  101. buttonSignUp.backgroundColor = [UIColor colorWithRed:25.0/255.0 green:89.0/255.0 blue:141.0/255.0 alpha:1.000];
  102. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  103. [buttonView addSubview:buttonLogin];
  104. [buttonView addSubview:buttonSignUp];
  105. // Pages
  106. EAIntroPage *page1 = [EAIntroPage page];
  107. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  108. page1.titleIconPositionY = titleIconPositionY;
  109. page1.title = NSLocalizedStringFromTable(@"_intro_1_title_", @"Intro", nil);
  110. page1.titlePositionY = titlePositionY;
  111. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  112. page1.titleFont = [UIFont systemFontOfSize:20];
  113. page1.desc = NSLocalizedStringFromTable(@"_intro_1_text_", @"Intro", nil);
  114. page1.descPositionY = descPositionY;
  115. page1.descColor = [[NCBrandColor sharedInstance] customerText];
  116. page1.descFont = [UIFont systemFontOfSize:14];
  117. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  118. page1.showTitleView = YES;
  119. EAIntroPage *page2 = [EAIntroPage page];
  120. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  121. page2.titleIconPositionY = titleIconPositionY;
  122. page2.title = NSLocalizedStringFromTable(@"_intro_2_title_", @"Intro", nil);
  123. page2.titlePositionY = titlePositionY;
  124. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  125. page2.titleFont = [UIFont systemFontOfSize:20];
  126. page2.desc = NSLocalizedStringFromTable(@"_intro_2_text_", @"Intro", nil);
  127. page2.descPositionY = descPositionY;
  128. page2.descColor = [[NCBrandColor sharedInstance] customerText];
  129. page2.descFont = [UIFont systemFontOfSize:14];
  130. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  131. page2.showTitleView = YES;
  132. EAIntroPage *page3 = [EAIntroPage page];
  133. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  134. page3.titleIconPositionY = titleIconPositionY;
  135. page3.title = NSLocalizedStringFromTable(@"_intro_3_title_", @"Intro", nil);
  136. page3.titlePositionY = titlePositionY;
  137. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  138. page3.titleFont = [UIFont systemFontOfSize:20];
  139. page3.desc = NSLocalizedStringFromTable(@"_intro_3_text_", @"Intro", nil);
  140. page3.descPositionY = descPositionY;
  141. page3.descColor = [[NCBrandColor sharedInstance] customerText];
  142. page3.descFont = [UIFont systemFontOfSize:14];
  143. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  144. page3.showTitleView = YES;
  145. // INTRO
  146. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3]];
  147. self.intro.tapToNext = NO;
  148. self.intro.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
  149. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  150. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  151. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  152. // intro.skipButton.enabled = NO;
  153. self.intro.swipeToExit = NO ;
  154. self.intro.skipButton = nil ;
  155. self.intro.titleView = buttonView;
  156. self.intro.titleViewY = buttonPosition;
  157. self.intro.swipeToExit = NO;
  158. /*
  159. page1.onPageDidAppear = ^{
  160. intro.skipButton.enabled = YES;
  161. [UIView animateWithDuration:0.3f animations:^{
  162. intro.skipButton.alpha = 1.f;
  163. }];
  164. };
  165. page2.onPageDidDisappear = ^{
  166. intro.skipButton.enabled = NO;
  167. [UIView animateWithDuration:0.3f animations:^{
  168. intro.skipButton.alpha = 0.f;
  169. }];
  170. };
  171. */
  172. [self.intro setDelegate:self];
  173. [self.intro showInView:self.rootView animateDuration:0];
  174. }
  175. @end