CCIntro.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. #import <QuartzCore/QuartzCore.h>
  27. @interface CCIntro ()
  28. {
  29. int safeAreaBottom;
  30. int selector;
  31. NSMutableArray *professions;
  32. EAIntroPage *page4;
  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. professions = [NSMutableArray new];
  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. // SafeArea
  65. if (@available(iOS 11, *)) {
  66. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
  67. if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
  68. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.right;
  69. } else {
  70. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  71. }
  72. }
  73. // Pages
  74. EAIntroPage *page1 = [EAIntroPage pageWithCustomViewFromNibNamed:@"HCIntroPage1"];
  75. UILabel *titlePage1 = (UILabel *)[page1.customView viewWithTag:1];
  76. UILabel *label1Page1 = (UILabel *)[page1.customView viewWithTag:2];
  77. UILabel *label2Page1 = (UILabel *)[page1.customView viewWithTag:3];
  78. UILabel *label3Page1 = (UILabel *)[page1.customView viewWithTag:4];
  79. UILabel *label4Page1 = (UILabel *)[page1.customView viewWithTag:5];
  80. if ([language isEqualToString:@"de"]) {
  81. titlePage1.text = @"HERZLICH WILLKOMMEN ZU IHRER PERSÖNLICHEN HANDWERKCLOUD!";
  82. label1Page1.text = @"Sparen Sie effektiv Zeit in der Verwaltung und Organisation";
  83. label2Page1.text = @"Die Daten in Ihrer Cloud sind immer und überall erreichbar";
  84. label3Page1.text = @"Ihr Verwaltungsaufwand sinkt, während Ihre Effizienz steigt";
  85. label4Page1.text = @"Bei Fragen unterstützen wir Sie jederzeit gerne";
  86. } else if ([language isEqualToString:@"it"]) {
  87. titlePage1.text = @"BENVENUTO SU HANDWERKCLOUD!";
  88. label1Page1.text = @"Risparmia tempo in amministrazione e organizzazione";
  89. label2Page1.text = @"I tuoi dati cloud sono disponibili ovunque e in qualsiasi momento";
  90. label3Page1.text = @"Riduci le abbondanti attività amministrative e aumenta la produttività";
  91. label4Page1.text = @"In caso di domande, saremo lieti di supportarti in qualsiasi momento";
  92. } else {
  93. titlePage1.text = @"WELCOME TO HANDWERKCLOUD!";
  94. label1Page1.text = @"Save time in administration and organization";
  95. label2Page1.text = @"Your cloud data is available anywhere and anytime";
  96. label3Page1.text = @"Reduce abundant administrative tasks and increase your productivity";
  97. label4Page1.text = @"If you have any questions, we‘ll be happy to support you at any time";
  98. }
  99. EAIntroPage *page2 = [EAIntroPage pageWithCustomViewFromNibNamed:@"HCIntroPage2"];
  100. UILabel *titlePage2 = (UILabel *)[page2.customView viewWithTag:1];
  101. UILabel *label1Page2 = (UILabel *)[page2.customView viewWithTag:2];
  102. UILabel *label2Page2 = (UILabel *)[page2.customView viewWithTag:3];
  103. UILabel *label3Page2 = (UILabel *)[page2.customView viewWithTag:4];
  104. UILabel *label4Page2 = (UILabel *)[page2.customView viewWithTag:5];
  105. UILabel *label5Page2 = (UILabel *)[page2.customView viewWithTag:6];
  106. UILabel *label6Page2 = (UILabel *)[page2.customView viewWithTag:7];
  107. if ([language isEqualToString:@"de"]) {
  108. titlePage2.text = @"DIE APP, DIE IHR HANDWERK VERSTEHT";
  109. label1Page2.text = @"Zeitmanagement, Projektmanagement";
  110. label2Page2.text = @"Digitales Aufmass";
  111. label3Page2.text = @"Bestandswesen";
  112. label4Page2.text = @"Datenverwaltung, Belegerfassung & -erkennung";
  113. label5Page2.text = @"Kalender, Einsatzplanung";
  114. label6Page2.text = @"Und vieles mehr";
  115. } else if ([language isEqualToString:@"it"]) {
  116. titlePage2.text = @"L' APP PER IL TUO ARTIGIANATO";
  117. label1Page2.text = @"Gestione del tempo, gestione del progetto";
  118. label2Page2.text = @"Misurazione fotometrica";
  119. label3Page2.text = @"Gestione delle scorte";
  120. label4Page2.text = @"Gestione dei dati";
  121. label5Page2.text = @"Calendario, pianificazione delle risorse";
  122. label6Page2.text = @"E molto di più";
  123. } else {
  124. titlePage2.text = @"THE APP FOR YOUR CRAFTSMANSHIP";
  125. label1Page2.text = @"Time management, project management";
  126. label2Page2.text = @"Photometric measurement";
  127. label3Page2.text = @"Inventory management";
  128. label4Page2.text = @"Data management";
  129. label5Page2.text = @"Calendar, resource planning";
  130. label6Page2.text = @"And a lot more";
  131. }
  132. EAIntroPage *page3 = [EAIntroPage pageWithCustomViewFromNibNamed:@"HCIntroPage3"];
  133. UILabel *titlePage3 = (UILabel *)[page3.customView viewWithTag:1];
  134. UIView *viewPage3 = (UIView *)[page3.customView viewWithTag:2];
  135. UILabel *label1Page3 = (UILabel *)[page3.customView viewWithTag:3];
  136. viewPage3.backgroundColor = [[NCBrandColor sharedInstance] customer];
  137. if ([language isEqualToString:@"de"]) {
  138. titlePage3.text = @"FÜR ALLE GENAU DIE PASSENDE LÖSUNG";
  139. label1Page3.text = @"Wählen Sie im nächsten Schritt Ihren Beruf aus, damit wir Ihnen personalisierte und genau auf Ihre Branche abgestimmte Inhalte zur Verfügung stellen können";
  140. } else if ([language isEqualToString:@"it"]) {
  141. titlePage3.text = @"LA SOLUZIONE PERFETTA PER TE";
  142. label1Page3.text = @"Nella pagina successiva, scegli la tua professione in modo che possiamo fornirti contenuti personalizzati per il tuo settore";
  143. } else {
  144. titlePage3.text = @"THE PERFECT SOLUTION FOR YOU";
  145. label1Page3.text = @"On the next page, please choose your profession so that we can provide you with personalised content for your industry";
  146. }
  147. page4 = [EAIntroPage pageWithCustomViewFromNibNamed:@"HCIntroPage4"];
  148. UILabel *titlePage4 = (UILabel *)[page4.customView viewWithTag:1];
  149. if ([language isEqualToString:@"de"]) {
  150. titlePage4.text = @"Wählen Sie Ihren Beruf";
  151. } else if ([language isEqualToString:@"it"]) {
  152. titlePage4.text = @"Scegli la tua professione";
  153. } else {
  154. titlePage4.text = @"Choose your profession";
  155. }
  156. UIButton *buttonLogin = (UIButton *)[page4.customView viewWithTag:2];
  157. buttonLogin.layer.cornerRadius = 20;
  158. buttonLogin.clipsToBounds = YES;
  159. [buttonLogin setTitle:NSLocalizedString(@"_ok_", nil) forState:UIControlStateNormal];
  160. buttonLogin.backgroundColor = [[NCBrandColor sharedInstance] customer];
  161. [buttonLogin addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
  162. for(int tag = 100; tag < 1300; tag = tag + 100) {
  163. UIView *view = (UIView *)[page4.customView viewWithTag:tag];
  164. view.layer.borderWidth = 1.0f;
  165. view.layer.borderColor = [[NCBrandColor sharedInstance] brand].CGColor;
  166. view.layer.cornerRadius = 10;
  167. UILabel *label = (UILabel *)[page4.customView viewWithTag:tag+2];
  168. label.text = [self returnProfession:tag language:language];
  169. UIButton *button = (UIButton *)[page4.customView viewWithTag:tag+3];
  170. [button addTarget:self action:@selector(selectProfession:) forControlEvents:UIControlEventTouchUpInside];
  171. }
  172. // INTRO
  173. self.intro = [[EAIntroView alloc] initWithFrame:self.rootView.bounds andPages:@[page1,page2,page3,page4]];
  174. //self.intro.bgImage = [UIImage imageNamed:@"introBackground"];
  175. self.intro.tapToNext = NO;
  176. self.intro.pageControlY = safeAreaBottom + 40;
  177. self.intro.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
  178. self.intro.pageControl.currentPageIndicatorTintColor = [[NCBrandColor sharedInstance] brand];
  179. self.intro.pageControl.backgroundColor = [UIColor whiteColor];
  180. self.intro.swipeToExit = NO ;
  181. self.intro.skipButton = nil ;
  182. self.intro.swipeToExit = NO;
  183. [self.intro setDelegate:self];
  184. [self.intro showInView:self.rootView animateDuration:0];
  185. }
  186. #pragma --------------------------------------------------------------------------------------------
  187. #pragma mark ===== Action =====
  188. #pragma --------------------------------------------------------------------------------------------
  189. - (IBAction)selectProfession:(UIButton *)sender
  190. {
  191. NSInteger tag = sender.tag-3;
  192. NSString *imageColor;
  193. NSString *profession = [self returnProfession:tag language:@"en"];
  194. UIView *view = (UIView *)[page4.customView viewWithTag:tag];
  195. UIImageView *imageView = (UIImageView *)[page4.customView viewWithTag:tag+1];
  196. UILabel *label = (UILabel *)[page4.customView viewWithTag:tag+2];
  197. switch (tag) {
  198. case 100:
  199. imageColor = @"introCarpenter";
  200. break;
  201. case 200:
  202. imageColor = @"introStovebuilder";
  203. break;
  204. case 300:
  205. imageColor = @"introWindowbuilder";
  206. break;
  207. case 400:
  208. imageColor = @"introInstaller";
  209. break;
  210. case 500:
  211. imageColor = @"introElectrician";
  212. break;
  213. case 600:
  214. imageColor = @"introPainter";
  215. break;
  216. case 700:
  217. imageColor = @"introFlasher";
  218. break;
  219. case 800:
  220. imageColor = @"introBricklayer";
  221. break;
  222. case 900:
  223. imageColor = @"introRoofer";
  224. break;
  225. case 1000:
  226. imageColor = @"introStuccoer";
  227. break;
  228. case 1100:
  229. imageColor = @"introArchitect";
  230. break;
  231. case 1200:
  232. imageColor = @"introOther";
  233. break;
  234. default:
  235. break;
  236. }
  237. if ([professions containsObject:profession]) {
  238. [professions removeObject:profession];
  239. view.backgroundColor = [UIColor clearColor];
  240. label.textColor = [UIColor blackColor];
  241. imageView.image = [UIImage imageNamed:imageColor];
  242. } else {
  243. [professions addObject:profession];
  244. view.backgroundColor = [[NCBrandColor sharedInstance] brand];
  245. label.textColor = [UIColor whiteColor];
  246. imageView.image = [UIImage imageNamed:[imageColor stringByAppendingString:@"White"]];
  247. }
  248. }
  249. - (IBAction)login:(UIButton *)sender
  250. {
  251. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  252. if (professions.count > 0) {
  253. NSString *professionsString = [[professions componentsJoinedByString:@","] stringByReplacingOccurrencesOfString:@" " withString:@""];
  254. [CCUtility setHCBusinessType:professionsString];
  255. selector = k_intro_login;
  256. [self.intro hideWithFadeOutDuration:0.7];
  257. } else {
  258. UILabel *titlePage4 = (UILabel *)[page4.customView viewWithTag:1];
  259. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:titlePage4.text preferredStyle:UIAlertControllerStyleAlert];
  260. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { }];
  261. [alertController addAction:okAction];
  262. [appDelegate.window.rootViewController presentViewController:alertController animated:YES completion:nil];
  263. }
  264. }
  265. - (void)host:(id)sender
  266. {
  267. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  268. NCBrowserWeb *browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  269. browserWebVC.urlBase = [NCBrandOptions sharedInstance].linkLoginHost;
  270. [appDelegate.window.rootViewController presentViewController:browserWebVC animated:YES completion:nil];
  271. }
  272. - (NSString *)returnProfession:(NSInteger)tag language:(NSString *)language
  273. {
  274. if ([language isEqualToString:@"de"]) {
  275. if (tag == 100) return @"SCHREINER";
  276. if (tag == 200) return @"OFENBAUER";
  277. if (tag == 300) return @"FENSTERBAUER";
  278. if (tag == 400) return @"INSTALLATEUR";
  279. if (tag == 500) return @"ELEKTRIKER";
  280. if (tag == 600) return @"MALER";
  281. if (tag == 700) return @"FLASCHNER";
  282. if (tag == 800) return @"MAURER";
  283. if (tag == 900) return @"DACHDECKER";
  284. if (tag == 1000) return @"STUCKATEUR";
  285. if (tag == 1100) return @"ARCHITEKT";
  286. if (tag == 1200) return @"SONSTIGES";
  287. } else if ([language isEqualToString:@"it"]) {
  288. if (tag == 100) return @"FALEGNAME";
  289. if (tag == 200) return @"CAMINETTI";
  290. if (tag == 300) return @"SERRAMENTI";
  291. if (tag == 400) return @"INSTALLATORE";
  292. if (tag == 500) return @"ELETTRICISTA";
  293. if (tag == 600) return @"PITTORE";
  294. if (tag == 700) return @"IDRAULICO";
  295. if (tag == 800) return @"MURATORE";
  296. if (tag == 900) return @"RIPARA TETTI";
  297. if (tag == 1000) return @"STUCCATORE";
  298. if (tag == 1100) return @"ARCHITETTO";
  299. if (tag == 1200) return @"ALTRO";
  300. } else {
  301. if (tag == 100) return @"CARPENTER";
  302. if (tag == 200) return @"STOVE BUILDER";
  303. if (tag == 300) return @"WINDOW BUILDER";
  304. if (tag == 400) return @"INSTALLER";
  305. if (tag == 500) return @"ELECTRICIAN";
  306. if (tag == 600) return @"PAINTER";
  307. if (tag == 700) return @"PLUMBER";
  308. if (tag == 800) return @"BRICK LAYER";
  309. if (tag == 900) return @"ROOFER";
  310. if (tag == 1000) return @"STUCCOER";
  311. if (tag == 1100) return @"ARCHITECT";
  312. if (tag == 1200) return @"OTHER";
  313. }
  314. return nil;
  315. }
  316. - (void)didStartLoading
  317. {
  318. }
  319. - (void)didReceiveServerRedirectForProvisionalNavigationWithUrl:(NSURL *)url
  320. {
  321. }
  322. - (void)didFinishLoadingWithSuccess:(BOOL)success url:(NSURL *)url
  323. {
  324. }
  325. - (void)webDismiss
  326. {
  327. }
  328. @end