VLCCloudServicesTableViewController.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.tableView.backgroundColor = [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. [[VLCSidebarController sharedInstance] toggleSidebar];
  55. }
  56. - (void)authenticationSessionsChanged:(NSNotification *)notification
  57. {
  58. [self.tableView reloadData];
  59. }
  60. #pragma mark - Table view data source
  61. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  62. {
  63. return [UIDocumentPickerViewController class] ? 5 : 4;// on iOS 8+ add document picker option
  64. }
  65. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  68. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  69. [cell setSeparatorInset:UIEdgeInsetsZero];
  70. }
  71. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  72. [cell setPreservesSuperviewLayoutMargins:NO];
  73. }
  74. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  75. [cell setLayoutMargins:UIEdgeInsetsZero];
  76. }
  77. }
  78. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
  80. switch (indexPath.row) {
  81. case 0: {
  82. //Dropbox
  83. BOOL isAuthorized = [[VLCDropboxController sharedInstance] isAuthorized];
  84. cell.icon.image = [UIImage imageNamed:@"Dropbox"];
  85. cell.cloudTitle.text = @"Dropbox";
  86. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  87. cell.lonesomeCloudTitle.text = @"";
  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. cell.lonesomeCloudTitle.text = @"";
  97. break;
  98. }
  99. case 2: {
  100. //Box
  101. BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
  102. cell.icon.image = [UIImage imageNamed:@"Box"];
  103. cell.cloudTitle.text = @"Box";
  104. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  105. cell.lonesomeCloudTitle.text = @"";
  106. break;
  107. }
  108. case 3: {
  109. //OneDrive
  110. BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
  111. cell.icon.image = [UIImage imageNamed:@"OneDrive"];
  112. cell.cloudTitle.text = @"OneDrive";
  113. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  114. cell.lonesomeCloudTitle.text = @"";
  115. break;
  116. }
  117. case 4:
  118. //Cloud Drives
  119. cell.icon.image = [UIImage imageNamed:@"iCloud"];
  120. cell.lonesomeCloudTitle.text = NSLocalizedString(@"CLOUD_SERVICES", nil);
  121. cell.cloudTitle.text = cell.cloudInformation.text = @"";
  122. break;
  123. default:
  124. break;
  125. }
  126. return cell;
  127. }
  128. #pragma mark - Table view delegate
  129. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  130. {
  131. // don't let select CLOUD_DRIVES menu item since there is no view controller to reveal
  132. if (indexPath.row == 4) {
  133. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  134. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  135. [self.documentPickerController showDocumentMenuViewController:[(VLCCloudServiceCell *)[self.tableView cellForRowAtIndexPath:indexPath] icon]];
  136. else
  137. [self.documentPickerController showDocumentMenuViewController:nil];
  138. return nil;
  139. } else
  140. return indexPath;
  141. }
  142. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  143. {
  144. return 66.0;
  145. }
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  147. switch (indexPath.row) {
  148. case 0:
  149. //dropBox
  150. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  151. break;
  152. case 1:
  153. //GoogleDrive
  154. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  155. break;
  156. case 2:
  157. //Box
  158. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  159. break;
  160. case 3:
  161. //OneDrive
  162. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  163. break;
  164. default:
  165. break;
  166. }
  167. }
  168. @end