CCOfflineContainer.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "Custom.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. #ifdef OPTION_OFFLINE_DISABLE
  57. _pageType = @[k_pageOfflineFavorites, k_pageOfflineLocal];
  58. #else
  59. _pageType = @[k_pageOfflineFavorites, k_pageOfflineOffline, k_pageOfflineLocal];
  60. #endif
  61. _currentPageType = k_pageOfflineFavorites;
  62. self.title = NSLocalizedString(@"_favorites_", nil);
  63. // Create page view controller
  64. self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageViewController"];
  65. self.pageViewController.dataSource = self;
  66. self.pageViewController.delegate = self;
  67. CCOfflinePageContent *startingViewController = [self viewControllerAtIndex:0];
  68. NSArray *viewControllers = @[startingViewController];
  69. [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  70. // Change the size of page view controller
  71. self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  72. [self addChildViewController:_pageViewController];
  73. [self.view addSubview:_pageViewController.view];
  74. [self.pageViewController didMoveToParentViewController:self];
  75. // Enable swipe gesture only for page controller
  76. for (UIScrollView *view in self.pageViewController.view.subviews) {
  77. if ([view isKindOfClass:[UIScrollView class]]) {
  78. view.scrollEnabled = NO;
  79. }
  80. }
  81. }
  82. // Apparirà
  83. - (void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:animated];
  86. // Color
  87. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  88. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  89. // Plus Button
  90. [app plusButtonVisibile:true];
  91. }
  92. #pragma --------------------------------------------------------------------------------------------
  93. #pragma mark ===== Page =====
  94. #pragma --------------------------------------------------------------------------------------------
  95. - (CCOfflinePageContent *)viewControllerAtIndex:(NSUInteger)index
  96. {
  97. if (([self.pageType count] == 0) || (index >= [self.pageType count])) {
  98. return nil;
  99. }
  100. // Create a new view controller and pass suitable data.
  101. CCOfflinePageContent *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageContent"];
  102. pageContentViewController.pageIndex = index;
  103. pageContentViewController.pageType = self.pageType[index];
  104. return pageContentViewController;
  105. }
  106. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
  107. {
  108. NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
  109. if ((index == 0) || (index == NSNotFound)) {
  110. return nil;
  111. }
  112. index--;
  113. return [self viewControllerAtIndex:index];
  114. }
  115. - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
  116. {
  117. NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
  118. if (index == NSNotFound) {
  119. return nil;
  120. }
  121. index++;
  122. if (index == [self.pageType count]) {
  123. return nil;
  124. }
  125. return [self viewControllerAtIndex:index];
  126. }
  127. - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
  128. {
  129. return [self.pageType count];
  130. }
  131. - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
  132. {
  133. return 0;
  134. }
  135. /*
  136. - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers
  137. {
  138. }
  139. */
  140. - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
  141. {
  142. CCOfflinePageContent *vc = [self.pageViewController.viewControllers lastObject];
  143. _currentPageType = vc.pageType;
  144. if ([_currentPageType isEqualToString:k_pageOfflineFavorites]) {
  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. self.title = NSLocalizedString(@"_offline_", nil);
  152. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  153. item.selectedImage = [UIImage imageNamed:image_tabBarOffline];
  154. item.image = [UIImage imageNamed:image_tabBarOffline];
  155. }
  156. if ([_currentPageType isEqualToString:k_pageOfflineLocal]) {
  157. self.title = NSLocalizedString(@"_local_storage_", nil);
  158. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
  159. item.selectedImage = [UIImage imageNamed:image_tabBarLocal];
  160. item.image = [UIImage imageNamed:image_tabBarLocal];
  161. }
  162. }
  163. @end