VLCCloudServicesTableViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*****************************************************************************
  2. * VLCCloudServicesTableViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # googlemail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "UIBarButtonItem+Theme.h"
  13. #import "VLCCloudServicesTableViewController.h"
  14. #import "VLCAppDelegate.h"
  15. #import "VLCDropboxTableViewController.h"
  16. #import "VLCGoogleDriveTableViewController.h"
  17. #import "VLCBoxTableViewController.h"
  18. #import "VLCOneDriveTableViewController.h"
  19. #import "VLCOneDriveController.h"
  20. #import "VLCDocumentPickerController.h"
  21. #import "VLCCloudServiceCell.h"
  22. #import <DropboxSDK/DropboxSDK.h>
  23. #import <BoxSDK/BoxSDK.h>
  24. #import "VLCGoogleDriveController.h"
  25. @interface VLCCloudServicesTableViewController ()
  26. @property (nonatomic) VLCDropboxTableViewController *dropboxTableViewController;
  27. @property (nonatomic) VLCGoogleDriveTableViewController *googleDriveTableViewController;
  28. @property (nonatomic) VLCBoxTableViewController *boxTableViewController;
  29. @property (nonatomic) VLCOneDriveTableViewController *oneDriveTableViewController;
  30. @property (nonatomic) VLCDocumentPickerController *documentPickerController;
  31. @end
  32. @implementation VLCCloudServicesTableViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.title = NSLocalizedString(@"CLOUD_SERVICES", "");
  36. [self.tableView registerNib:[UINib nibWithNibName:@"VLCCloudServiceCell" bundle:nil] forCellReuseIdentifier:@"CloudServiceCell"];
  37. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack)];
  38. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  39. self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  40. self.googleDriveTableViewController = [[VLCGoogleDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  41. self.boxTableViewController = [[VLCBoxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  42. self.oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  43. self.documentPickerController = [VLCDocumentPickerController new];
  44. }
  45. - (void)viewWillAppear:(BOOL)animated
  46. {
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
  48. [self.tableView reloadData];
  49. [super viewWillAppear:animated];
  50. }
  51. - (void)goBack
  52. {
  53. [[NSNotificationCenter defaultCenter] removeObserver:self];
  54. VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  55. [[appDelegate revealController] toggleSidebar:![appDelegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  56. }
  57. - (void)authenticationSessionsChanged:(NSNotification *)notification
  58. {
  59. [self.tableView reloadData];
  60. }
  61. #pragma mark - Table view data source
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  63. {
  64. return [UIDocumentPickerViewController class] ? 5 : 4;// on iOS 8+ add document picker option
  65. }
  66. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  69. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  70. [cell setSeparatorInset:UIEdgeInsetsZero];
  71. }
  72. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  73. [cell setPreservesSuperviewLayoutMargins:NO];
  74. }
  75. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  76. [cell setLayoutMargins:UIEdgeInsetsZero];
  77. }
  78. }
  79. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  80. VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
  81. switch (indexPath.row) {
  82. case 0: {
  83. //Dropbox
  84. BOOL isAuthorized = [[DBSession sharedSession] isLinked];
  85. cell.icon.image = [UIImage imageNamed:@"Dropbox"];
  86. cell.cloudTitle.text = @"Dropbox";
  87. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  88. break;
  89. }
  90. case 1: {
  91. //GoogleDrive
  92. BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
  93. cell.icon.image = [UIImage imageNamed:@"Drive"];
  94. cell.cloudTitle.text = @"Google Drive";
  95. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  96. break;
  97. }
  98. case 2: {
  99. //Box
  100. BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
  101. cell.icon.image = [UIImage imageNamed:@"Box"];
  102. cell.cloudTitle.text = @"Box";
  103. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  104. break;
  105. }
  106. case 3: {
  107. //OneDrive
  108. BOOL isAuthorized = [[VLCOneDriveController sharedInstance] activeSession];
  109. cell.icon.image = [UIImage imageNamed:@"OneDrive"];
  110. cell.cloudTitle.text = @"OneDrive";
  111. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  112. break;
  113. }
  114. case 4:
  115. //Cloud Drives
  116. cell.icon.image = [UIImage imageNamed:@"CloudDrives"];
  117. cell.cloudTitle.text = @"Cloud Drives";
  118. cell.cloudInformation.text = @"";
  119. break;
  120. default:
  121. break;
  122. }
  123. return cell;
  124. }
  125. #pragma mark - Table view delegate
  126. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  127. {
  128. // don't let select CLOUD_DRIVES menu item since there is no view controller to reveal
  129. if (indexPath.row == 4) {
  130. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  131. [self.documentPickerController showDocumentMenuViewController:[self.tableView cellForRowAtIndexPath:indexPath]];
  132. } else {
  133. [self.documentPickerController showDocumentMenuViewController:nil];
  134. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  135. }
  136. return nil;
  137. } else
  138. return indexPath;
  139. }
  140. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  141. {
  142. return 66.0;
  143. }
  144. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  145. switch (indexPath.row) {
  146. case 0:
  147. //dropBox
  148. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  149. break;
  150. case 1:
  151. //GoogleDrive
  152. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  153. break;
  154. case 2:
  155. //Box
  156. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  157. break;
  158. case 3:
  159. //OneDrive
  160. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. @end