CCSplit.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //
  2. // CCSplit.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/10/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 "CCSplit.h"
  24. #import "AppDelegate.h"
  25. #import "CCLogin.h"
  26. #import "NCAutoUpload.h"
  27. #import "NCBridgeSwift.h"
  28. @interface CCSplit () <CCLoginDelegate, NCLoginWebDelegate>
  29. {
  30. AppDelegate *appDelegate;
  31. BOOL prevRunningInFullScreen;
  32. }
  33. @end
  34. @implementation CCSplit
  35. #pragma --------------------------------------------------------------------------------------------
  36. #pragma mark ===== Init =====
  37. #pragma --------------------------------------------------------------------------------------------
  38. - (id)initWithCoder:(NSCoder *)aDecoder
  39. {
  40. if (self = [super initWithCoder:aDecoder]) {
  41. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  42. prevRunningInFullScreen = YES;
  43. }
  44. return self;
  45. }
  46. - (void)viewDidLoad
  47. {
  48. [super viewDidLoad];
  49. self.delegate = self;
  50. // Display mode SPLIT
  51. self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  52. //self.maximumPrimaryColumnWidth = 400;
  53. // Settings TabBar
  54. UITabBarController *tabBarController = [self.viewControllers firstObject];
  55. [appDelegate createTabBarController:tabBarController];
  56. // Settings Navigation Controller
  57. UINavigationController *navigationController = [self.viewControllers lastObject];
  58. [appDelegate aspectNavigationControllerBar:navigationController.navigationBar online:YES hidden:NO];
  59. [self inizialize];
  60. }
  61. // Apparirà
  62. - (void)viewWillAppear:(BOOL)animated
  63. {
  64. [super viewWillAppear:animated];
  65. [self showIntro];
  66. }
  67. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  68. {
  69. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  70. // iPhone + (fallthrough res)
  71. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone && (UIScreen.mainScreen.nativeBounds.size.height == 2208 || UIScreen.mainScreen.nativeBounds.size.height == 1920)) {
  72. // FIX master-detail
  73. UITabBarController *tbc = self.viewControllers.firstObject;
  74. for (UINavigationController *nvc in tbc.viewControllers) {
  75. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  76. [nvc popViewControllerAnimated:NO];
  77. }
  78. }
  79. }
  80. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  81. 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))) {
  82. // Portrait
  83. } else {
  84. // Landscape
  85. }
  86. }];
  87. }
  88. #pragma --------------------------------------------------------------------------------------------
  89. #pragma mark ===== inizialization =====
  90. #pragma --------------------------------------------------------------------------------------------
  91. - (void)inizialize
  92. {
  93. // setting version
  94. self.version = [CCUtility setVersion];
  95. self.build = [CCUtility setBuild];
  96. // init home
  97. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  98. }
  99. #pragma --------------------------------------------------------------------------------------------
  100. #pragma mark ===== Intro =====
  101. #pragma --------------------------------------------------------------------------------------------
  102. - (void)showIntro
  103. {
  104. // Brand
  105. if ([NCBrandOptions sharedInstance].disable_intro) {
  106. [CCUtility setIntro:YES];
  107. if (appDelegate.activeAccount.length == 0) {
  108. [appDelegate openLoginView:self delegate:self loginType:k_login_Add_Forced selector:k_intro_login];
  109. }
  110. } else {
  111. if ([CCUtility getIntro] == NO) {
  112. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view];
  113. [_intro show];
  114. } else {
  115. if (appDelegate.activeAccount.length == 0) {
  116. [appDelegate openLoginView:self delegate:self loginType:k_login_Add selector:k_intro_login];
  117. }
  118. }
  119. }
  120. }
  121. - (void)introFinishSelector:(NSInteger)selector
  122. {
  123. switch (selector) {
  124. case k_intro_login:
  125. {
  126. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  127. if (appDelegate.activeAccount.length == 0) {
  128. [appDelegate openLoginView:self delegate:self loginType:k_login_Add selector:k_intro_login];
  129. }
  130. });
  131. }
  132. break;
  133. case k_intro_signup:
  134. {
  135. [appDelegate openLoginView:self delegate:self loginType:k_login_Add selector:k_intro_signup];
  136. }
  137. break;
  138. }
  139. }
  140. #pragma --------------------------------------------------------------------------------------------
  141. #pragma mark === Delegate Login ===
  142. #pragma --------------------------------------------------------------------------------------------
  143. - (void)loginSuccess:(NSInteger)loginType
  144. {
  145. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  146. }
  147. #pragma --------------------------------------------------------------------------------------------
  148. #pragma mark ===== Split View Controller =====
  149. #pragma --------------------------------------------------------------------------------------------
  150. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  151. {
  152. return YES;
  153. }
  154. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  155. {
  156. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  157. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  158. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  159. return controller;
  160. }
  161. }
  162. }
  163. // No detail view present
  164. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  165. // Color
  166. [appDelegate aspectNavigationControllerBar:secondaryNC.navigationBar online:YES hidden:NO];
  167. // Ensure back button is enabled
  168. UIViewController *detailViewController = [secondaryNC visibleViewController];
  169. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  170. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  171. return secondaryNC;
  172. }
  173. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  174. {
  175. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  176. UINavigationController *ncMaster = [tbMaster selectedViewController];
  177. //UIViewController *main = [ncMaster.viewControllers firstObject];
  178. UIViewController *detail = [ncMaster.viewControllers lastObject];
  179. if ([detail isKindOfClass:[CCDetail class]]) {
  180. [ncMaster popViewControllerAnimated:NO];
  181. }
  182. return nil;
  183. }
  184. // sender = CCMain
  185. // vc = UINavigationController detail
  186. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  187. {
  188. UINavigationController *ncDetail = (UINavigationController *)vc;
  189. UINavigationController *ncMaster = [self.viewControllers.firstObject selectedViewController];
  190. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  191. if ([self.viewControllers.firstObject isKindOfClass:[UITabBarController class]]) {
  192. // Fix : Application tried to present modally an active controller
  193. if ([ncMaster isBeingPresented]) {
  194. // being presented
  195. } else if ([ncMaster isMovingToParentViewController]) {
  196. // being pushed
  197. } else {
  198. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  199. }
  200. return;
  201. }
  202. }
  203. [super showDetailViewController:vc sender:sender];
  204. // display icon "<>"
  205. ncDetail.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  206. }
  207. // OK
  208. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  209. {
  210. UIViewController *viewController = [svc.viewControllers lastObject];
  211. if ([viewController isKindOfClass:[UINavigationController class]]) {
  212. UINavigationController *navigationController = (UINavigationController *)viewController;
  213. UIViewController *detail = [navigationController.viewControllers firstObject];
  214. if ([detail isKindOfClass:[CCDetail class]]) {
  215. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  216. }
  217. }
  218. }
  219. #pragma --------------------------------------------------------------------------------------------
  220. #pragma mark ===== Slide Over - Split View =====
  221. #pragma --------------------------------------------------------------------------------------------
  222. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  223. {
  224. // simply create a property of 'BOOL' type
  225. BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
  226. prevRunningInFullScreen = isRunningInFullScreen;
  227. if (prevRunningInFullScreen == NO) {
  228. // FIX master-detail
  229. UITabBarController *tbc = self.viewControllers.firstObject;
  230. for (UINavigationController *nvc in tbc.viewControllers) {
  231. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  232. [nvc popViewControllerAnimated:NO];
  233. }
  234. }
  235. }
  236. }
  237. @end