VLCCloudServicesTableViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 "VLCBoxController.h"
  18. #import "VLCOneDriveTableViewController.h"
  19. #import "VLCOneDriveController.h"
  20. #import "VLCDocumentPickerController.h"
  21. #import "VLCCloudServiceCell.h"
  22. #import "VLCGoogleDriveController.h"
  23. #import "VLC-Swift.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.tableView registerNib:[UINib nibWithNibName:@"VLCCloudServiceCell" bundle:nil] forCellReuseIdentifier:@"CloudServiceCell"];
  35. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
  36. [self themeDidChange];
  37. self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  38. self.googleDriveTableViewController = [[VLCGoogleDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
  39. [[VLCBoxController sharedInstance] startSession];
  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. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  45. {
  46. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  47. if (self) {
  48. self.title = NSLocalizedString(@"CLOUD_SERVICES", @"");
  49. }
  50. return self;
  51. }
  52. - (void)themeDidChange
  53. {
  54. self.tableView.separatorColor = PresentationTheme.current.colors.background;
  55. self.tableView.backgroundColor = PresentationTheme.current.colors.background;
  56. [self setNeedsStatusBarAppearanceUpdate];
  57. }
  58. - (void)viewWillAppear:(BOOL)animated
  59. {
  60. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
  61. [self.tableView reloadData];
  62. [super viewWillAppear:animated];
  63. }
  64. - (void)authenticationSessionsChanged:(NSNotification *)notification
  65. {
  66. [self.tableView reloadData];
  67. }
  68. - (NSString *)detailText
  69. {
  70. int services = [self numberOfAuthorizedServices];
  71. if (services == 1) {
  72. return NSLocalizedString(@"LOGGED_IN_SERVICE", nil);
  73. } else {
  74. return [NSString stringWithFormat:NSLocalizedString(@"LOGGED_IN_SERVICES", ""), services];
  75. }
  76. }
  77. - (int)numberOfAuthorizedServices
  78. {
  79. int i = [[VLCDropboxController sharedInstance] isAuthorized] ? 1 : 0;
  80. i += [[VLCGoogleDriveController sharedInstance] isAuthorized] ? 1 : 0;
  81. i += [[BoxSDK sharedSDK].OAuth2Session isAuthorized] ? 1 : 0;
  82. i += [[VLCOneDriveController sharedInstance] isAuthorized] ? 1 : 0;
  83. return i;
  84. }
  85. - (UIStatusBarStyle)preferredStatusBarStyle
  86. {
  87. return PresentationTheme.current.colors.statusBarStyle;
  88. }
  89. - (UIImage *)cellImage
  90. {
  91. return [UIImage imageNamed:@"iCloudIcon"];
  92. }
  93. #pragma mark - Table view data source
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  95. {
  96. return 5;
  97. }
  98. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. cell.backgroundColor = (indexPath.row % 2 == 0)? PresentationTheme.current.colors.cellBackgroundA: PresentationTheme.current.colors.cellBackgroundB;
  101. [cell setSeparatorInset:UIEdgeInsetsZero];
  102. [cell setPreservesSuperviewLayoutMargins:NO];
  103. [cell setLayoutMargins:UIEdgeInsetsZero];
  104. }
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  106. VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
  107. cell.cloudTitle.textColor = cell.cloudInformation.textColor = cell.lonesomeCloudTitle.textColor = PresentationTheme.current.colors.cellTextColor;
  108. cell.icon.tintColor = PresentationTheme.current.colors.cellTextColor;
  109. switch (indexPath.row) {
  110. case 0: {
  111. //Dropbox
  112. BOOL isAuthorized = [[VLCDropboxController sharedInstance] isAuthorized];
  113. cell.icon.image = [UIImage imageNamed:@"Dropbox"];
  114. cell.cloudTitle.text = @"Dropbox";
  115. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  116. cell.lonesomeCloudTitle.text = @"";
  117. break;
  118. }
  119. case 1: {
  120. //GoogleDrive
  121. BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
  122. cell.icon.image = [UIImage imageNamed:@"Drive"];
  123. cell.cloudTitle.text = @"Google Drive";
  124. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  125. cell.lonesomeCloudTitle.text = @"";
  126. break;
  127. }
  128. case 2: {
  129. //Box
  130. BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
  131. cell.icon.image = [UIImage imageNamed:@"Box"];
  132. cell.cloudTitle.text = @"Box";
  133. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  134. cell.lonesomeCloudTitle.text = @"";
  135. break;
  136. }
  137. case 3: {
  138. //OneDrive
  139. BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
  140. cell.icon.image = [UIImage imageNamed:@"OneDrive"];
  141. cell.cloudTitle.text = @"OneDrive";
  142. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  143. cell.lonesomeCloudTitle.text = @"";
  144. break;
  145. }
  146. case 4:
  147. //Cloud Drives
  148. cell.icon.image = [UIImage imageNamed:@"iCloud"];
  149. cell.lonesomeCloudTitle.text = NSLocalizedString(@"CLOUD_SERVICES", nil);
  150. cell.cloudTitle.text = cell.cloudInformation.text = @"";
  151. break;
  152. default:
  153. break;
  154. }
  155. return cell;
  156. }
  157. #pragma mark - Table view delegate
  158. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  159. {
  160. return 66.0;
  161. }
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  165. switch (indexPath.row) {
  166. case 0:
  167. //dropBox
  168. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  169. break;
  170. case 1:
  171. //GoogleDrive
  172. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  173. break;
  174. case 2:
  175. //Box
  176. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  177. break;
  178. case 3:
  179. //OneDrive
  180. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  181. break;
  182. case 4:
  183. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  184. [self.documentPickerController showDocumentMenuViewController:[(VLCCloudServiceCell *)[self.tableView cellForRowAtIndexPath:indexPath] icon]];
  185. else
  186. [self.documentPickerController showDocumentMenuViewController:nil];
  187. break;
  188. default:
  189. break;
  190. }
  191. }
  192. @end