CCIntro.m 7.0 KB

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