VLCCloudStorageTableViewController.m 7.3 KB

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