VLCDropboxCollectionViewController.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "VLCRemoteBrowsingTVCell.h"
  15. #import "VLCRemoteBrowsingTVCell+CloudStorage.h"
  16. @interface VLCDropboxCollectionViewController () <VLCCloudStorageDelegate>
  17. {
  18. VLCDropboxController *_dropboxController;
  19. DBFILESMetadata *_selectedFile;
  20. NSArray *_mediaList;
  21. }
  22. @end
  23. @implementation VLCDropboxCollectionViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. _dropboxController = [VLCDropboxController sharedInstance];
  27. self.controller = _dropboxController;
  28. self.controller.delegate = self;
  29. self.title = @"Dropbox";
  30. }
  31. - (void)viewWillAppear:(BOOL)animated
  32. {
  33. [super viewWillAppear:animated];
  34. self.controller = [VLCDropboxController sharedInstance];
  35. self.controller.delegate = self;
  36. if (self.currentPath != nil) {
  37. NSString *lastPathComponent = self.currentPath.lastPathComponent;
  38. self.title = lastPathComponent.length > 0 ? lastPathComponent : @"Dropbox";
  39. }
  40. [self updateViewAfterSessionChange];
  41. }
  42. - (void)mediaListUpdated
  43. {
  44. _mediaList = [self.controller.currentListFiles copy];
  45. [self.collectionView reloadData];
  46. }
  47. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  48. {
  49. VLCRemoteBrowsingTVCell *cell = (VLCRemoteBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
  50. NSUInteger index = indexPath.row;
  51. if (_mediaList) {
  52. if (index < _mediaList.count) {
  53. cell.dropboxFile = _mediaList[index];
  54. }
  55. }
  56. return cell;
  57. }
  58. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. _selectedFile = _mediaList[indexPath.row];
  61. if (![_selectedFile isKindOfClass:[DBFILESFolderMetadata class]])
  62. [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
  63. else {
  64. /* dive into subdirectory */
  65. NSString *futurePath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.name];
  66. [_dropboxController reset];
  67. VLCDropboxCollectionViewController *targetViewController = [[VLCDropboxCollectionViewController alloc] initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
  68. targetViewController.currentPath = futurePath;
  69. [self.navigationController pushViewController:targetViewController animated:YES];
  70. }
  71. _selectedFile = nil;
  72. }
  73. @end