VLCOneDriveTableViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*****************************************************************************
  2. * VLCOneDriveTableViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCOneDriveTableViewController.h"
  13. #import "VLCOneDriveController.h"
  14. #import "UIBarButtonItem+Theme.h"
  15. #import "VLCCloudStorageTableViewCell.h"
  16. #import "VLCAppDelegate.h"
  17. #import "VLCOneDriveController.h"
  18. #import "VLCProgressView.h"
  19. #import "UIDevice+SpeedCategory.h"
  20. @interface VLCOneDriveTableViewController ()
  21. {
  22. VLCOneDriveController *_oneDriveController;
  23. VLCOneDriveObject *_selectedFile;
  24. }
  25. @end
  26. @implementation VLCOneDriveTableViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. _oneDriveController = (VLCOneDriveController *)[VLCOneDriveController sharedInstance];
  30. self.controller = _oneDriveController;
  31. self.controller.delegate = self;
  32. self.navigationItem.title = @"OneDrive";
  33. self.cloudStorageLogo = nil;
  34. [self.cloudStorageLogo sizeToFit];
  35. self.cloudStorageLogo.center = self.view.center;
  36. }
  37. - (void)viewWillAppear:(BOOL)animated
  38. {
  39. [super viewWillAppear:animated];
  40. [self updateViewAfterSessionChange];
  41. }
  42. #pragma mark - generic interface interaction
  43. - (void)goBack
  44. {
  45. if (_oneDriveController.rootFolder != _oneDriveController.currentFolder) {
  46. if ([_oneDriveController.rootFolder.name isEqualToString:_oneDriveController.currentFolder.parent.name]) {
  47. _oneDriveController.currentFolder = nil;
  48. self.title = _oneDriveController.rootFolder.name;
  49. } else {
  50. _oneDriveController.currentFolder = _oneDriveController.currentFolder.parent;
  51. self.title = _oneDriveController.currentFolder.name;
  52. }
  53. [self.activityIndicator startAnimating];
  54. [_oneDriveController loadCurrentFolder];
  55. } else
  56. [self.navigationController popViewControllerAnimated:YES];
  57. }
  58. #pragma mark - table view data source
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. static NSString *CellIdentifier = @"OneDriveCell";
  62. VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  63. if (cell == nil)
  64. cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier];
  65. cell.oneDriveFile = _oneDriveController.currentFolder.items[indexPath.row];
  66. cell.delegate = self;
  67. return cell;
  68. }
  69. #pragma mark - table view delegate
  70. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. VLCOneDriveObject *selectedObject = _oneDriveController.currentFolder.items[indexPath.row];
  73. if (selectedObject.isFolder) {
  74. /* dive into sub folder */
  75. [self.activityIndicator startAnimating];
  76. _oneDriveController.currentFolder = selectedObject;
  77. [_oneDriveController loadCurrentFolder];
  78. self.title = selectedObject.name;
  79. } else {
  80. /* stream file */
  81. NSURL *url = [NSURL URLWithString:selectedObject.downloadPath];
  82. VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
  83. [appDelegate openMovieFromURL:url];
  84. }
  85. [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
  86. }
  87. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  88. {
  89. if (buttonIndex == 1)
  90. [_oneDriveController downloadObject:_selectedFile];
  91. _selectedFile = nil;
  92. }
  93. #pragma mark - login dialog
  94. - (void)loginAction:(id)sender
  95. {
  96. [_oneDriveController login];
  97. }
  98. #pragma mark - onedrive controller delegation
  99. - (void)sessionWasUpdated
  100. {
  101. [self updateViewAfterSessionChange];
  102. }
  103. #pragma mark - cell delegation
  104. - (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
  105. {
  106. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  107. _selectedFile = _oneDriveController.currentFolder.items[indexPath.row];
  108. if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
  109. /* selected item is a proper file, ask the user if s/he wants to download it */
  110. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil) message:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) otherButtonTitles:NSLocalizedString(@"BUTTON_DOWNLOAD", nil), nil];
  111. [alert show];
  112. } else {
  113. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil) message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
  114. [alert show];
  115. }
  116. }
  117. @end