CCIntro.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // CCIntro.m
  3. // Nextcloud
  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. /*
  118. EAIntroPage *page1 = [EAIntroPage pageWithCustomViewFromNibNamed:@"NCIntroPage1"];
  119. page1.customView.backgroundColor = [[NCBrandColor sharedInstance] customer];
  120. UILabel *titlePage1 = (UILabel *)[page1.customView viewWithTag:1];
  121. titlePage1.text = NSLocalizedString(@"_intro_1_title_", nil);
  122. */
  123. EAIntroPage *page1 = [EAIntroPage page];
  124. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  125. page1.titleIconPositionY = titleIconPositionY;
  126. page1.title = NSLocalizedString(@"_intro_1_title_", nil);
  127. page1.titlePositionY = titlePositionY;
  128. page1.titleColor = [[NCBrandColor sharedInstance] customerText];
  129. page1.titleFont = [UIFont systemFontOfSize:23];
  130. page1.bgColor = [[NCBrandColor sharedInstance] customer];
  131. page1.showTitleView = YES;
  132. EAIntroPage *page2 = [EAIntroPage page];
  133. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  134. page2.titleIconPositionY = titleIconPositionY;
  135. page2.title = NSLocalizedString(@"_intro_2_title_", nil);
  136. page2.titlePositionY = titlePositionY;
  137. page2.titleColor = [[NCBrandColor sharedInstance] customerText];
  138. page2.titleFont = [UIFont systemFontOfSize:23];
  139. page2.bgColor = [[NCBrandColor sharedInstance] customer];
  140. page2.showTitleView = YES;
  141. EAIntroPage *page3 = [EAIntroPage page];
  142. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  143. page3.titleIconPositionY = titleIconPositionY;
  144. page3.title = NSLocalizedString(@"_intro_3_title_", nil);
  145. page3.titlePositionY = titlePositionY;
  146. page3.titleColor = [[NCBrandColor sharedInstance] customerText];
  147. page3.titleFont = [UIFont systemFontOfSize:23];
  148. page3.bgColor = [[NCBrandColor sharedInstance] customer];
  149. page3.showTitleView = YES;
  150. EAIntroPage *page4 = [EAIntroPage page];
  151. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro4"]];
  152. page4.titleIconPositionY = titleIconPositionY;
  153. page4.title = NSLocalizedString(@"_intro_4_title_", nil);
  154. page4.titlePositionY = titlePositionY;
  155. page4.titleColor = [[NCBrandColor sharedInstance] customerText];
  156. page4.titleFont = [UIFont systemFontOfSize:23];
  157. page4.bgColor = [[NCBrandColor sharedInstance] customer];
  158. page4.showTitleView = YES;
  159. // INTRO
  160. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3,page4]];
  161. self.intro.tapToNext = NO;
  162. self.intro.pageControlY = height - buttonPosition + 50;
  163. self.intro.pageControl.pageIndicatorTintColor = [[NCBrandColor sharedInstance] nextcloudSoft];
  164. self.intro.pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
  165. self.intro.pageControl.backgroundColor = [[NCBrandColor sharedInstance] customer];
  166. // [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  167. // intro.skipButton.enabled = NO;
  168. self.intro.swipeToExit = NO ;
  169. self.intro.skipButton = nil ;
  170. self.intro.titleView = buttonView;
  171. self.intro.titleViewY = buttonPosition;
  172. self.intro.swipeToExit = NO;
  173. /*
  174. page1.onPageDidAppear = ^{
  175. intro.skipButton.enabled = YES;
  176. [UIView animateWithDuration:0.3f animations:^{
  177. intro.skipButton.alpha = 1.f;
  178. }];
  179. };
  180. page2.onPageDidDisappear = ^{
  181. intro.skipButton.enabled = NO;
  182. [UIView animateWithDuration:0.3f animations:^{
  183. intro.skipButton.alpha = 0.f;
  184. }];
  185. };
  186. */
  187. [self.intro setDelegate:self];
  188. [self.intro showInView:self.rootView animateDuration:0];
  189. }
  190. #pragma --------------------------------------------------------------------------------------------
  191. #pragma mark ===== Action =====
  192. #pragma --------------------------------------------------------------------------------------------
  193. - (void)login:(id)sender
  194. {
  195. selector = k_intro_login;
  196. [self.intro hideWithFadeOutDuration:0.7];
  197. }
  198. - (void)signUp:(id)sender
  199. {
  200. selector = k_intro_signup;
  201. [self.intro hideWithFadeOutDuration:0.7];
  202. }
  203. - (void)host:(id)sender
  204. {
  205. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  206. SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:[NCBrandOptions sharedInstance].linkLoginHost colorText:[UIColor whiteColor] colorDoneButton:[UIColor blackColor] doneButtonVisible:YES hideToolbar:NO];
  207. webVC.delegateWeb = self;
  208. [appDelegate.window.rootViewController presentViewController:webVC animated:YES completion:nil];
  209. }
  210. - (void)didStartLoading
  211. {
  212. }
  213. - (void)didReceiveServerRedirectForProvisionalNavigationWithUrl:(NSURL *)url
  214. {
  215. }
  216. - (void)didFinishLoadingWithSuccess:(BOOL)success url:(NSURL *)url
  217. {
  218. }
  219. - (void)webDismiss
  220. {
  221. }
  222. @end