CCIntro.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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)login:(id)sender
  57. {
  58. selector = k_intro_login;
  59. [self.intro hideWithFadeOutDuration:0.7];
  60. }
  61. - (void)signUp:(id)sender
  62. {
  63. selector = k_intro_signup;
  64. [self.intro hideWithFadeOutDuration:0.7];
  65. }
  66. - (void)show
  67. {
  68. [self showIntro];
  69. }
  70. - (void)showIntro
  71. {
  72. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  73. CGFloat height = self.rootView.bounds.size.height;
  74. CGFloat width = self.rootView.bounds.size.width;
  75. if (height <= 568) {
  76. titleIconPositionY = 20;
  77. titlePositionY = height / 2 + 40.0;
  78. descPositionY = height / 2;
  79. buttonPosition = height / 2 + 50.0;
  80. } else {
  81. titleIconPositionY = 100;
  82. titlePositionY = height / 2 + 40.0;
  83. descPositionY = height / 2;
  84. buttonPosition = height / 2 + 120.0;
  85. }
  86. // Button
  87. UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.rootView.bounds.size.width,220)];
  88. buttonView.userInteractionEnabled = YES ;
  89. UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  90. buttonLogin.frame = CGRectMake(50.0, 0.0, width - 100.0, 40.0);
  91. buttonLogin.layer.cornerRadius = 3;
  92. buttonLogin.clipsToBounds = YES;
  93. [buttonLogin setTitle:[NSLocalizedString(@"_log_in_", nil) uppercaseString] forState:UIControlStateNormal];
  94. buttonLogin.titleLabel.font = [UIFont systemFontOfSize:14];
  95. [buttonLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  96. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customerText];
  97. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchDown];
  98. [buttonView addSubview:buttonLogin];
  99. UIButton *buttonSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  100. buttonSignUp.frame = CGRectMake(50.0, 60.0, width - 100.0, 40.0);
  101. buttonSignUp.layer.cornerRadius = 3;
  102. buttonSignUp.clipsToBounds = YES;
  103. [buttonSignUp setTitle:[NSLocalizedString(@"_sign_up_", nil) uppercaseString] forState:UIControlStateNormal];
  104. buttonSignUp.titleLabel.font = [UIFont systemFontOfSize:14];
  105. [buttonSignUp setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  106. buttonSignUp.backgroundColor = [UIColor colorWithRed:25.0/255.0 green:89.0/255.0 blue:141.0/255.0 alpha:1.000];
  107. [buttonSignUp addTarget:self action:@selector(signUp:) forControlEvents:UIControlEventTouchDown];
  108. [buttonView addSubview:buttonSignUp];
  109. UIButton *buttonHost = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  110. buttonHost.frame = CGRectMake(50.0, 200.0, width - 100.0, 20.0);
  111. buttonHost.layer.cornerRadius = 3;
  112. buttonHost.clipsToBounds = YES;
  113. [buttonHost setTitle:NSLocalizedString(@"_host_your_own_server", nil) forState:UIControlStateNormal];
  114. buttonHost.titleLabel.font = [UIFont systemFontOfSize:14];
  115. [buttonHost setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  116. buttonHost.backgroundColor = [UIColor clearColor];
  117. [buttonHost addTarget:self action:@selector(host:) forControlEvents:UIControlEventTouchDown];
  118. [buttonView addSubview:buttonHost];
  119. // Pages
  120. EAIntroPage *page1 = [EAIntroPage page];
  121. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  122. page1.titleIconPositionY = titleIconPositionY;
  123. page1.title = NSLocalizedString(@"_intro_1_title_", nil);
  124. page1.titlePositionY = titlePositionY;
  125. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  126. page1.titleFont = [UIFont systemFontOfSize:23];
  127. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  128. page1.showTitleView = YES;
  129. EAIntroPage *page2 = [EAIntroPage page];
  130. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  131. page2.titleIconPositionY = titleIconPositionY;
  132. page2.title = NSLocalizedString(@"_intro_2_title_", nil);
  133. page2.titlePositionY = titlePositionY;
  134. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  135. page2.titleFont = [UIFont systemFontOfSize:23];
  136. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  137. page2.showTitleView = YES;
  138. EAIntroPage *page3 = [EAIntroPage page];
  139. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  140. page3.titleIconPositionY = titleIconPositionY;
  141. page3.title = NSLocalizedString(@"_intro_3_title_", nil);
  142. page3.titlePositionY = titlePositionY;
  143. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  144. page3.titleFont = [UIFont systemFontOfSize:23];
  145. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  146. page3.showTitleView = YES;
  147. EAIntroPage *page4 = [EAIntroPage page];
  148. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro4"]];
  149. page4.titleIconPositionY = titleIconPositionY;
  150. page4.title = NSLocalizedString(@"_intro_4_title_", nil);
  151. page4.titlePositionY = titlePositionY;
  152. page4.titleColor = [[NCBrandColor sharedInstance] customerText];
  153. page4.titleFont = [UIFont systemFontOfSize:23];
  154. page4.bgColor = [[NCBrandColor sharedInstance] customer];
  155. page4.showTitleView = YES;
  156. // INTRO
  157. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3,page4]];
  158. self.intro.tapToNext = NO;
  159. self.intro.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
  160. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  161. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  162. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  163. // intro.skipButton.enabled = NO;
  164. self.intro.swipeToExit = NO ;
  165. self.intro.skipButton = nil ;
  166. self.intro.titleView = buttonView;
  167. self.intro.titleViewY = buttonPosition;
  168. self.intro.swipeToExit = NO;
  169. /*
  170. page1.onPageDidAppear = ^{
  171. intro.skipButton.enabled = YES;
  172. [UIView animateWithDuration:0.3f animations:^{
  173. intro.skipButton.alpha = 1.f;
  174. }];
  175. };
  176. page2.onPageDidDisappear = ^{
  177. intro.skipButton.enabled = NO;
  178. [UIView animateWithDuration:0.3f animations:^{
  179. intro.skipButton.alpha = 0.f;
  180. }];
  181. };
  182. */
  183. [self.intro setDelegate:self];
  184. [self.intro showInView:self.rootView animateDuration:0];
  185. }
  186. #pragma --------------------------------------------------------------------------------------------
  187. #pragma mark ===== Web =====
  188. #pragma --------------------------------------------------------------------------------------------
  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];
  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. - (void)decidePolicyForNavigationAction:(WKWebView *)webView decidePolicyFor:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
  209. {
  210. decisionHandler(WKNavigationActionPolicyAllow);
  211. }
  212. @end