CCIntro.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 descPositionY;
  30. int titleIconPositionY;
  31. int buttonPosition;
  32. int selector;
  33. }
  34. @end
  35. @implementation CCIntro
  36. - (id)initWithDelegate:(id <CCIntroDelegate>)delegate delegateView:(UIView *)delegateView
  37. {
  38. self = [super init];
  39. if (self) {
  40. self.delegate = delegate;
  41. self.rootView = delegateView;
  42. }
  43. return self;
  44. }
  45. - (UIStatusBarStyle)preferredStatusBarStyle
  46. {
  47. return UIStatusBarStyleLightContent;
  48. }
  49. - (void)introWillFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  50. {
  51. [self.delegate introFinishSelector:selector];
  52. }
  53. - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  54. {
  55. }
  56. - (void)show
  57. {
  58. [self showIntro];
  59. }
  60. - (void)showIntro
  61. {
  62. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  63. CGFloat height = self.rootView.bounds.size.height;
  64. CGFloat width = self.rootView.bounds.size.width;
  65. if (height <= 568) {
  66. titleIconPositionY = 20;
  67. titlePositionY = height / 2 + 40.0;
  68. descPositionY = height / 2;
  69. buttonPosition = height / 2 + 50.0;
  70. } else {
  71. titleIconPositionY = 100;
  72. titlePositionY = height / 2 + 40.0;
  73. descPositionY = height / 2;
  74. buttonPosition = height / 2 + 120.0;
  75. }
  76. // Button
  77. UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.rootView.bounds.size.width,220)];
  78. buttonView.userInteractionEnabled = YES ;
  79. UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  80. buttonLogin.frame = CGRectMake(50.0, 0.0, width - 100.0, 40.0);
  81. buttonLogin.layer.cornerRadius = 3;
  82. buttonLogin.clipsToBounds = YES;
  83. [buttonLogin setTitle:[NSLocalizedString(@"_log_in_", nil) uppercaseString] forState:UIControlStateNormal];
  84. buttonLogin.titleLabel.font = [UIFont systemFontOfSize:14];
  85. [buttonLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  86. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  87. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchDown];
  88. [buttonView addSubview:buttonLogin];
  89. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  90. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  91. buttonSignUp.layer.cornerRadius = 3;
  92. buttonSignUp.clipsToBounds = YES;
  93. [buttonSignUp setTitle:[NSLocalizedString(@"_sign_up_", nil) uppercaseString] forState:UIControlStateNormal];
  94. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:14];
  95. [buttonSignUp setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  96. buttonSignUp.backgroundColor = [UIColor colorWithRed:25.0/255.0 green:89.0/255.0 blue:141.0/255.0 alpha:1.000];
  97. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  98. [buttonView addSubview:buttonSignUp];
  99. UIButton *buttonHost = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  100. buttonHost.frame = CGRectMake(50.0, 200.0, width - 100.0, 20.0);
  101. buttonHost.layer.cornerRadius = 3;
  102. buttonHost.clipsToBounds = YES;
  103. [buttonHost setTitle:NSLocalizedString(@"_host_your_own_server", nil) forState:UIControlStateNormal];
  104. buttonHost.titleLabel.font = [UIFont systemFontOfSize:14];
  105. [buttonHost setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  106. buttonHost.backgroundColor = [UIColor clearColor];
  107. [buttonHost addTarget:self action:@selector(host:) forControlEvents:UIControlEventTouchDown];
  108. [buttonView addSubview:buttonHost];
  109. // Pages
  110. EAIntroPage *page1 = [EAIntroPage page];
  111. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  112. page1.titleIconPositionY = titleIconPositionY;
  113. page1.title = NSLocalizedString(@"_intro_1_title_", nil);
  114. page1.titlePositionY = titlePositionY;
  115. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  116. page1.titleFont = [UIFont systemFontOfSize:23];
  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 = NSLocalizedString(@"_intro_2_title_", nil);
  123. page2.titlePositionY = titlePositionY;
  124. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  125. page2.titleFont = [UIFont systemFontOfSize:23];
  126. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  127. page2.showTitleView = YES;
  128. EAIntroPage *page3 = [EAIntroPage page];
  129. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  130. page3.titleIconPositionY = titleIconPositionY;
  131. page3.title = NSLocalizedString(@"_intro_3_title_", nil);
  132. page3.titlePositionY = titlePositionY;
  133. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  134. page3.titleFont = [UIFont systemFontOfSize:23];
  135. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  136. page3.showTitleView = YES;
  137. EAIntroPage *page4 = [EAIntroPage page];
  138. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro4"]];
  139. page4.titleIconPositionY = titleIconPositionY;
  140. page4.title = NSLocalizedString(@"_intro_4_title_", nil);
  141. page4.titlePositionY = titlePositionY;
  142. page4.titleColor = [[NCBrandColor sharedInstance] customerText];
  143. page4.titleFont = [UIFont systemFontOfSize:23];
  144. page4.bgColor = [[NCBrandColor sharedInstance] customer];
  145. page4.showTitleView = YES;
  146. // INTRO
  147. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3,page4]];
  148. self.intro.tapToNext = NO;
  149. self.intro.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
  150. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  151. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  152. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  153. // intro.skipButton.enabled = NO;
  154. self.intro.swipeToExit = NO ;
  155. self.intro.skipButton = nil ;
  156. self.intro.titleView = buttonView;
  157. self.intro.titleViewY = buttonPosition;
  158. self.intro.swipeToExit = NO;
  159. /*
  160. page1.onPageDidAppear = ^{
  161. intro.skipButton.enabled = YES;
  162. [UIView animateWithDuration:0.3f animations:^{
  163. intro.skipButton.alpha = 1.f;
  164. }];
  165. };
  166. page2.onPageDidDisappear = ^{
  167. intro.skipButton.enabled = NO;
  168. [UIView animateWithDuration:0.3f animations:^{
  169. intro.skipButton.alpha = 0.f;
  170. }];
  171. };
  172. */
  173. [self.intro setDelegate:self];
  174. [self.intro showInView:self.rootView animateDuration:0];
  175. }
  176. #pragma --------------------------------------------------------------------------------------------
  177. #pragma mark ===== Action =====
  178. #pragma --------------------------------------------------------------------------------------------
  179. - (void)login:(id)sender
  180. {
  181. selector = k_intro_login;
  182. [self.intro hideWithFadeOutDuration:0.7];
  183. }
  184. - (void)signUp:(id)sender
  185. {
  186. selector = k_intro_signup;
  187. [self.intro hideWithFadeOutDuration:0.7];
  188. }
  189. - (void)host:(id)sender
  190. {
  191. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  192. SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:[NCBrandOptions sharedInstance].linkLoginHost colorText:[UIColor whiteColor] colorDoneButton:[UIColor blackColor] doneButtonVisible:YES hideToolbar:NO useRedirectCookieHandling:false];
  193. webVC.delegateWeb = self;
  194. [appDelegate.window.rootViewController presentViewController:webVC animated:YES completion:nil];
  195. }
  196. - (void)didStartLoading
  197. {
  198. }
  199. - (void)didReceiveServerRedirectForProvisionalNavigationWithUrl:(NSURL *)url
  200. {
  201. }
  202. - (void)didFinishLoadingWithSuccess:(BOOL)success url:(NSURL *)url
  203. {
  204. }
  205. - (void)webDismiss
  206. {
  207. }
  208. @end