CCOfflineContainer.m 7.7 KB

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