CCSplit.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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)loginDisappear
  155. {
  156. appDelegate.activeLogin = nil;
  157. }
  158. #pragma --------------------------------------------------------------------------------------------
  159. #pragma mark ===== newAccount =====
  160. #pragma --------------------------------------------------------------------------------------------
  161. - (void)newAccount
  162. {
  163. if (appDelegate.activeAccount.length == 0) {
  164. [appDelegate openLoginView:self loginType:loginAddForced];
  165. }
  166. }
  167. #pragma --------------------------------------------------------------------------------------------
  168. #pragma mark ===== Split View Controller =====
  169. #pragma --------------------------------------------------------------------------------------------
  170. - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
  171. {
  172. return YES;
  173. }
  174. - (UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController
  175. {
  176. if ([primaryViewController isKindOfClass:[UINavigationController class]]) {
  177. for (UIViewController *controller in [(UINavigationController *)primaryViewController viewControllers]) {
  178. if ([controller isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)controller visibleViewController] isKindOfClass:[CCDetail class]]) {
  179. return controller;
  180. }
  181. }
  182. }
  183. // No detail view present
  184. UINavigationController *secondaryNC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCDetailNC"];
  185. // Color
  186. [appDelegate aspectNavigationControllerBar:secondaryNC.navigationBar online:YES hidden:NO];
  187. // Ensure back button is enabled
  188. UIViewController *detailViewController = [secondaryNC visibleViewController];
  189. detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
  190. detailViewController.navigationItem.leftItemsSupplementBackButton = YES;
  191. return secondaryNC;
  192. }
  193. - (UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController
  194. {
  195. UITabBarController *tbMaster = splitViewController.viewControllers[0];
  196. UINavigationController *ncMaster = [tbMaster selectedViewController];
  197. //UIViewController *main = [ncMaster.viewControllers firstObject];
  198. UIViewController *detail = [ncMaster.viewControllers lastObject];
  199. if ([detail isKindOfClass:[CCDetail class]]) {
  200. [ncMaster popViewControllerAnimated:NO];
  201. }
  202. return nil;
  203. }
  204. // sender = CCMain
  205. // vc = UINavigationController detail
  206. - (void)showDetailViewController:(UIViewController *)vc sender:(id)sender
  207. {
  208. UINavigationController *ncDetail = (UINavigationController *)vc;
  209. UINavigationController *ncMaster = [self.viewControllers.firstObject selectedViewController];
  210. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  211. if ([self.viewControllers.firstObject isKindOfClass:[UITabBarController class]]) {
  212. // Fix : Application tried to present modally an active controller
  213. if ([ncMaster isBeingPresented]) {
  214. // being presented
  215. } else if ([ncMaster isMovingToParentViewController]) {
  216. // being pushed
  217. } else {
  218. [ncMaster pushViewController:ncDetail.topViewController animated:YES];
  219. }
  220. return;
  221. }
  222. }
  223. [super showDetailViewController:vc sender:sender];
  224. // display icon "<>"
  225. ncDetail.topViewController.navigationItem.leftBarButtonItem = self.displayModeButtonItem;
  226. }
  227. // OK
  228. - (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
  229. {
  230. UIViewController *viewController = [svc.viewControllers lastObject];
  231. if ([viewController isKindOfClass:[UINavigationController class]]) {
  232. UINavigationController *navigationController = (UINavigationController *)viewController;
  233. UIViewController *detail = [navigationController.viewControllers firstObject];
  234. if ([detail isKindOfClass:[CCDetail class]]) {
  235. [(CCDetail *)detail performSelector:@selector(changeToDisplayMode) withObject:nil afterDelay:0.05];
  236. }
  237. }
  238. }
  239. #pragma --------------------------------------------------------------------------------------------
  240. #pragma mark ===== Slide Over - Split View =====
  241. #pragma --------------------------------------------------------------------------------------------
  242. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  243. {
  244. // simply create a property of 'BOOL' type
  245. BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
  246. prevRunningInFullScreen = isRunningInFullScreen;
  247. if (prevRunningInFullScreen == NO) {
  248. // FIX master-detail
  249. UITabBarController *tbc = self.viewControllers.firstObject;
  250. for (UINavigationController *nvc in tbc.viewControllers) {
  251. if ([nvc.topViewController isKindOfClass:[CCDetail class]]) {
  252. [nvc popViewControllerAnimated:NO];
  253. }
  254. }
  255. }
  256. }
  257. @end