CCSplit.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //
  2. // CCSplit.m
  3. // Nextcloud iOS
  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, CCLoginDelegateWeb>
  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. // Display mode SPLIT
  50. self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
  51. //self.maximumPrimaryColumnWidth = 400;
  52. // Settings TabBar
  53. UITabBarController *tabBarController = [self.viewControllers firstObject];
  54. [appDelegate createTabBarController:tabBarController];
  55. // Settings Navigation Controller
  56. UINavigationController *navigationController = [self.viewControllers lastObject];
  57. [appDelegate aspectNavigationControllerBar:navigationController.navigationBar online:YES hidden:NO];
  58. [self inizialize];
  59. }
  60. // Apparirà
  61. - (void)viewWillAppear:(BOOL)animated
  62. {
  63. [super viewWillAppear:animated];
  64. [self showIntro];
  65. }
  66. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  67. {
  68. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  69. // iPhone + (fallthrough res)
  70. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone && (UIScreen.mainScreen.nativeBounds.size.height == 2208 || UIScreen.mainScreen.nativeBounds.size.height == 1920)) {
  71. // FIX master-detail
  72. UITabBarController *tbc = self.viewControllers.firstObject;
  73. for (UINavigationController *nvc in tbc.viewControllers) {
  74. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  75. [nvc popViewControllerAnimated:NO];
  76. }
  77. }
  78. }
  79. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  80. 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))) {
  81. // Portrait
  82. } else {
  83. // Landscape
  84. }
  85. }];
  86. }
  87. #pragma --------------------------------------------------------------------------------------------
  88. #pragma mark ===== inizialization =====
  89. #pragma --------------------------------------------------------------------------------------------
  90. - (void)inizialize
  91. {
  92. // setting version
  93. self.version = [CCUtility setVersion];
  94. self.build = [CCUtility setBuild];
  95. // init home
  96. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  97. }
  98. #pragma --------------------------------------------------------------------------------------------
  99. #pragma mark ===== Intro =====
  100. #pragma --------------------------------------------------------------------------------------------
  101. - (void)showIntro
  102. {
  103. // Brand
  104. if ([NCBrandOptions sharedInstance].disable_intro) {
  105. [CCUtility setIntro:YES];
  106. if (appDelegate.activeAccount.length == 0) {
  107. [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_login];
  108. }
  109. } else {
  110. if ([CCUtility getIntro] == NO) {
  111. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view];
  112. [_intro show];
  113. } else {
  114. if (appDelegate.activeAccount.length == 0) {
  115. [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_login];
  116. }
  117. }
  118. }
  119. }
  120. - (void)introFinishSelector:(NSInteger)selector
  121. {
  122. switch (selector) {
  123. case k_intro_login:
  124. {
  125. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  126. if (appDelegate.activeAccount.length == 0) {
  127. [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_login];
  128. }
  129. });
  130. }
  131. break;
  132. case k_intro_signup:
  133. {
  134. [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_signup];
  135. }
  136. break;
  137. }
  138. }
  139. #pragma --------------------------------------------------------------------------------------------
  140. #pragma mark === Delegate Login ===
  141. #pragma --------------------------------------------------------------------------------------------
  142. - (void)loginSuccess:(NSInteger)loginType
  143. {
  144. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  145. [appDelegate subscribingNextcloudServerPushNotification];
  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