CCIntro.m 9.5 KB

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