CCSplit.m 8.1 KB

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