VLCDropboxCollectionViewController.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCDropboxCollectionViewController.h"
  12. #import "VLCDropboxController.h"
  13. #import "UIDevice+VLC.h"
  14. #import "DBKeychain.h"
  15. #import "VLCRemoteBrowsingTVCell.h"
  16. #import "VLCRemoteBrowsingTVCell+CloudStorage.h"
  17. @interface VLCDropboxCollectionViewController () <VLCCloudStorageDelegate>
  18. {
  19. VLCDropboxController *_dropboxController;
  20. DBMetadata *_selectedFile;
  21. NSArray *_mediaList;
  22. }
  23. @end
  24. @implementation VLCDropboxCollectionViewController
  25. - (void)dealloc
  26. {
  27. [[NSNotificationCenter defaultCenter] removeObserver:self];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. _dropboxController = [VLCDropboxController sharedInstance];
  32. self.controller = _dropboxController;
  33. self.controller.delegate = self;
  34. self.title = @"Dropbox";
  35. }
  36. - (void)viewWillAppear:(BOOL)animated
  37. {
  38. [super viewWillAppear:animated];
  39. self.controller = [VLCDropboxController sharedInstance];
  40. self.controller.delegate = self;
  41. if (self.currentPath != nil) {
  42. NSString *lastPathComponent = self.currentPath.lastPathComponent;
  43. self.title = lastPathComponent.length > 0 ? lastPathComponent : @"Dropbox";
  44. }
  45. [self updateViewAfterSessionChange];
  46. }
  47. - (void)mediaListUpdated
  48. {
  49. _mediaList = [self.controller.currentListFiles copy];
  50. [self.collectionView reloadData];
  51. }
  52. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  53. {
  54. VLCRemoteBrowsingTVCell *cell = (VLCRemoteBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
  55. NSUInteger index = indexPath.row;
  56. if (_mediaList) {
  57. if (index < _mediaList.count) {
  58. cell.dropboxFile = _mediaList[index];
  59. }
  60. }
  61. return cell;
  62. }
  63. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  64. {
  65. _selectedFile = _mediaList[indexPath.row];
  66. if (!_selectedFile.isDirectory)
  67. [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
  68. else {
  69. /* dive into subdirectory */
  70. NSString *futurePath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.filename];
  71. [_dropboxController reset];
  72. VLCDropboxCollectionViewController *targetViewController = [[VLCDropboxCollectionViewController alloc] initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
  73. targetViewController.currentPath = futurePath;
  74. [self.navigationController pushViewController:targetViewController animated:YES];
  75. }
  76. _selectedFile = nil;
  77. }
  78. @end