VLCCloudServicesTableViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. if (@available(iOS 11.0, *)) {
  64. self.navigationController.navigationBar.prefersLargeTitles = YES;
  65. }
  66. }
  67. - (void)authenticationSessionsChanged:(NSNotification *)notification
  68. {
  69. [self.tableView reloadData];
  70. }
  71. - (NSString *)detailText
  72. {
  73. int services = [self numberOfAuthorizedServices];
  74. if (services == 1) {
  75. return NSLocalizedString(@"LOGGED_IN_SERVICE", nil);
  76. } else {
  77. return [NSString stringWithFormat:NSLocalizedString(@"LOGGED_IN_SERVICES", ""), services];
  78. }
  79. }
  80. - (int)numberOfAuthorizedServices
  81. {
  82. int i = [[VLCDropboxController sharedInstance] isAuthorized] ? 1 : 0;
  83. i += [[VLCGoogleDriveController sharedInstance] isAuthorized] ? 1 : 0;
  84. i += [[VLCBoxController sharedInstance] isAuthorized] ? 1 : 0;
  85. i += [[VLCOneDriveController sharedInstance] isAuthorized] ? 1 : 0;
  86. return i;
  87. }
  88. - (UIStatusBarStyle)preferredStatusBarStyle
  89. {
  90. return PresentationTheme.current.colors.statusBarStyle;
  91. }
  92. - (UIImage *)cellImage
  93. {
  94. return [UIImage imageNamed:@"iCloudIcon"];
  95. }
  96. #pragma mark - Table view data source
  97. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  98. {
  99. return 5;
  100. }
  101. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. cell.backgroundColor = PresentationTheme.current.colors.cellBackgroundA;
  104. [cell setSeparatorInset:UIEdgeInsetsZero];
  105. [cell setPreservesSuperviewLayoutMargins:NO];
  106. [cell setLayoutMargins:UIEdgeInsetsZero];
  107. }
  108. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  109. VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
  110. cell.cloudTitle.textColor = cell.lonesomeCloudTitle.textColor = PresentationTheme.current.colors.cellTextColor;
  111. switch (indexPath.row) {
  112. case 0: {
  113. //Dropbox
  114. BOOL isAuthorized = [[VLCDropboxController sharedInstance] isAuthorized];
  115. cell.icon.image = [UIImage imageNamed:@"DropboxCell"];
  116. cell.cloudTitle.text = @"Dropbox";
  117. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  118. cell.cloudInformation.textColor = isAuthorized ? PresentationTheme.current.colors.orangeUI : PresentationTheme.current.colors.cellDetailTextColor;
  119. cell.lonesomeCloudTitle.text = @"";
  120. break;
  121. }
  122. case 1: {
  123. //GoogleDrive
  124. BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
  125. cell.icon.image = [UIImage imageNamed:@"DriveCell"];
  126. cell.cloudTitle.text = @"Google Drive";
  127. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  128. cell.cloudInformation.textColor = isAuthorized ? PresentationTheme.current.colors.orangeUI : PresentationTheme.current.colors.cellDetailTextColor;
  129. cell.lonesomeCloudTitle.text = @"";
  130. break;
  131. }
  132. case 2: {
  133. //Box
  134. BOOL isAuthorized = [[VLCBoxController sharedInstance] isAuthorized];
  135. cell.icon.image = [UIImage imageNamed:@"BoxCell"];
  136. cell.cloudTitle.text = @"Box";
  137. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  138. cell.cloudInformation.textColor = isAuthorized ? PresentationTheme.current.colors.orangeUI : PresentationTheme.current.colors.cellDetailTextColor;
  139. cell.lonesomeCloudTitle.text = @"";
  140. break;
  141. }
  142. case 3: {
  143. //OneDrive
  144. BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
  145. cell.icon.image = [UIImage imageNamed:@"OneDriveCell"];
  146. cell.cloudTitle.text = @"OneDrive";
  147. cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
  148. cell.cloudInformation.textColor = isAuthorized ? PresentationTheme.current.colors.orangeUI : PresentationTheme.current.colors.cellDetailTextColor;
  149. cell.lonesomeCloudTitle.text = @"";
  150. break;
  151. }
  152. case 4:
  153. //Cloud Drives
  154. cell.icon.image = [UIImage imageNamed:@"iCloudCell"];
  155. cell.lonesomeCloudTitle.text = @"iCloud";
  156. cell.cloudTitle.text = cell.cloudInformation.text = @"";
  157. break;
  158. default:
  159. break;
  160. }
  161. return cell;
  162. }
  163. #pragma mark - Table view delegate
  164. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  165. {
  166. return 66.0;
  167. }
  168. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  169. {
  170. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  171. switch (indexPath.row) {
  172. case 0:
  173. //dropBox
  174. [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
  175. break;
  176. case 1:
  177. //GoogleDrive
  178. [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
  179. break;
  180. case 2:
  181. //Box
  182. [self.navigationController pushViewController:self.boxTableViewController animated:YES];
  183. break;
  184. case 3:
  185. //OneDrive
  186. [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
  187. break;
  188. case 4:
  189. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  190. [self.documentPickerController showDocumentMenuViewController:[(VLCCloudServiceCell *)[self.tableView cellForRowAtIndexPath:indexPath] icon]];
  191. else
  192. [self.documentPickerController showDocumentMenuViewController:nil];
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. @end