CCSplit.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. //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];
  97. }
  98. #pragma --------------------------------------------------------------------------------------------
  99. #pragma mark ===== Intro =====
  100. #pragma --------------------------------------------------------------------------------------------
  101. - (void)showIntro
  102. {
  103. // Brand
  104. if ([NCBrandOptions sharedInstance].disable_intro) {
  105. [CCUtility setIntroMessage:k_Intro set:YES];
  106. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  107. [self introWillFinish:nil type:nil wasSkipped:NO];
  108. } else {
  109. // -1-
  110. if ([CCUtility getIntroMessage:k_Intro] == NO) {
  111. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro];
  112. [_intro show];
  113. }
  114. // -2-
  115. /*
  116. else if ([CCUtility getIntroMessage:k_Intro_no_cryptocloud] == NO) {
  117. _intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  118. [_intro show];
  119. }
  120. */
  121. // NO INTRO
  122. else {
  123. [self introWillFinish:nil type:nil wasSkipped:NO];
  124. }
  125. }
  126. }
  127. - (void)introWillFinish:(EAIntroView *)introView type:(NSString *)type wasSkipped:(BOOL)wasSkipped
  128. {
  129. // -1-
  130. if ([type isEqualToString:k_Intro]) {
  131. [CCUtility setIntroMessage:k_Intro set:YES];
  132. // next
  133. //_intro = [[CCIntro alloc] initWithDelegate:self delegateView:self.view type:k_Intro_no_cryptocloud];
  134. //[_intro show];
  135. //
  136. //return;
  137. }
  138. // -2-
  139. /*
  140. if ([type isEqualToString:k_Intro_no_cryptocloud]) {
  141. [CCUtility setIntroMessage:k_Intro_no_cryptocloud set:YES];
  142. }
  143. */
  144. // check account
  145. [self performSelector:@selector(newAccount) withObject:nil afterDelay:0.1];
  146. }
  147. #pragma --------------------------------------------------------------------------------------------
  148. #pragma mark === Delegate Login ===
  149. #pragma --------------------------------------------------------------------------------------------
  150. - (void)loginSuccess:(NSInteger)loginType
  151. {
  152. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  153. }
  154. - (void)loginClose
  155. {
  156. appDelegate.activeLogin = nil;
  157. }
  158. - (void)loginWebClose
  159. {
  160. appDelegate.activeLoginWeb = nil;
  161. }
  162. #pragma --------------------------------------------------------------------------------------------
  163. #pragma mark ===== newAccount =====
  164. #pragma --------------------------------------------------------------------------------------------
  165. - (void)newAccount
  166. {
  167. if (appDelegate.activeAccount.length == 0) {
  168. [appDelegate openLoginView:self loginType:loginAddForced];
  169. }
  170. }
  171. #pragma --------------------------------------------------------------------------------------------
  172. #pragma mark ===== Split View Controller =====
  173. #pragma --------------------------------------------------------------------------------------------
  174. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  175. {
  176. return YES;
  177. }
  178. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  179. {
  180. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  181. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  182. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  183. return controller;
  184. }
  185. }
  186. }
  187. // No detail view present
  188. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  189. // Color
  190. [appDelegate aspectNavigationControllerBar:secondaryNC.navigationBar online:YES hidden:NO];
  191. // Ensure back button is enabled
  192. UIViewController *detailViewController = [secondaryNC visibleViewController];
  193. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  194. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  195. return secondaryNC;
  196. }
  197. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  198. {
  199. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  200. UINavigationController *ncMaster = [tbMaster selectedViewController];
  201. //UIViewController *main = [ncMaster.viewControllers firstObject];
  202. UIViewController *detail = [ncMaster.viewControllers lastObject];
  203. if ([detail isKindOfClass:[CCDetail class]]) {
  204. [ncMaster popViewControllerAnimated:NO];
  205. }
  206. return nil;
  207. }
  208. // sender = CCMain
  209. // vc = UINavigationController detail
  210. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  211. {
  212. UINavigationController *ncDetail = (UINavigationController *)vc;
  213. UINavigationController *ncMaster = [self.viewControllers.firstObject selectedViewController];
  214. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  215. if ([self.viewControllers.firstObject isKindOfClass:[UITabBarController class]]) {
  216. // Fix : Application tried to present modally an active controller
  217. if ([ncMaster isBeingPresented]) {
  218. // being presented
  219. } else if ([ncMaster isMovingToParentViewController]) {
  220. // being pushed
  221. } else {
  222. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  223. }
  224. return;
  225. }
  226. }
  227. [super showDetailViewController:vc sender:sender];
  228. // display icon "<>"
  229. ncDetail.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  230. }
  231. // OK
  232. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  233. {
  234. UIViewController *viewController = [svc.viewControllers lastObject];
  235. if ([viewController isKindOfClass:[UINavigationController class]]) {
  236. UINavigationController *navigationController = (UINavigationController *)viewController;
  237. UIViewController *detail = [navigationController.viewControllers firstObject];
  238. if ([detail isKindOfClass:[CCDetail class]]) {
  239. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  240. }
  241. }
  242. }
  243. #pragma --------------------------------------------------------------------------------------------
  244. #pragma mark ===== Slide Over - Split View =====
  245. #pragma --------------------------------------------------------------------------------------------
  246. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  247. {
  248. // simply create a property of 'BOOL' type
  249. BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
  250. prevRunningInFullScreen = isRunningInFullScreen;
  251. if (prevRunningInFullScreen == NO) {
  252. // FIX master-detail
  253. UITabBarController *tbc = self.viewControllers.firstObject;
  254. for (UINavigationController *nvc in tbc.viewControllers) {
  255. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  256. [nvc popViewControllerAnimated:NO];
  257. }
  258. }
  259. }
  260. }
  261. @end