123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #import "CCOfflineContainer.h"
- #import "CCOfflinePageContent.h"
- #import "AppDelegate.h"
- #import "CCSynchronize.h"
- #ifdef CUSTOM_BUILD
- #import "CustomSwift.h"
- #else
- #import "Nextcloud-Swift.h"
- #endif
- #pragma GCC diagnostic ignored "-Wundeclared-selector"
- @interface CCOfflineContainer ()
- {
- UIPageControl *pageControl;
- }
- @end
- @implementation CCOfflineContainer
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
-
- app.activeOffline = self;
- }
- return self;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== View =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
- #ifdef OPTION_OFFLINE_DISABLE
- _pageType = @[k_pageOfflineFavorites, k_pageOfflineLocal];
- #else
- _pageType = @[k_pageOfflineFavorites, k_pageOfflineOffline, k_pageOfflineLocal];
- #endif
-
- _currentPageType = k_pageOfflineFavorites;
- self.title = NSLocalizedString(@"_favorites_", nil);
-
-
- self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageViewController"];
- self.pageViewController.dataSource = self;
- self.pageViewController.delegate = self;
-
- CCOfflinePageContent *startingViewController = [self viewControllerAtIndex:0];
- NSArray *viewControllers = @[startingViewController];
- [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
-
- self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
-
- [self addChildViewController:_pageViewController];
- [self.view addSubview:_pageViewController.view];
- [self.pageViewController didMoveToParentViewController:self];
-
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
-
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
-
- [app plusButtonVisibile:true];
- }
- - (void)triggerProgressTask:(NSNotification *)notification
- {
- NSDictionary *dict = notification.userInfo;
- float progress = [[dict valueForKey:@"progress"] floatValue];
-
- if (progress == 0)
- [self.navigationController cancelCCProgress];
- else
- [self.navigationController setCCProgressPercentage:progress*100 andTintColor:COLOR_NAVIGATIONBAR_PROGRESS];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Page =====
- #pragma --------------------------------------------------------------------------------------------
- - (CCOfflinePageContent *)viewControllerAtIndex:(NSUInteger)index
- {
- if (([self.pageType count] == 0) || (index >= [self.pageType count])) {
- return nil;
- }
-
-
- CCOfflinePageContent *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageContent"];
-
- pageContentViewController.pageIndex = index;
- pageContentViewController.pageType = self.pageType[index];
-
- return pageContentViewController;
- }
- - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
- {
- NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
-
- if ((index == 0) || (index == NSNotFound)) {
- return nil;
- }
-
- index--;
- return [self viewControllerAtIndex:index];
- }
- - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
- {
- NSUInteger index = ((CCOfflinePageContent*) viewController).pageIndex;
-
- if (index == NSNotFound) {
- return nil;
- }
-
- index++;
- if (index == [self.pageType count]) {
- return nil;
- }
- return [self viewControllerAtIndex:index];
- }
- - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
- {
- return [self.pageType count];
- }
- - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
- {
- return 0;
- }
- - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
- {
- CCOfflinePageContent *vc = [self.pageViewController.viewControllers lastObject];
- _currentPageType = vc.pageType;
- if ([_currentPageType isEqualToString:k_pageOfflineFavorites]) {
-
- self.title = NSLocalizedString(@"_favorites_", nil);
-
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
- item.selectedImage = [UIImage imageNamed:image_tabBarFavorite];
- item.image = [UIImage imageNamed:image_tabBarFavorite];
- }
- if ([_currentPageType isEqualToString:k_pageOfflineOffline]) {
-
- self.title = NSLocalizedString(@"_offline_", nil);
-
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
- item.selectedImage = [UIImage imageNamed:image_tabBarOffline];
- item.image = [UIImage imageNamed:image_tabBarOffline];
- }
-
- if ([_currentPageType isEqualToString:k_pageOfflineLocal]) {
-
- self.title = NSLocalizedString(@"_local_storage_", nil);
-
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexOffline];
- item.selectedImage = [UIImage imageNamed:image_tabBarLocal];
- item.image = [UIImage imageNamed:image_tabBarLocal];
- }
- }
- @end
|