CCOffline.m 7.4 KB

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