CCIntro.m 7.2 KB

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