VLCCloudStorageTableViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*****************************************************************************
  2. * VLCCloudStorageTableViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Fabio Ritrovato <sephiroth87 # videolan.org>
  10. * Carola Nitz <nitz.carola # googlemail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCCloudStorageTableViewController.h"
  15. #import "VLCCloudStorageTableViewCell.h"
  16. #if TARGET_OS_IOS
  17. #import "VLCProgressView.h"
  18. #endif
  19. @interface VLCCloudStorageTableViewController()
  20. {
  21. #if TARGET_OS_IOS
  22. VLCProgressView *_progressView;
  23. #endif
  24. UIBarButtonItem *_progressBarButtonItem;
  25. UIBarButtonItem *_logoutButton;
  26. }
  27. @end
  28. @implementation VLCCloudStorageTableViewController
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32. _authorizationInProgress = NO;
  33. #if TARGET_OS_IOS
  34. self.modalPresentationStyle = UIModalPresentationFormSheet;
  35. UIBarButtonItem *backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack)];
  36. self.navigationItem.leftBarButtonItem = backButton;
  37. _logoutButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_LOGOUT", "") style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
  38. [self.loginButton setTitle:NSLocalizedString(@"DROPBOX_LOGIN", nil) forState:UIControlStateNormal];
  39. [self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"sudHeaderBg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
  40. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  41. self.tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  42. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  43. #endif
  44. self.navigationItem.titleView.contentMode = UIViewContentModeScaleAspectFit;
  45. self.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
  46. _numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
  47. [_numberOfFilesBarButtonItem setTitleTextAttributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
  48. _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  49. _activityIndicator.hidesWhenStopped = YES;
  50. _activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
  51. [self.view addSubview:_activityIndicator];
  52. [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
  53. [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
  54. #if TARGET_OS_IOS
  55. _progressView = [VLCProgressView new];
  56. _progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
  57. [self _showProgressInToolbar:NO];
  58. #endif
  59. }
  60. #if TARGET_OS_IOS
  61. - (void)viewWillAppear:(BOOL)animated
  62. {
  63. self.navigationController.toolbarHidden = NO;
  64. self.navigationController.toolbar.barStyle = UIBarStyleBlack;
  65. [self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
  66. [super viewWillAppear:animated];
  67. }
  68. - (void)viewWillDisappear:(BOOL)animated
  69. {
  70. self.navigationController.toolbarHidden = YES;
  71. [super viewWillDisappear:animated];
  72. }
  73. #endif
  74. - (void)_requestInformationForCurrentPath
  75. {
  76. [_activityIndicator startAnimating];
  77. [self.controller requestDirectoryListingAtPath:self.currentPath];
  78. [_activityIndicator stopAnimating];
  79. }
  80. - (void)mediaListUpdated
  81. {
  82. [_activityIndicator stopAnimating];
  83. [self.tableView reloadData];
  84. NSUInteger count = self.controller.currentListFiles.count;
  85. if (count == 0)
  86. self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"NO_FILES", nil);
  87. else if (count != 1)
  88. self.numberOfFilesBarButtonItem.title = [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
  89. else
  90. self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"ONE_FILE", nil);
  91. }
  92. #if TARGET_OS_IOS
  93. - (void)_showProgressInToolbar:(BOOL)value
  94. {
  95. if (!value)
  96. [self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
  97. else {
  98. _progressView.progressBar.progress = 0.;
  99. [self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
  100. }
  101. }
  102. - (void)updateRemainingTime:(NSString *)time
  103. {
  104. [_progressView updateTime:time];
  105. }
  106. - (void)currentProgressInformation:(CGFloat)progress
  107. {
  108. [_progressView.progressBar setProgress:progress animated:YES];
  109. }
  110. #endif
  111. - (void)operationWithProgressInformationStarted
  112. {
  113. #if TARGET_OS_IOS
  114. [self _showProgressInToolbar:YES];
  115. #endif
  116. }
  117. - (void)operationWithProgressInformationStopped
  118. {
  119. #if TARGET_OS_IOS
  120. [self _showProgressInToolbar:NO];
  121. #endif
  122. }
  123. #pragma mark - UITableViewDataSources
  124. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  125. {
  126. return self.controller.currentListFiles.count;
  127. }
  128. #pragma mark - UITableViewDelegate
  129. #if TARGET_OS_IOS
  130. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  133. }
  134. #endif
  135. - (void)goBack
  136. {
  137. if (((![self.currentPath isEqualToString:@""] && ![self.currentPath isEqualToString:@"/"]) && [self.currentPath length] > 0) && [self.controller isAuthorized]){
  138. self.currentPath = [self.currentPath stringByDeletingLastPathComponent];
  139. [self _requestInformationForCurrentPath];
  140. } else
  141. [self.navigationController popViewControllerAnimated:YES];
  142. }
  143. - (void)_showLoginPanel
  144. {
  145. self.loginToCloudStorageView.frame = self.tableView.frame;
  146. self.navigationItem.rightBarButtonItem = nil;
  147. [self.view addSubview:self.loginToCloudStorageView];
  148. }
  149. - (void)updateViewAfterSessionChange
  150. {
  151. self.navigationItem.rightBarButtonItem = _logoutButton;
  152. if(_authorizationInProgress) {
  153. if (self.loginToCloudStorageView.superview) {
  154. [self.loginToCloudStorageView removeFromSuperview];
  155. }
  156. }
  157. if (![self.controller isAuthorized]) {
  158. [_activityIndicator stopAnimating];
  159. [self _showLoginPanel];
  160. return;
  161. }
  162. //reload if we didn't come back from streaming
  163. if (self.currentPath == nil) {
  164. self.currentPath = @"";
  165. }
  166. if([self.controller.currentListFiles count] == 0)
  167. [self _requestInformationForCurrentPath];
  168. }
  169. - (void)logout
  170. {
  171. [self.controller logout];
  172. [self updateViewAfterSessionChange];
  173. }
  174. - (IBAction)loginAction:(id)sender
  175. {
  176. }
  177. @end