CCIntro.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. [buttonView addSubview:buttonLogin];
  95. if (![NCBrandOptions sharedInstance].disable_linkLoginProvider) {
  96. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  97. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  98. buttonSignUp.layer.cornerRadius = 3;
  99. buttonSignUp.clipsToBounds = YES;
  100. [buttonSignUp setTitle:[NSLocalizedStringFromTable(@"_sign_up_", @"Intro", nil) uppercaseString] forState:UIControlStateNormal];
  101. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:14];
  102. [buttonSignUp setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  103. buttonSignUp.backgroundColor = [UIColor colorWithRed:25.0/255.0 green:89.0/255.0 blue:141.0/255.0 alpha:1.000];
  104. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  105. [buttonView addSubview:buttonSignUp];
  106. }
  107. // Pages
  108. EAIntroPage *page1 = [EAIntroPage page];
  109. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  110. page1.titleIconPositionY = titleIconPositionY;
  111. page1.title = NSLocalizedStringFromTable(@"_intro_1_title_", @"Intro", nil);
  112. page1.titlePositionY = titlePositionY;
  113. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  114. page1.titleFont = [UIFont systemFontOfSize:20];
  115. page1.desc = NSLocalizedStringFromTable(@"_intro_1_text_", @"Intro", nil);
  116. page1.descPositionY = descPositionY;
  117. page1.descColor = [[NCBrandColor sharedInstance] customerText];
  118. page1.descFont = [UIFont systemFontOfSize:14];
  119. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  120. page1.showTitleView = YES;
  121. EAIntroPage *page2 = [EAIntroPage page];
  122. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  123. page2.titleIconPositionY = titleIconPositionY;
  124. page2.title = NSLocalizedStringFromTable(@"_intro_2_title_", @"Intro", nil);
  125. page2.titlePositionY = titlePositionY;
  126. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  127. page2.titleFont = [UIFont systemFontOfSize:20];
  128. page2.desc = NSLocalizedStringFromTable(@"_intro_2_text_", @"Intro", nil);
  129. page2.descPositionY = descPositionY;
  130. page2.descColor = [[NCBrandColor sharedInstance] customerText];
  131. page2.descFont = [UIFont systemFontOfSize:14];
  132. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  133. page2.showTitleView = YES;
  134. EAIntroPage *page3 = [EAIntroPage page];
  135. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  136. page3.titleIconPositionY = titleIconPositionY;
  137. page3.title = NSLocalizedStringFromTable(@"_intro_3_title_", @"Intro", nil);
  138. page3.titlePositionY = titlePositionY;
  139. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  140. page3.titleFont = [UIFont systemFontOfSize:20];
  141. page3.desc = NSLocalizedStringFromTable(@"_intro_3_text_", @"Intro", nil);
  142. page3.descPositionY = descPositionY;
  143. page3.descColor = [[NCBrandColor sharedInstance] customerText];
  144. page3.descFont = [UIFont systemFontOfSize:14];
  145. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  146. page3.showTitleView = YES;
  147. // INTRO
  148. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3]];
  149. self.intro.tapToNext = NO;
  150. self.intro.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
  151. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  152. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  153. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  154. // intro.skipButton.enabled = NO;
  155. self.intro.swipeToExit = NO ;
  156. self.intro.skipButton = nil ;
  157. self.intro.titleView = buttonView;
  158. self.intro.titleViewY = buttonPosition;
  159. self.intro.swipeToExit = NO;
  160. /*
  161. page1.onPageDidAppear = ^{
  162. intro.skipButton.enabled = YES;
  163. [UIView animateWithDuration:0.3f animations:^{
  164. intro.skipButton.alpha = 1.f;
  165. }];
  166. };
  167. page2.onPageDidDisappear = ^{
  168. intro.skipButton.enabled = NO;
  169. [UIView animateWithDuration:0.3f animations:^{
  170. intro.skipButton.alpha = 0.f;
  171. }];
  172. };
  173. */
  174. [self.intro setDelegate:self];
  175. [self.intro showInView:self.rootView animateDuration:0];
  176. }
  177. @end