VLCCloudStorageTableViewController.m 7.5 KB

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