CCIntro.m 9.6 KB

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