CCOfflineContainer.m 7.6 KB

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