VLCOneDriveCollectionViewController.m 3.5 KB

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