VLCCloudServicesTableViewController.m 7.8 KB

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