VLCCloudServicesTableViewController.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. cell.lonesomeCloudTitle.text = @"";
  89. break;
  90. }
  91. case 1: {
  92. //GoogleDrive
  93. BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
  94. cell.icon.image = [UIImage imageNamed:@"Drive"];
  95. cell.cloudTitle.text = @"Google Drive";
  96. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  97. cell.lonesomeCloudTitle.text = @"";
  98. break;
  99. }
  100. case 2: {
  101. //Box
  102. BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
  103. cell.icon.image = [UIImage imageNamed:@"Box"];
  104. cell.cloudTitle.text = @"Box";
  105. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  106. cell.lonesomeCloudTitle.text = @"";
  107. break;
  108. }
  109. case 3: {
  110. //OneDrive
  111. BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
  112. cell.icon.image = [UIImage imageNamed:@"OneDrive"];
  113. cell.cloudTitle.text = @"OneDrive";
  114. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  115. cell.lonesomeCloudTitle.text = @"";
  116. break;
  117. }
  118. case 4:
  119. //Cloud Drives
  120. cell.icon.image = [UIImage imageNamed:@"iCloud"];
  121. cell.lonesomeCloudTitle.text = NSLocalizedString(@"CLOUD_SERVICES", nil);
  122. cell.cloudTitle.text = cell.cloudInformation.text = @"";
  123. break;
  124. default:
  125. break;
  126. }
  127. // cell.icon.contentMode = UIViewContentModeScaleAspectFit;
  128. return cell;
  129. }
  130. #pragma mark - Table view delegate
  131. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. // don't let select CLOUD_DRIVES menu item since there is no view controller to reveal
  134. if (indexPath.row == 4) {
  135. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  136. [self.documentPickerController showDocumentMenuViewController:[self.tableView cellForRowAtIndexPath:indexPath]];
  137. } else {
  138. [self.documentPickerController showDocumentMenuViewController:nil];
  139. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  140. }
  141. return nil;
  142. } else
  143. return indexPath;
  144. }
  145. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  146. {
  147. return 66.0;
  148. }
  149. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  150. switch (indexPath.row) {
  151. case 0:
  152. //dropBox
  153. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  154. break;
  155. case 1:
  156. //GoogleDrive
  157. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  158. break;
  159. case 2:
  160. //Box
  161. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  162. break;
  163. case 3:
  164. //OneDrive
  165. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  166. break;
  167. default:
  168. break;
  169. }
  170. }
  171. @end