VLCDropboxCollectionViewController.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. @interface VLCDropboxCollectionViewController () <VLCCloudStorageDelegate>
  17. {
  18. VLCDropboxController *_dropboxController;
  19. DBMetadata *_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. VLCCloudStorageCollectionViewCell *cell = (VLCCloudStorageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
  54. if (!cell) {
  55. NSLog(@"oh boy");
  56. }
  57. NSUInteger index = indexPath.row;
  58. if (_mediaList) {
  59. if (index < _mediaList.count) {
  60. cell.dropboxFile = _mediaList[index];
  61. }
  62. }
  63. return cell;
  64. }
  65. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67. _selectedFile = _mediaList[indexPath.row];
  68. if (!_selectedFile.isDirectory)
  69. [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
  70. else {
  71. /* dive into subdirectory */
  72. NSString *futurePath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.filename];
  73. [_dropboxController reset];
  74. VLCDropboxCollectionViewController *targetViewController = [[VLCDropboxCollectionViewController alloc] initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
  75. targetViewController.currentPath = futurePath;
  76. [self.navigationController pushViewController:targetViewController animated:YES];
  77. }
  78. _selectedFile = nil;
  79. }
  80. @end