VLCOneDriveTableViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*****************************************************************************
  2. * VLCOneDriveTableViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014 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. @interface VLCOneDriveTableViewController () <UITableViewDataSource, UITableViewDelegate>
  19. {
  20. UIBarButtonItem *_backButton;
  21. UIBarButtonItem *_logoutButton;
  22. UIActivityIndicatorView *_activityIndicator;
  23. VLCOneDriveController *_oneDriveController;
  24. }
  25. @end
  26. @implementation VLCOneDriveTableViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. _oneDriveController = [VLCOneDriveController sharedInstance];
  30. _oneDriveController.delegate = self;
  31. self.modalPresentationStyle = UIModalPresentationFormSheet;
  32. self.navigationItem.title = @"OneDrive";
  33. _backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack:)];
  34. self.navigationItem.leftBarButtonItem = _backButton;
  35. _logoutButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_LOGOUT", "") style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
  36. self.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
  37. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  38. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  39. self.cloudStorageLogo = nil;
  40. if (!SYSTEM_RUNS_IOS7_OR_LATER) {
  41. self.flatLoginButton.hidden = YES;
  42. [self.loginButton setTitle:NSLocalizedString(@"ONEDRIVE_LOGIN", nil) forState:UIControlStateNormal];
  43. } else {
  44. self.loginButton.hidden = YES;
  45. [self.flatLoginButton setTitle:NSLocalizedString(@"ONEDRIVE_LOGIN", nil) forState:UIControlStateNormal];
  46. }
  47. _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  48. _activityIndicator.hidesWhenStopped = YES;
  49. _activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
  50. [self.view addSubview:_activityIndicator];
  51. [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
  52. [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
  53. }
  54. - (void)viewWillAppear:(BOOL)animated
  55. {
  56. [super viewWillAppear:animated];
  57. // FIXME: we should update the listing...
  58. [self _showLoginDialog];
  59. [self.cloudStorageLogo sizeToFit];
  60. self.cloudStorageLogo.center = self.view.center;
  61. }
  62. #pragma mark - generic interface interaction
  63. - (IBAction)goBack:(id)sender
  64. {
  65. //FIXME: handle case for being in a folder
  66. [self.navigationController popViewControllerAnimated:YES];
  67. }
  68. #pragma mark - table view data source
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  70. {
  71. return 0;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. return nil;
  76. }
  77. #pragma mark - table view delegate
  78. - (void)tableView:(UITableView *)tableView
  79. willDisplayCell:(UITableViewCell *)cell
  80. forRowAtIndexPath:(NSIndexPath *)indexPath
  81. {
  82. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  83. }
  84. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  86. }
  87. #pragma mark - login dialog
  88. - (void)logout
  89. {
  90. [_oneDriveController logout];
  91. [self updateViewAfterSessionChange];
  92. }
  93. - (void)_showLoginDialog
  94. {
  95. self.loginToCloudStorageView.frame = self.tableView.frame;
  96. self.navigationItem.rightBarButtonItem = nil;
  97. [self.view addSubview:self.loginToCloudStorageView];
  98. }
  99. - (void)loginAction:(id)sender
  100. {
  101. if (![_oneDriveController activeSession])
  102. [_oneDriveController login];
  103. else
  104. [_oneDriveController logout];
  105. }
  106. @end