VLCSettingsController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*****************************************************************************
  2. * VLCSettingsController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Carola Nitz <nitz.carola # googlemail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCSettingsController.h"
  15. #import "VLCAppDelegate.h"
  16. #import "VLCPlaylistViewController.h"
  17. #import "IASKSettingsReader.h"
  18. #import "IASKAppSettingsViewController.h"
  19. #import "PAPasscodeViewController.h"
  20. #import <DropboxSDK/DropboxSDK.h>
  21. #import "VLCGoogleDriveController.h"
  22. #import "VLCOneDriveController.h"
  23. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  24. {
  25. NSString *_currentUnlinkSpecifier;
  26. NSString *_currentUnlinkDialogTitle;
  27. NSString *_currentCloudName;
  28. }
  29. @end
  30. @implementation VLCSettingsController
  31. - (id)init
  32. {
  33. self = [super init];
  34. if (self)
  35. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  36. return self;
  37. }
  38. - (void)dealloc
  39. {
  40. [[NSNotificationCenter defaultCenter] removeObserver:self];
  41. }
  42. - (void)willShow
  43. {
  44. [self filterCloudStorageCellsWithAnimation:NO];
  45. }
  46. - (void)settingDidChange:(NSNotification*)notification
  47. {
  48. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  49. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  50. if (passcodeOn) {
  51. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  52. passcodeLockController.delegate = self;
  53. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  54. }
  55. }
  56. }
  57. - (void) filterCloudStorageCellsWithAnimation:(BOOL)shouldAnimate
  58. {
  59. NSMutableSet * hideKeys = [[NSMutableSet alloc] init];
  60. if (![[DBSession sharedSession] isLinked])
  61. [hideKeys addObject:@"UnlinkDropbox"];
  62. if (![[VLCGoogleDriveController sharedInstance] isAuthorized])
  63. [hideKeys addObject:@"UnlinkGoogleDrive"];
  64. if (![[VLCOneDriveController sharedInstance] activeSession])
  65. [hideKeys addObject:@"UnlinkOneDrive"];
  66. [self.viewController setHiddenKeys:hideKeys animated:shouldAnimate];
  67. }
  68. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  69. {
  70. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  71. }
  72. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier
  73. {
  74. _currentUnlinkSpecifier = specifier.key;
  75. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"]) {
  76. _currentCloudName = @"Dropbox";
  77. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_DROPBOX", nil);
  78. } else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"]) {
  79. _currentCloudName = @"Google Drive";
  80. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_GOOGLEDRIVE", nil);
  81. } else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkOneDrive"]) {
  82. _currentCloudName = @"OneDrive";
  83. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_ONEDRIVE", nil);
  84. }
  85. UIAlertView *alert = [[UIAlertView alloc]
  86. initWithTitle:_currentUnlinkDialogTitle
  87. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING", nil), _currentCloudName]
  88. delegate:self
  89. cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
  90. otherButtonTitles:NSLocalizedString(@"BUTTON_CLOUDUNLINKING", nil), nil];
  91. [alert show];
  92. }
  93. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  94. {
  95. if (buttonIndex == 1) {
  96. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"])
  97. [[DBSession sharedSession] unlinkAll];
  98. else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"])
  99. [[VLCGoogleDriveController sharedInstance] logout];
  100. else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkOneDrive"])
  101. [[VLCOneDriveController sharedInstance] logout];
  102. _currentUnlinkSpecifier = nil;
  103. UIAlertView *alert = [[UIAlertView alloc]
  104. initWithTitle:_currentUnlinkDialogTitle
  105. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING_DONE", nil), _currentCloudName]
  106. delegate:self
  107. cancelButtonTitle:NSLocalizedString(@"BUTTON_DONE", nil)
  108. otherButtonTitles:nil];
  109. [alert show];
  110. [self filterCloudStorageCellsWithAnimation:YES];
  111. _currentUnlinkDialogTitle = nil;
  112. _currentCloudName = nil;
  113. }
  114. }
  115. #pragma mark - PAPasscode delegate
  116. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  117. {
  118. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  119. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  120. [defaults synchronize];
  121. [controller dismissViewControllerAnimated:YES completion:nil];
  122. }
  123. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  124. {
  125. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  126. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  127. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  128. [defaults synchronize];
  129. [controller dismissViewControllerAnimated:YES completion:nil];
  130. }
  131. @end