CCSplit.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // CCSplit.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/10/15.
  6. // Copyright (c) 2014 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 "CCSplit.h"
  24. #import "AppDelegate.h"
  25. #import "CCLogin.h"
  26. #ifdef CUSTOM_BUILD
  27. #import "CustomSwift.h"
  28. #else
  29. #import "Nextcloud-Swift.h"
  30. #endif
  31. @interface CCSplit ()
  32. {
  33. CCLoginWeb *_loginWeb;
  34. CCLogin *_loginVC;
  35. }
  36. @end
  37. @implementation CCSplit
  38. #pragma --------------------------------------------------------------------------------------------
  39. #pragma mark ===== Init =====
  40. #pragma --------------------------------------------------------------------------------------------
  41. - (id)initWithCoder:(NSCoder *)aDecoder
  42. {
  43. if (self = [super initWithCoder:aDecoder]) {
  44. }
  45. return self;
  46. }
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. self.delegate = self;
  51. [self inizialize];
  52. }
  53. // Apparirà
  54. - (void)viewWillAppear:(BOOL)animated
  55. {
  56. [super viewWillAppear:animated];
  57. [self showIntro];
  58. }
  59. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  60. {
  61. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  62. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  63. // Portrait
  64. } else {
  65. // Landscape
  66. }
  67. }];
  68. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  69. }
  70. #pragma --------------------------------------------------------------------------------------------
  71. #pragma mark ===== inizialization =====
  72. #pragma --------------------------------------------------------------------------------------------
  73. - (void)inizialize
  74. {
  75. // setting version
  76. self.version = [CCUtility setVersionCryptoCloud];
  77. // init home
  78. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  79. }
  80. #pragma --------------------------------------------------------------------------------------------
  81. #pragma mark ===== Intro =====
  82. #pragma --------------------------------------------------------------------------------------------
  83. - (void)showIntro
  84. {
  85. // Brand
  86. if (k_option_disable_intro) {
  87. [CCUtility setIntro:@"1.0"];
  88. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  89. } else {
  90. if ([CCUtility getIntro:@"1.0"] == NO) {
  91. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view];
  92. [_intro showIntroCryptoCloud:0.0];
  93. } else {
  94. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  95. }
  96. }
  97. }
  98. - (void)introWillFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped
  99. {
  100. [CCUtility setIntro:@"1.0"];
  101. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  102. }
  103. #pragma --------------------------------------------------------------------------------------------
  104. #pragma mark ===== newAccount =====
  105. #pragma --------------------------------------------------------------------------------------------
  106. - (void)loginSuccess:(NSInteger)loginType
  107. {
  108. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  109. }
  110. - (void)newAccount
  111. {
  112. if (app.activeAccount.length == 0) {
  113. // Brand
  114. if (k_option_use_login_web) {
  115. _loginWeb = [CCLoginWeb new];
  116. _loginWeb.delegate = self;
  117. _loginWeb.loginType = loginAddForced;
  118. [_loginWeb presentModalWithDefaultTheme:self];
  119. } else {
  120. _loginVC = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
  121. _loginVC.delegate = self;
  122. _loginVC.loginType = loginAddForced;
  123. [self presentViewController:_loginVC animated:YES completion:nil];
  124. }
  125. }
  126. }
  127. #pragma --------------------------------------------------------------------------------------------
  128. #pragma mark ===== Split View Controller =====
  129. #pragma --------------------------------------------------------------------------------------------
  130. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  131. {
  132. return YES;
  133. }
  134. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  135. {
  136. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  137. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  138. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  139. return controller;
  140. }
  141. }
  142. }
  143. // No detail view present
  144. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  145. // Color
  146. [app aspectNavigationControllerBar:secondaryNC.navigationBar encrypted:NO online:YES hidden:NO];
  147. // Ensure back button is enabled
  148. UIViewController *detailViewController = [secondaryNC visibleViewController];
  149. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  150. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  151. return secondaryNC;
  152. }
  153. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  154. {
  155. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  156. UINavigationController *ncMaster = [tbMaster selectedViewController];
  157. //UIViewController *main = [ncMaster.viewControllers firstObject];
  158. UIViewController *detail = [ncMaster.viewControllers lastObject];
  159. if ([detail isKindOfClass:[CCDetail class]]) {
  160. [ncMaster popViewControllerAnimated:NO];
  161. }
  162. return nil;
  163. }
  164. // sender = CCMain
  165. // vc = UINavigationController detail
  166. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  167. {
  168. UINavigationController *ncDetail = (UINavigationController *)vc;
  169. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  170. if ([self.viewControllers[0] isKindOfClass:[UITabBarController class]]) {
  171. UINavigationController *ncMaster = [self.viewControllers[0] selectedViewController];
  172. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  173. return;
  174. }
  175. }
  176. [super showDetailViewController:vc sender:sender];
  177. // display icon "\"
  178. ncDetail.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  179. self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  180. }
  181. // OK
  182. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  183. {
  184. UIViewController *viewController = [svc.viewControllers lastObject];
  185. if ([viewController isKindOfClass:[UINavigationController class]]) {
  186. UINavigationController *navigationController = (UINavigationController *)viewController;
  187. UIViewController *detail = [navigationController.viewControllers firstObject];
  188. if ([detail isKindOfClass:[CCDetail class]]) {
  189. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  190. }
  191. }
  192. }
  193. @end