VLCCloudStorageTableViewController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 "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. if (!SYSTEM_RUNS_IOS7_OR_LATER) {
  34. self.flatLoginButton.hidden = YES;
  35. [self.loginButton setTitle:NSLocalizedString(@"DROPBOX_LOGIN", nil) forState:UIControlStateNormal];
  36. } else {
  37. self.loginButton.hidden = YES;
  38. [self.flatLoginButton setTitle:NSLocalizedString(@"DROPBOX_LOGIN", nil) forState:UIControlStateNormal];
  39. }
  40. [self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"sudHeaderBg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
  41. self.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
  42. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  43. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  44. _progressView = [VLCProgressView new];
  45. _progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
  46. _numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
  47. [_numberOfFilesBarButtonItem setTitleTextAttributes:@{ UITextAttributeFont : [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. [self _showProgressInToolbar:NO];
  55. }
  56. - (void)viewWillAppear:(BOOL)animated
  57. {
  58. self.navigationController.toolbarHidden = NO;
  59. self.navigationController.toolbar.barStyle = UIBarStyleBlack;
  60. [self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
  61. [super viewWillAppear:animated];
  62. }
  63. - (void)viewWillDisappear:(BOOL)animated
  64. {
  65. self.navigationController.toolbarHidden = YES;
  66. [super viewWillDisappear:animated];
  67. }
  68. - (void)_requestInformationForCurrentPath
  69. {
  70. [_activityIndicator startAnimating];
  71. [self.controller requestDirectoryListingAtPath:self.currentPath];
  72. }
  73. - (void)mediaListUpdated
  74. {
  75. [_activityIndicator stopAnimating];
  76. [self.tableView reloadData];
  77. NSUInteger count = self.controller.currentListFiles.count;
  78. if (count == 0)
  79. self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"NO_FILES", nil);
  80. else if (count != 1)
  81. self.numberOfFilesBarButtonItem.title = [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
  82. else
  83. self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"ONE_FILE", nil);
  84. }
  85. - (void)_showProgressInToolbar:(BOOL)value
  86. {
  87. if (!value)
  88. [self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
  89. else {
  90. _progressView.progressBar.progress = 0.;
  91. [self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
  92. }
  93. }
  94. - (void)operationWithProgressInformationStarted
  95. {
  96. [self _showProgressInToolbar:YES];
  97. }
  98. - (void)updateRemainingTime:(NSString *)time
  99. {
  100. [_progressView updateTime:time];
  101. }
  102. - (void)currentProgressInformation:(CGFloat)progress
  103. {
  104. [_progressView.progressBar setProgress:progress animated:YES];
  105. }
  106. - (void)operationWithProgressInformationStopped
  107. {
  108. [self _showProgressInToolbar:NO];
  109. }
  110. #pragma mark - UITableViewDataSources
  111. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  112. {
  113. return self.controller.currentListFiles.count;
  114. }
  115. #pragma mark - UITableViewDelegate
  116. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  119. }
  120. - (void)goBack
  121. {
  122. if (((![self.currentPath isEqualToString:@""] && ![self.currentPath isEqualToString:@"/"]) && [self.currentPath length] > 0) && [self.controller isAuthorized]){
  123. self.currentPath = [self.currentPath stringByDeletingLastPathComponent];
  124. [self _requestInformationForCurrentPath];
  125. } else
  126. [self.navigationController popViewControllerAnimated:YES];
  127. }
  128. - (void)_showLoginPanel
  129. {
  130. self.loginToCloudStorageView.frame = self.tableView.frame;
  131. self.navigationItem.rightBarButtonItem = nil;
  132. [self.view addSubview:self.loginToCloudStorageView];
  133. }
  134. - (void)updateViewAfterSessionChange
  135. {
  136. self.navigationItem.rightBarButtonItem = _logoutButton;
  137. if(_authorizationInProgress) {
  138. if (self.loginToCloudStorageView.superview) {
  139. [self.loginToCloudStorageView removeFromSuperview];
  140. }
  141. return;
  142. }
  143. if (![self.controller isAuthorized]) {
  144. [self _showLoginPanel];
  145. return;
  146. }
  147. //reload if we didn't come back from streaming
  148. self.currentPath = @"";
  149. if([self.controller.currentListFiles count] == 0)
  150. [self _requestInformationForCurrentPath];
  151. }
  152. - (void)logout
  153. {
  154. [self.controller logout];
  155. [self updateViewAfterSessionChange];
  156. }
  157. - (IBAction)loginAction:(id)sender
  158. {
  159. }
  160. @end