CCIntro.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // CCIntro.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 05/11/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCIntro () <SwiftModalWebVCDelegate>
  27. {
  28. int titlePositionY;
  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)show
  56. {
  57. [self showIntro];
  58. }
  59. - (void)showIntro
  60. {
  61. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  62. CGFloat height = self.rootView.bounds.size.height;
  63. CGFloat width = self.rootView.bounds.size.width;
  64. if (height <= 568) {
  65. titleIconPositionY = 20;
  66. titlePositionY = height / 2 + 40.0;
  67. buttonPosition = height / 2 + 50.0;
  68. } else {
  69. titleIconPositionY = 40;
  70. titlePositionY = height / 2 + 40.0;
  71. buttonPosition = height / 2 + 120.0;
  72. }
  73. // Button
  74. UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.rootView.bounds.size.width, height - buttonPosition)];
  75. buttonView.userInteractionEnabled = YES ;
  76. UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  77. buttonLogin.frame = CGRectMake(50.0, 0.0, width - 100.0, 40.0);
  78. buttonLogin.layer.cornerRadius = 3;
  79. buttonLogin.clipsToBounds = YES;
  80. [buttonLogin setTitle:[NSLocalizedString(@"_log_in_", nil) uppercaseString] forState:UIControlStateNormal];
  81. buttonLogin.titleLabel.font = [UIFont systemFontOfSize:14];
  82. [buttonLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  83. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  84. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchDown];
  85. [buttonView addSubview:buttonLogin];
  86. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  87. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  88. buttonSignUp.layer.cornerRadius = 3;
  89. buttonSignUp.clipsToBounds = YES;
  90. [buttonSignUp setTitle:[NSLocalizedString(@"_sign_up_", nil) uppercaseString] forState:UIControlStateNormal];
  91. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:14];
  92. [buttonSignUp setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  93. buttonSignUp.backgroundColor = [UIColor colorWithRed:25.0/255.0 green:89.0/255.0 blue:141.0/255.0 alpha:1.000];
  94. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  95. [buttonView addSubview:buttonSignUp];
  96. UIButton *buttonHost = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  97. buttonHost.frame = CGRectMake(50.0, height - buttonPosition - 40.0, width - 100.0, 20.0);
  98. buttonHost.layer.cornerRadius = 3;
  99. buttonHost.clipsToBounds = YES;
  100. [buttonHost setTitle:NSLocalizedString(@"_host_your_own_server", nil) forState:UIControlStateNormal];
  101. buttonHost.titleLabel.font = [UIFont systemFontOfSize:14];
  102. [buttonHost setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  103. buttonHost.backgroundColor = [UIColor clearColor];
  104. [buttonHost addTarget:self action:@selector(host:) forControlEvents:UIControlEventTouchDown];
  105. [buttonView addSubview:buttonHost];
  106. // Pages
  107. EAIntroPage *page1 = [EAIntroPage page];
  108. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  109. page1.titleIconPositionY = titleIconPositionY;
  110. page1.title = NSLocalizedString(@"_intro_1_title_", nil);
  111. page1.titlePositionY = titlePositionY;
  112. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  113. page1.titleFont = [UIFont systemFontOfSize:23];
  114. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  115. page1.showTitleView = YES;
  116. EAIntroPage *page2 = [EAIntroPage page];
  117. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  118. page2.titleIconPositionY = titleIconPositionY;
  119. page2.title = NSLocalizedString(@"_intro_2_title_", nil);
  120. page2.titlePositionY = titlePositionY;
  121. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  122. page2.titleFont = [UIFont systemFontOfSize:23];
  123. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  124. page2.showTitleView = YES;
  125. EAIntroPage *page3 = [EAIntroPage page];
  126. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  127. page3.titleIconPositionY = titleIconPositionY;
  128. page3.title = NSLocalizedString(@"_intro_3_title_", nil);
  129. page3.titlePositionY = titlePositionY;
  130. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  131. page3.titleFont = [UIFont systemFontOfSize:23];
  132. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  133. page3.showTitleView = YES;
  134. EAIntroPage *page4 = [EAIntroPage page];
  135. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro4"]];
  136. page4.titleIconPositionY = titleIconPositionY;
  137. page4.title = NSLocalizedString(@"_intro_4_title_", nil);
  138. page4.titlePositionY = titlePositionY;
  139. page4.titleColor = [[NCBrandColor sharedInstance] customerText];
  140. page4.titleFont = [UIFont systemFontOfSize:23];
  141. page4.bgColor = [[NCBrandColor sharedInstance] customer];
  142. page4.showTitleView = YES;
  143. // INTRO
  144. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3,page4]];
  145. self.intro.tapToNext = NO;
  146. self.intro.pageControlY = height - buttonPosition + 50;
  147. self.intro.pageControl.pageIndicatorTintColor = [[NCBrandColor sharedInstance] nextcloudSoft];
  148. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
  149. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  150. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  151. // intro.skipButton.enabled = NO;
  152. self.intro.swipeToExit = NO ;
  153. self.intro.skipButton = nil ;
  154. self.intro.titleView = buttonView;
  155. self.intro.titleViewY = buttonPosition;
  156. self.intro.swipeToExit = NO;
  157. /*
  158. page1.onPageDidAppear = ^{
  159. intro.skipButton.enabled = YES;
  160. [UIView animateWithDuration:0.3f animations:^{
  161. intro.skipButton.alpha = 1.f;
  162. }];
  163. };
  164. page2.onPageDidDisappear = ^{
  165. intro.skipButton.enabled = NO;
  166. [UIView animateWithDuration:0.3f animations:^{
  167. intro.skipButton.alpha = 0.f;
  168. }];
  169. };
  170. */
  171. [self.intro setDelegate:self];
  172. [self.intro showInView:self.rootView animateDuration:0];
  173. }
  174. #pragma --------------------------------------------------------------------------------------------
  175. #pragma mark ===== Action =====
  176. #pragma --------------------------------------------------------------------------------------------
  177. - (void)login:(id)sender
  178. {
  179. selector = k_intro_login;
  180. [self.intro hideWithFadeOutDuration:0.7];
  181. }
  182. - (void)signUp:(id)sender
  183. {
  184. selector = k_intro_signup;
  185. [self.intro hideWithFadeOutDuration:0.7];
  186. }
  187. - (void)host:(id)sender
  188. {
  189. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  190. SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:[NCBrandOptions sharedInstance].linkLoginHost colorText:[UIColor whiteColor] colorDoneButton:[UIColor blackColor] doneButtonVisible:YES hideToolbar:NO];
  191. webVC.delegateWeb = self;
  192. [appDelegate.window.rootViewController presentViewController:webVC animated:YES completion:nil];
  193. }
  194. - (void)didStartLoading
  195. {
  196. }
  197. - (void)didReceiveServerRedirectForProvisionalNavigationWithUrl:(NSURL *)url
  198. {
  199. }
  200. - (void)didFinishLoadingWithSuccess:(BOOL)success url:(NSURL *)url
  201. {
  202. }
  203. - (void)webDismiss
  204. {
  205. }
  206. @end