VLCOneDriveCollectionViewController.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2014-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 "VLCOneDriveCollectionViewController.h"
  12. #import "VLCOneDriveController.h"
  13. #import "VLCRemoteBrowsingTVCell.h"
  14. @interface VLCOneDriveCollectionViewController ()
  15. {
  16. VLCOneDriveObject *_currentFolder;
  17. VLCOneDriveController *_oneDriveController;
  18. }
  19. @end
  20. @implementation VLCOneDriveCollectionViewController
  21. - (instancetype)initWithOneDriveObject:(VLCOneDriveObject *)object
  22. {
  23. self = [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
  24. if (self) {
  25. _oneDriveController = [VLCOneDriveController sharedInstance];
  26. self.controller = _oneDriveController;
  27. _oneDriveController.delegate = self;
  28. _currentFolder = object;
  29. _oneDriveController.currentFolder = object;
  30. [_oneDriveController loadCurrentFolder];
  31. }
  32. return self;
  33. }
  34. - (void)viewWillAppear:(BOOL)animated
  35. {
  36. if (_currentFolder != nil)
  37. self.title = _currentFolder.name;
  38. else
  39. self.title = @"OneDrive";
  40. [self updateViewAfterSessionChange];
  41. self.authorizationInProgress = NO;
  42. [super viewWillAppear:animated];
  43. }
  44. - (void)mediaListUpdated
  45. {
  46. [self.collectionView reloadData];
  47. [self.activityIndicator stopAnimating];
  48. }
  49. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  50. {
  51. VLCCloudStorageCollectionViewCell *cell = (VLCCloudStorageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
  52. if (_currentFolder == nil)
  53. _currentFolder = _oneDriveController.rootFolder;
  54. if (_currentFolder) {
  55. NSArray *items = _currentFolder.items;
  56. if (indexPath.row < items.count) {
  57. cell.oneDriveFile = items[indexPath.row];
  58. }
  59. }
  60. return cell;
  61. }
  62. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  63. {
  64. if (_currentFolder == nil)
  65. return;
  66. NSArray *folderItems = _currentFolder.items;
  67. NSInteger row = indexPath.row;
  68. if (row >= folderItems.count)
  69. return;
  70. VLCOneDriveObject *selectedObject = folderItems[row];
  71. if (selectedObject.isFolder) {
  72. /* dive into sub folder */
  73. VLCOneDriveCollectionViewController *targetViewController = [[VLCOneDriveCollectionViewController alloc] initWithOneDriveObject:selectedObject];
  74. [self.navigationController pushViewController:targetViewController animated:YES];
  75. } else {
  76. /* stream file */
  77. NSURL *url = [NSURL URLWithString:selectedObject.downloadPath];
  78. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  79. [vpc playURL:url successCallback:nil errorCallback:nil];
  80. VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
  81. [self presentViewController:movieVC
  82. animated:YES
  83. completion:nil];
  84. }
  85. }
  86. - (void)sessionWasUpdated
  87. {
  88. [self updateViewAfterSessionChange];
  89. }
  90. @end