CCOfflineContainer.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // CCOfflineContainer.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/17.
  6. // Copyright (c) 2014 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 "CCOfflineContainer.h"
  24. #import "CCOfflinePageContent.h"
  25. #import "AppDelegate.h"
  26. #import "CCSynchronize.h"
  27. #ifdef CUSTOM_BUILD
  28. #import "NextcloudCustom-Swift.h"
  29. #else
  30. #import "Nextcloud-Swift.h"
  31. #endif
  32. #pragma GCC diagnostic ignored "-Wundeclared-selector"
  33. @interface CCOfflineContainer ()
  34. {
  35. UIPageControl *pageControl;
  36. }
  37. @end
  38. @implementation CCOfflineContainer
  39. #pragma --------------------------------------------------------------------------------------------
  40. #pragma mark ===== Init =====
  41. #pragma --------------------------------------------------------------------------------------------
  42. - (id)initWithCoder:(NSCoder *)aDecoder
  43. {
  44. if (self = [super initWithCoder:aDecoder]) {
  45. app.activeOffline = self;
  46. }
  47. return self;
  48. }
  49. #pragma --------------------------------------------------------------------------------------------
  50. #pragma mark ===== View =====
  51. #pragma --------------------------------------------------------------------------------------------
  52. - (void)viewDidLoad
  53. {
  54. [super viewDidLoad];
  55. // Create data model
  56. _pageType = @[k_pageOfflineFavorites, k_pageOfflineOffline, k_pageOfflineLocal];
  57. _currentPageType = k_pageOfflineFavorites;
  58. self.title = NSLocalizedString(@"_favorites_", nil);
  59. // Create page view controller
  60. self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageViewController"];
  61. self.pageViewController.dataSource = self;
  62. self.pageViewController.delegate = self;
  63. CCOfflinePageContent *startingViewController = [self viewControllerAtIndex:0];
  64. NSArray *viewControllers = @[startingViewController];
  65. [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  66. // Change the size of page view controller
  67. self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  68. [self addChildViewController:_pageViewController];
  69. [self.view addSubview:_pageViewController.view];
  70. [self.pageViewController didMoveToParentViewController:self];
  71. // Enable swipe gesture only for page controller
  72. for (UIScrollView *view in self.pageViewController.view.subviews) {
  73. if ([view isKindOfClass:[UIScrollView class]]) {
  74. view.scrollEnabled = NO;
  75. }
  76. }
  77. }
  78. // Apparirà
  79. - (void)viewWillAppear:(BOOL)animated
  80. {
  81. [super viewWillAppear:animated];
  82. // Color
  83. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  84. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  85. // Plus Button
  86. [app plusButtonVisibile:true];
  87. }
  88. #pragma --------------------------------------------------------------------------------------------
  89. #pragma mark ===== Page =====
  90. #pragma --------------------------------------------------------------------------------------------
  91. - (CCOfflinePageContent *)viewControllerAtIndex:(NSUInteger)index
  92. {
  93. if (([self.pageType count] == 0) || (index >= [self.pageType count])) {
  94. return nil;
  95. }
  96. // Create a new view controller and pass suitable data.
  97. CCOfflinePageContent *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageContent"];
  98. pageContentViewController.pageIndex = index;
  99. pageContentViewController.pageType = self.pageType[index];
  100. return pageContentViewController;
  101. }
  102. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
  103. {
  104. NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
  105. if ((index == 0) || (index == NSNotFound)) {
  106. return nil;
  107. }
  108. index--;
  109. return [self viewControllerAtIndex:index];
  110. }
  111. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
  112. {
  113. NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
  114. if (index == NSNotFound) {
  115. return nil;
  116. }
  117. index++;
  118. if (index == [self.pageType count]) {
  119. return nil;
  120. }
  121. return [self viewControllerAtIndex:index];
  122. }
  123. - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
  124. {
  125. return [self.pageType count];
  126. }
  127. - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
  128. {
  129. return 0;
  130. }
  131. /*
  132. - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers
  133. {
  134. }
  135. */
  136. - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
  137. {
  138. CCOfflinePageContent *vc = [self.pageViewController.viewControllers lastObject];
  139. NSString *serverUrl = vc.serverUrl;
  140. _currentPageType = vc.pageType;
  141. if ([_currentPageType isEqualToString:k_pageOfflineFavorites]) {
  142. if (serverUrl)
  143. self.title = NSLocalizedString(@"_favorites_", nil);
  144. else
  145. self.title = NSLocalizedString(@"_favorites_", nil);
  146. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  147. item.selectedImage = [UIImage imageNamed:image_tabBarFavorite];
  148. item.image = [UIImage imageNamed:image_tabBarFavorite];
  149. }
  150. if ([_currentPageType isEqualToString:k_pageOfflineOffline]) {
  151. if (serverUrl)
  152. self.title = NSLocalizedString(@"_offline_", nil);
  153. else
  154. self.title = NSLocalizedString(@"_offline_", nil);
  155. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  156. item.selectedImage = [UIImage imageNamed:image_tabBarOffline];
  157. item.image = [UIImage imageNamed:image_tabBarOffline];
  158. }
  159. if ([_currentPageType isEqualToString:k_pageOfflineLocal]) {
  160. if ([serverUrl isEqualToString:[CCUtility getDirectoryLocal]])
  161. self.title = NSLocalizedString(@"_local_storage_", nil);
  162. else
  163. self.title = NSLocalizedString(@"_local_storage_", nil);
  164. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  165. item.selectedImage = [UIImage imageNamed:image_tabBarLocal];
  166. item.image = [UIImage imageNamed:image_tabBarLocal];
  167. }
  168. }
  169. @end