VLCSettingsController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  23. {
  24. NSString *_currentUnlinkSpecifier;
  25. NSString *_currentUnlinkDialogTitle;
  26. NSString *_currentCloudName;
  27. }
  28. @end
  29. @implementation VLCSettingsController
  30. - (id)init
  31. {
  32. self = [super init];
  33. if (self)
  34. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  35. return self;
  36. }
  37. - (void)dealloc
  38. {
  39. [[NSNotificationCenter defaultCenter] removeObserver:self];
  40. }
  41. - (void)willShow
  42. {
  43. [self filterCloudStorageCellsWithAnimation:NO];
  44. }
  45. - (void)settingDidChange:(NSNotification*)notification
  46. {
  47. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  48. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  49. if (passcodeOn) {
  50. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  51. passcodeLockController.delegate = self;
  52. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  53. }
  54. }
  55. }
  56. - (void) filterCloudStorageCellsWithAnimation:(BOOL)shouldAnimate
  57. {
  58. NSMutableSet * hideKeys = [[NSMutableSet alloc] init];
  59. if (![[DBSession sharedSession] isLinked]) {
  60. [hideKeys addObject:@"UnlinkDropbox"];
  61. }
  62. if (![[VLCGoogleDriveController sharedInstance] isAuthorized]) {
  63. [hideKeys addObject:@"UnlinkGoogleDrive"];
  64. }
  65. [self.viewController setHiddenKeys:hideKeys animated:shouldAnimate];
  66. }
  67. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  68. {
  69. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  70. }
  71. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier
  72. {
  73. _currentUnlinkSpecifier = specifier.key;
  74. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"]) {
  75. _currentCloudName = @"Dropbox";
  76. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_DROPBOX", nil);
  77. } else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"]) {
  78. _currentCloudName = @"Google Drive";
  79. _currentUnlinkDialogTitle = NSLocalizedString(@"SETTINGS_UNLINK_GOOGLEDRIVE", nil);
  80. }
  81. UIAlertView *alert = [[UIAlertView alloc]
  82. initWithTitle:_currentUnlinkDialogTitle
  83. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING", nil), _currentCloudName]
  84. delegate:self
  85. cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
  86. otherButtonTitles:NSLocalizedString(@"BUTTON_CLOUDUNLINKING", nil), nil];
  87. [alert show];
  88. }
  89. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  90. {
  91. if (buttonIndex == 1) {
  92. if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkDropbox"])
  93. [[DBSession sharedSession] unlinkAll];
  94. else if ([_currentUnlinkSpecifier isEqualToString:@"UnlinkGoogleDrive"])
  95. [[VLCGoogleDriveController sharedInstance] logout];
  96. _currentUnlinkSpecifier = nil;
  97. UIAlertView *alert = [[UIAlertView alloc]
  98. initWithTitle:_currentUnlinkDialogTitle
  99. message:[NSString stringWithFormat:NSLocalizedString(@"CLOUDUNLINKING_DONE", nil), _currentCloudName]
  100. delegate:self
  101. cancelButtonTitle:NSLocalizedString(@"BUTTON_DONE", nil)
  102. otherButtonTitles:nil];
  103. [alert show];
  104. [self filterCloudStorageCellsWithAnimation:YES];
  105. _currentUnlinkDialogTitle = nil;
  106. _currentCloudName = nil;
  107. }
  108. }
  109. #pragma mark - PAPasscode delegate
  110. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  111. {
  112. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  113. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  114. [defaults synchronize];
  115. [controller dismissViewControllerAnimated:YES completion:nil];
  116. }
  117. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  118. {
  119. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  120. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  121. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  122. [defaults synchronize];
  123. [controller dismissViewControllerAnimated:YES completion:nil];
  124. }
  125. @end