VLCCloudServicesTableViewController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 "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. [self.tableView reloadData];
  47. [super viewWillAppear:animated];
  48. }
  49. - (void)goBack
  50. {
  51. VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
  52. [[appDelegate revealController] toggleSidebar:![appDelegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  53. }
  54. #pragma mark - Table view data source
  55. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  56. {
  57. return [UIDocumentPickerViewController class] ? 5 : 4;// on iOS 8+ add document picker option
  58. }
  59. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  62. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  63. [cell setSeparatorInset:UIEdgeInsetsZero];
  64. }
  65. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  66. [cell setPreservesSuperviewLayoutMargins:NO];
  67. }
  68. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  69. [cell setLayoutMargins:UIEdgeInsetsZero];
  70. }
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73. VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
  74. switch (indexPath.row) {
  75. case 0: {
  76. //Dropbox
  77. BOOL isAuthorized = [[DBSession sharedSession] isLinked];
  78. cell.icon.image = [UIImage imageNamed:@"Dropbox"];
  79. cell.cloudTitle.text = @"Dropbox";
  80. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  81. break;
  82. }
  83. case 1: {
  84. //GoogleDrive
  85. BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
  86. cell.icon.image = [UIImage imageNamed:@"Drive"];
  87. cell.cloudTitle.text = @"Google Drive";
  88. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  89. break;
  90. }
  91. case 2: {
  92. //Box
  93. BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
  94. cell.icon.image = [UIImage imageNamed:@"Box"];
  95. cell.cloudTitle.text = @"Box";
  96. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  97. break;
  98. }
  99. case 3: {
  100. //OneDrive
  101. //TODO: figure out right way to check session state
  102. BOOL isAuthorized = NO;//[[OneDriveSDK sharedSDK] isAuthorized];
  103. cell.icon.image = [UIImage imageNamed:@"OneDrive"];
  104. cell.cloudTitle.text = @"One Drive";
  105. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  106. break;
  107. }
  108. case 4:
  109. //Cloud Drives
  110. cell.icon.image = [UIImage imageNamed:@"CloudDrives"];
  111. cell.cloudTitle.text = @"Cloud Drives";
  112. cell.cloudInformation.text = @"";
  113. break;
  114. default:
  115. break;
  116. }
  117. return cell;
  118. }
  119. #pragma mark - Table view delegate
  120. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. // don't let select CLOUD_DRIVES menu item since there is no view controller to reveal
  123. if (indexPath.row == 4) {
  124. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  125. [self.documentPickerController showDocumentMenuViewController:[self.tableView cellForRowAtIndexPath:indexPath]];
  126. } else {
  127. [self.documentPickerController showDocumentMenuViewController:nil];
  128. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  129. }
  130. return nil;
  131. } else
  132. return indexPath;
  133. }
  134. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  135. {
  136. return 66.0;
  137. }
  138. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  139. switch (indexPath.row) {
  140. case 0:
  141. //dropBox
  142. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  143. break;
  144. case 1:
  145. //GoogleDrive
  146. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  147. break;
  148. case 2:
  149. //Box
  150. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  151. break;
  152. case 3:
  153. //OneDrive
  154. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  155. break;
  156. default:
  157. break;
  158. }
  159. }
  160. @end