CCSplit.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. 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. // Navigation Controller del detail colorato e con le freccette per l'espansione <> displayModeButtonItem
  52. UINavigationController *navigationController = [self.viewControllers lastObject];
  53. navigationController.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  54. [appDelegate aspectNavigationControllerBar:navigationController.navigationBar online:YES hidden:NO];
  55. [self inizialize];
  56. }
  57. // Apparirà
  58. - (void)viewWillAppear:(BOOL)animated
  59. {
  60. [super viewWillAppear:animated];
  61. [self showIntro];
  62. }
  63. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  64. {
  65. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  66. // iPhone + (fallthrough res)
  67. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone && (UIScreen.mainScreen.nativeBounds.size.height == 2208 || UIScreen.mainScreen.nativeBounds.size.height == 1920)) {
  68. // FIX master-detail
  69. UITabBarController *tbc = self.viewControllers.firstObject;
  70. for (UINavigationController *nvc in tbc.viewControllers) {
  71. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  72. [nvc popViewControllerAnimated:NO];
  73. }
  74. }
  75. }
  76. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  77. 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))) {
  78. // Portrait
  79. } else {
  80. // Landscape
  81. }
  82. }];
  83. }
  84. #pragma --------------------------------------------------------------------------------------------
  85. #pragma mark ===== inizialization =====
  86. #pragma --------------------------------------------------------------------------------------------
  87. - (void)inizialize
  88. {
  89. // setting version
  90. self.version = [CCUtility setVersion];
  91. self.build = [CCUtility setBuild];
  92. // init home
  93. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  94. }
  95. #pragma --------------------------------------------------------------------------------------------
  96. #pragma mark ===== Intro =====
  97. #pragma --------------------------------------------------------------------------------------------
  98. - (void)showIntro
  99. {
  100. // Brand
  101. if ([NCBrandOptions sharedInstance].disable_intro) {
  102. [CCUtility setIntroMessage:k_Intro set:YES];
  103. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  104. [self introWillFinish:nil type:nil wasSkipped:NO];
  105. } else {
  106. // -1-
  107. if ([CCUtility getIntroMessage:k_Intro] == NO) {
  108. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro];
  109. [_intro show];
  110. }
  111. // -2-
  112. /*
  113. else if ([CCUtility getIntroMessage:k_Intro_no_cryptocloud] == NO) {
  114. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  115. [_intro show];
  116. }
  117. */
  118. // NO INTRO
  119. else {
  120. [self introWillFinish:nil type:nil wasSkipped:NO];
  121. }
  122. }
  123. }
  124. - (void)introWillFinish:(EAIntroView *)introView type:(NSString *)type wasSkipped:(BOOL)wasSkipped
  125. {
  126. // -1-
  127. if ([type isEqualToString:k_Intro]) {
  128. [CCUtility setIntroMessage:k_Intro set:YES];
  129. // next
  130. //_intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  131. //[_intro show];
  132. //
  133. //return;
  134. }
  135. // -2-
  136. /*
  137. if ([type isEqualToString:k_Intro_no_cryptocloud]) {
  138. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  139. }
  140. */
  141. // check account
  142. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  143. }
  144. #pragma --------------------------------------------------------------------------------------------
  145. #pragma mark === Delegate Login ===
  146. #pragma --------------------------------------------------------------------------------------------
  147. - (void)loginSuccess:(NSInteger)loginType
  148. {
  149. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  150. }
  151. - (void)loginDisappear
  152. {
  153. appDelegate.activeLogin = nil;
  154. }
  155. #pragma --------------------------------------------------------------------------------------------
  156. #pragma mark ===== newAccount =====
  157. #pragma --------------------------------------------------------------------------------------------
  158. - (void)newAccount
  159. {
  160. if (appDelegate.activeAccount.length == 0) {
  161. [appDelegate openLoginView:self loginType:loginAddForced];
  162. }
  163. }
  164. #pragma --------------------------------------------------------------------------------------------
  165. #pragma mark ===== Split View Controller =====
  166. #pragma --------------------------------------------------------------------------------------------
  167. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  168. {
  169. return YES;
  170. }
  171. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  172. {
  173. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  174. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  175. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  176. return controller;
  177. }
  178. }
  179. }
  180. // No detail view present
  181. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  182. // Color
  183. [appDelegate aspectNavigationControllerBar:secondaryNC.navigationBar online:YES hidden:NO];
  184. // Ensure back button is enabled
  185. UIViewController *detailViewController = [secondaryNC visibleViewController];
  186. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  187. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  188. return secondaryNC;
  189. }
  190. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  191. {
  192. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  193. UINavigationController *ncMaster = [tbMaster selectedViewController];
  194. //UIViewController *main = [ncMaster.viewControllers firstObject];
  195. UIViewController *detail = [ncMaster.viewControllers lastObject];
  196. if ([detail isKindOfClass:[CCDetail class]]) {
  197. [ncMaster popViewControllerAnimated:NO];
  198. }
  199. return nil;
  200. }
  201. // sender = CCMain
  202. // vc = UINavigationController detail
  203. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  204. {
  205. UINavigationController *ncDetail = (UINavigationController *)vc;
  206. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  207. if ([self.viewControllers[0] isKindOfClass:[UITabBarController class]]) {
  208. UINavigationController *ncMaster = [self.viewControllers[0] selectedViewController];
  209. // Fix : Application tried to present modally an active controller
  210. if ([ncMaster isBeingPresented]) {
  211. // being presented
  212. } else if ([ncMaster isMovingToParentViewController]) {
  213. // being pushed
  214. } else {
  215. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  216. }
  217. return;
  218. }
  219. }
  220. [super showDetailViewController:vc sender:sender];
  221. }
  222. // OK
  223. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  224. {
  225. UIViewController *viewController = [svc.viewControllers lastObject];
  226. if ([viewController isKindOfClass:[UINavigationController class]]) {
  227. UINavigationController *navigationController = (UINavigationController *)viewController;
  228. UIViewController *detail = [navigationController.viewControllers firstObject];
  229. if ([detail isKindOfClass:[CCDetail class]]) {
  230. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  231. }
  232. }
  233. }
  234. #pragma --------------------------------------------------------------------------------------------
  235. #pragma mark ===== Slide Over - Split View =====
  236. #pragma --------------------------------------------------------------------------------------------
  237. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  238. {
  239. // simply create a property of 'BOOL' type
  240. BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
  241. prevRunningInFullScreen = isRunningInFullScreen;
  242. if (prevRunningInFullScreen == NO) {
  243. // FIX master-detail
  244. UITabBarController *tbc = self.viewControllers.firstObject;
  245. for (UINavigationController *nvc in tbc.viewControllers) {
  246. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  247. [nvc popViewControllerAnimated:NO];
  248. }
  249. }
  250. }
  251. }
  252. @end