CCIntro.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // CCIntro.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 05/11/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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. @interface CCIntro ()
  25. {
  26. int titlePositionY;
  27. int descPositionY;
  28. int titleIconPositionY;
  29. }
  30. @end
  31. @implementation CCIntro
  32. - (id)initWithDelegate:(id <CCIntroDelegate>)delegate delegateView:(UIView *)delegateView type:(NSString *)type
  33. {
  34. self = [super init];
  35. if (self) {
  36. self.delegate = delegate;
  37. self.rootView = delegateView;
  38. self.type = type;
  39. }
  40. return self;
  41. }
  42. - (UIStatusBarStyle)preferredStatusBarStyle
  43. {
  44. return UIStatusBarStyleLightContent;
  45. }
  46. - (void)introWillFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  47. {
  48. if (self.delegate && [self.delegate respondsToSelector:@selector(introWillFinish:type:wasSkipped:)])
  49. [self.delegate introWillFinish:introView type:self.type wasSkipped:wasSkipped];
  50. }
  51. - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  52. {
  53. if (self.delegate && [self.delegate respondsToSelector:@selector(introDidFinish:type:wasSkipped:)])
  54. [self.delegate introDidFinish:introView type:self.type wasSkipped:wasSkipped];
  55. }
  56. - (void)show
  57. {
  58. if ([self.type isEqualToString:k_Intro])
  59. [self showIntro];
  60. if ([self.type isEqualToString:k_Intro_no_cryptocloud])
  61. [self showIntroNoCryptoCloud];
  62. }
  63. - (void)showIntro
  64. {
  65. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  66. CGFloat height = self.rootView.bounds.size.height;
  67. if (height <= 480) {
  68. titleIconPositionY = 20; titlePositionY = 260; descPositionY = 230;
  69. }
  70. // 812 = iPhoneX
  71. if (height > 480 && height <= 812) {
  72. titleIconPositionY = 50; titlePositionY = height / 2; descPositionY = height / 2 - 40 ;
  73. }
  74. if (height > 812) {
  75. titleIconPositionY = 100; titlePositionY = 290; descPositionY = 250;
  76. }
  77. EAIntroPage *page1 = [EAIntroPage page];
  78. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro1"]];
  79. page1.title = NSLocalizedStringFromTable(@"_intro_1_title_", @"Intro", nil);
  80. page1.desc = NSLocalizedStringFromTable(@"_intro_1_text_", @"Intro", nil);
  81. page1.titlePositionY = titlePositionY;
  82. page1.titleColor = [UIColor blackColor];
  83. page1.titleFont = [UIFont systemFontOfSize:20];
  84. page1.descPositionY = descPositionY;
  85. page1.descColor = [UIColor blackColor];
  86. page1.descFont = [UIFont systemFontOfSize:14];
  87. page1.bgImage = [UIImage imageNamed:@"bgbianco"];
  88. page1.titleIconPositionY = titleIconPositionY;
  89. page1.showTitleView = NO;
  90. EAIntroPage *page11 = [EAIntroPage page];
  91. page11.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro11"]];
  92. page11.title = NSLocalizedStringFromTable(@"_intro_11_title_", @"Intro", nil);
  93. page11.desc = NSLocalizedStringFromTable(@"_intro_11_text_", @"Intro", nil);
  94. page11.titlePositionY = titlePositionY;
  95. page11.titleColor = [UIColor blackColor];
  96. page11.titleFont = [UIFont systemFontOfSize:20];
  97. page11.descPositionY = descPositionY;
  98. page11.descColor = [UIColor blackColor];
  99. page11.descFont = [UIFont systemFontOfSize:14];
  100. page11.bgImage = [UIImage imageNamed:@"bgbianco"];
  101. page11.titleIconPositionY = titleIconPositionY;
  102. page11.showTitleView = NO;
  103. EAIntroPage *page2 = [EAIntroPage page];
  104. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro2"]];
  105. page2.title = NSLocalizedStringFromTable(@"_intro_2_title_", @"Intro", nil);
  106. page2.desc = NSLocalizedStringFromTable(@"_intro_2_text_", @"Intro", nil);
  107. page2.titlePositionY = titlePositionY;
  108. page2.titleColor = [UIColor blackColor];
  109. page2.titleFont = [UIFont systemFontOfSize:20];
  110. page2.descPositionY = descPositionY;
  111. page2.descColor = [UIColor blackColor];
  112. page2.descFont = [UIFont systemFontOfSize:14];
  113. page2.bgImage = [UIImage imageNamed:@"bgbianco"];
  114. page2.titleIconPositionY = titleIconPositionY;
  115. page2.showTitleView = NO;
  116. EAIntroPage *page3 = [EAIntroPage page];
  117. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"intro3"]];
  118. page3.title = NSLocalizedStringFromTable(@"_intro_3_title_", @"Intro", nil);
  119. page3.desc = NSLocalizedStringFromTable(@"_intro_3_text_", @"Intro", nil);
  120. page3.titlePositionY = titlePositionY;
  121. page3.titleColor = [UIColor blackColor];
  122. page3.titleFont = [UIFont systemFontOfSize:20];
  123. page3.descPositionY = descPositionY;
  124. page3.descColor = [UIColor blackColor];
  125. page3.descFont = [UIFont systemFontOfSize:14];
  126. page3.bgImage = [UIImage imageNamed:@"bgbianco"];
  127. page3.titleIconPositionY = titleIconPositionY;
  128. page3.showTitleView = NO;
  129. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds];
  130. intro.tapToNext = YES;
  131. intro.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
  132. intro.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  133. intro.pageControl.backgroundColor = [UIColor clearColor];
  134. [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  135. intro.skipButton.enabled = NO;
  136. page1.onPageDidAppear = ^{
  137. intro.skipButton.enabled = YES;
  138. [UIView animateWithDuration:0.3f animations:^{
  139. intro.skipButton.alpha = 1.f;
  140. }];
  141. };
  142. page2.onPageDidDisappear = ^{
  143. intro.skipButton.enabled = NO;
  144. [UIView animateWithDuration:0.3f animations:^{
  145. intro.skipButton.alpha = 0.f;
  146. }];
  147. };
  148. [intro setDelegate:self];
  149. [intro setPages:@[page1,page11,page2,page3]];
  150. [intro showInView:self.rootView animateDuration:0];
  151. }
  152. - (void)showIntroNoCryptoCloud
  153. {
  154. //NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
  155. CGFloat height = self.rootView.bounds.size.height;
  156. if (height <= 480) {
  157. titleIconPositionY = 20; titlePositionY = 260; descPositionY = 230;
  158. }
  159. // 812 = iPhoneX
  160. if (height > 480 && height <= 812) {
  161. titleIconPositionY = 50; titlePositionY = height / 2; descPositionY = height / 2 - 40 ;
  162. }
  163. if (height > 812) {
  164. titleIconPositionY = 100; titlePositionY = 290; descPositionY = 250;
  165. }
  166. EAIntroPage *page1 = [EAIntroPage page];
  167. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IntroNoCryptoCloud"]];
  168. page1.bgImage = [UIImage imageNamed:@"bgbianco"];
  169. page1.showTitleView = NO;
  170. page1.titlePositionY = titlePositionY;
  171. page1.titleColor = [UIColor blackColor];
  172. page1.titleFont = [UIFont systemFontOfSize:20];
  173. page1.title = NSLocalizedStringFromTable(@"_introNoCryptoCloud_1_title_", @"Intro", nil);
  174. page1.descPositionY = descPositionY;
  175. page1.descColor = [UIColor blackColor];
  176. page1.descFont = [UIFont systemFontOfSize:14];
  177. page1.desc = NSLocalizedStringFromTable(@"_introNoCryptoCloud_1_text_", @"Intro", nil);
  178. page1.titleIconPositionY = titleIconPositionY;
  179. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds];
  180. intro.tapToNext = YES;
  181. intro.pageControl.pageIndicatorTintColor = [UIColor clearColor];
  182. intro.pageControl.currentPageIndicatorTintColor = [UIColor clearColor];
  183. intro.pageControl.backgroundColor = [UIColor clearColor];
  184. [intro.skipButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  185. intro.skipButton.enabled = NO;
  186. intro.skipButton.alpha = 0.f;
  187. [intro setDelegate:self];
  188. [intro setPages:@[page1]];
  189. [intro showInView:self.rootView animateDuration:0.3];
  190. }
  191. @end