VLCDropboxCollectionViewController.m 2.7 KB

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