VLCDropboxCollectionViewController.m 3.0 KB

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