CCSplit.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // CCSplit.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 09/10/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 "CCSplit.h"
  24. #import "AppDelegate.h"
  25. #import "CCLogin.h"
  26. #import "NCAutoUpload.h"
  27. #import "NCBridgeSwift.h"
  28. @interface CCSplit () <CCLoginDelegate, CCLoginDelegateWeb>
  29. {
  30. }
  31. @end
  32. @implementation CCSplit
  33. #pragma --------------------------------------------------------------------------------------------
  34. #pragma mark ===== Init =====
  35. #pragma --------------------------------------------------------------------------------------------
  36. - (id)initWithCoder:(NSCoder *)aDecoder
  37. {
  38. if (self = [super initWithCoder:aDecoder]) {
  39. }
  40. return self;
  41. }
  42. - (void)viewDidLoad
  43. {
  44. [self inizialize];
  45. [super viewDidLoad];
  46. }
  47. // Apparirà
  48. - (void)viewWillAppear:(BOOL)animated
  49. {
  50. [super viewWillAppear:animated];
  51. [self showIntro];
  52. }
  53. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  54. {
  55. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  56. 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))) {
  57. // Portrait
  58. } else {
  59. // Landscape
  60. }
  61. }];
  62. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  63. }
  64. #pragma --------------------------------------------------------------------------------------------
  65. #pragma mark ===== inizialization =====
  66. #pragma --------------------------------------------------------------------------------------------
  67. - (void)inizialize
  68. {
  69. // setting version
  70. self.version = [CCUtility setVersion];
  71. self.build = [CCUtility setBuild];
  72. // init home
  73. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  74. }
  75. #pragma --------------------------------------------------------------------------------------------
  76. #pragma mark ===== Intro =====
  77. #pragma --------------------------------------------------------------------------------------------
  78. - (void)showIntro
  79. {
  80. // Brand
  81. if ([NCBrandOptions sharedInstance].disable_intro) {
  82. [CCUtility setIntroMessage:k_Intro set:YES];
  83. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  84. [self introWillFinish:nil type:nil wasSkipped:NO];
  85. } else {
  86. // -1-
  87. if ([CCUtility getIntroMessage:k_Intro] == NO) {
  88. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro];
  89. [_intro show];
  90. }
  91. // -2-
  92. /*
  93. else if ([CCUtility getIntroMessage:k_Intro_no_cryptocloud] == NO) {
  94. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  95. [_intro show];
  96. }
  97. */
  98. // NO INTRO
  99. else {
  100. [self introWillFinish:nil type:nil wasSkipped:NO];
  101. }
  102. }
  103. }
  104. - (void)introWillFinish:(EAIntroView *)introView type:(NSString *)type wasSkipped:(BOOL)wasSkipped
  105. {
  106. // -1-
  107. if ([type isEqualToString:k_Intro]) {
  108. [CCUtility setIntroMessage:k_Intro set:YES];
  109. // next
  110. //_intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  111. //[_intro show];
  112. //
  113. //return;
  114. }
  115. // -2-
  116. /*
  117. if ([type isEqualToString:k_Intro_no_cryptocloud]) {
  118. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  119. }
  120. */
  121. // check account
  122. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  123. }
  124. #pragma --------------------------------------------------------------------------------------------
  125. #pragma mark === Delegate Login ===
  126. #pragma --------------------------------------------------------------------------------------------
  127. - (void)loginSuccess:(NSInteger)loginType
  128. {
  129. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  130. }
  131. - (void)loginDisappear
  132. {
  133. app.activeLogin = nil;
  134. }
  135. #pragma --------------------------------------------------------------------------------------------
  136. #pragma mark ===== newAccount =====
  137. #pragma --------------------------------------------------------------------------------------------
  138. - (void)newAccount
  139. {
  140. if (app.activeAccount.length == 0) {
  141. [app openLoginView:self loginType:loginAddForced];
  142. }
  143. }
  144. #pragma --------------------------------------------------------------------------------------------
  145. #pragma mark ===== Split View Controller =====
  146. #pragma --------------------------------------------------------------------------------------------
  147. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  148. {
  149. return YES;
  150. }
  151. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  152. {
  153. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  154. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  155. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  156. return controller;
  157. }
  158. }
  159. }
  160. // No detail view present
  161. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  162. // Color
  163. [app aspectNavigationControllerBar:secondaryNC.navigationBar online:YES hidden:NO];
  164. // Ensure back button is enabled
  165. UIViewController *detailViewController = [secondaryNC visibleViewController];
  166. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  167. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  168. return secondaryNC;
  169. }
  170. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  171. {
  172. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  173. UINavigationController *ncMaster = [tbMaster selectedViewController];
  174. //UIViewController *main = [ncMaster.viewControllers firstObject];
  175. UIViewController *detail = [ncMaster.viewControllers lastObject];
  176. if ([detail isKindOfClass:[CCDetail class]]) {
  177. [ncMaster popViewControllerAnimated:NO];
  178. }
  179. return nil;
  180. }
  181. // sender = CCMain
  182. // vc = UINavigationController detail
  183. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  184. {
  185. UINavigationController *ncDetail = (UINavigationController *)vc;
  186. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  187. if ([self.viewControllers[0] isKindOfClass:[UITabBarController class]]) {
  188. UINavigationController *ncMaster = [self.viewControllers[0] selectedViewController];
  189. // Fix : Application tried to present modally an active controller
  190. if ([ncMaster isBeingPresented]) {
  191. // being presented
  192. } else if ([ncMaster isMovingToParentViewController]) {
  193. // being pushed
  194. } else {
  195. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  196. }
  197. return;
  198. }
  199. }
  200. [super showDetailViewController:vc sender:sender];
  201. // display icon "\"
  202. ncDetail.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  203. self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  204. }
  205. // OK
  206. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  207. {
  208. UIViewController *viewController = [svc.viewControllers lastObject];
  209. if ([viewController isKindOfClass:[UINavigationController class]]) {
  210. UINavigationController *navigationController = (UINavigationController *)viewController;
  211. UIViewController *detail = [navigationController.viewControllers firstObject];
  212. if ([detail isKindOfClass:[CCDetail class]]) {
  213. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  214. }
  215. }
  216. }
  217. @end