VLCAppDelegate.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*****************************************************************************
  2. * VLCAppDelegate.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Jean-Romain Prévost <jr # 3on.fr>
  11. * Luis Fernandes <zipleen # gmail.com>
  12. * Carola Nitz <nitz.carola # googlemail.com>
  13. * Tamas Timar <ttimar.vlc # gmail.com>
  14. * Tobias Conradi <videolan # tobias-conradi.de>
  15. * Soomin Lee <TheHungryBu # gmail.com>
  16. *
  17. * Refer to the COPYING file of the official project for license.
  18. *****************************************************************************/
  19. #import "VLCAppDelegate.h"
  20. #import "VLCMediaFileDiscoverer.h"
  21. #import "NSString+SupportedMedia.h"
  22. #import "UIDevice+VLC.h"
  23. #import "VLCLibraryViewController.h"
  24. #import "VLCHTTPUploaderController.h"
  25. #import "VLCMigrationViewController.h"
  26. #import <BoxSDK/BoxSDK.h>
  27. #import "VLCPlaybackController.h"
  28. #import "VLCPlaybackController+MediaLibrary.h"
  29. #import "VLCPlayerDisplayController.h"
  30. #import <MediaPlayer/MediaPlayer.h>
  31. #import <HockeySDK/HockeySDK.h>
  32. #import "VLCSidebarController.h"
  33. #import "VLCKeychainCoordinator.h"
  34. #import "VLCActivityManager.h"
  35. #import "VLCDropboxConstants.h"
  36. #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
  37. NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
  38. #define BETA_DISTRIBUTION 1
  39. @interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
  40. {
  41. BOOL _passcodeValidated;
  42. BOOL _isRunningMigration;
  43. BOOL _isComingFromHandoff;
  44. VLCWatchCommunication *_watchCommunication;
  45. }
  46. @end
  47. @implementation VLCAppDelegate
  48. + (void)initialize
  49. {
  50. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  51. NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowTouchID : @(1),
  52. kVLCSettingContinueAudioInBackgroundKey : @(YES),
  53. kVLCSettingStretchAudio : @(NO),
  54. kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
  55. kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
  56. kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
  57. kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
  58. kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
  59. kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
  60. kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
  61. kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
  62. kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
  63. kVLCSettingVolumeGesture : @(YES),
  64. kVLCSettingPlayPauseGesture : @(YES),
  65. kVLCSettingBrightnessGesture : @(YES),
  66. kVLCSettingSeekGesture : @(YES),
  67. kVLCSettingCloseGesture : @(YES),
  68. kVLCSettingVariableJumpDuration : @(NO),
  69. kVLCSettingVideoFullscreenPlayback : @(YES),
  70. kVLCSettingContinuePlayback : @(1),
  71. kVLCSettingContinueAudioPlayback : @(1),
  72. kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
  73. kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
  74. kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
  75. kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
  76. kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
  77. kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
  78. kVLCAutomaticallyPlayNextItem : @(YES)};
  79. [defaults registerDefaults:appDefaults];
  80. }
  81. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  82. {
  83. BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
  84. [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
  85. liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
  86. delegate:nil];
  87. // Configure Dropbox
  88. [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
  89. // Configure the SDK in here only!
  90. [hockeyManager startManager];
  91. [hockeyManager.authenticator authenticateInstallation];
  92. /* listen to validation notification */
  93. [[NSNotificationCenter defaultCenter] addObserver:self
  94. selector:@selector(passcodeWasValidated:)
  95. name:VLCPasscodeValidated
  96. object:nil];
  97. [self setupAppearence];
  98. // Init the HTTP Server and clean its cache
  99. [[VLCHTTPUploaderController sharedInstance] cleanCache];
  100. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  101. // enable crash preventer
  102. void (^setupBlock)() = ^{
  103. _libraryViewController = [[VLCLibraryViewController alloc] init];
  104. VLCSidebarController *sidebarVC = [VLCSidebarController sharedInstance];
  105. VLCNavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:_libraryViewController];
  106. sidebarVC.contentViewController = navCon;
  107. VLCPlayerDisplayController *playerDisplayController = [VLCPlayerDisplayController sharedInstance];
  108. playerDisplayController.childViewController = sidebarVC.fullViewController;
  109. self.window.rootViewController = playerDisplayController;
  110. [self.window makeKeyAndVisible];
  111. [self validatePasscode];
  112. BOOL spotlightEnabled = ![[VLCKeychainCoordinator defaultCoordinator] passcodeLockEnabled];
  113. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  114. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  115. VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
  116. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  117. discoverer.directoryPath = [searchPaths firstObject];
  118. [discoverer addObserver:self];
  119. [discoverer startDiscovering];
  120. };
  121. NSError *error = nil;
  122. if ([[MLMediaLibrary sharedMediaLibrary] libraryMigrationNeeded]){
  123. _isRunningMigration = YES;
  124. VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
  125. migrationController.completionHandler = ^{
  126. //migrate
  127. setupBlock();
  128. _isRunningMigration = NO;
  129. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  130. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  131. };
  132. self.window.rootViewController = migrationController;
  133. [self.window makeKeyAndVisible];
  134. } else {
  135. if (error != nil) {
  136. APLog(@"removed persistentStore since it was corrupt");
  137. NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
  138. [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
  139. }
  140. setupBlock();
  141. }
  142. if ([VLCWatchCommunication isSupported]) {
  143. _watchCommunication = [VLCWatchCommunication sharedInstance];
  144. // TODO: push DB changes instead
  145. // [_watchCommunication startRelayingNotificationName:NSManagedObjectContextDidSaveNotification object:nil];
  146. [_watchCommunication startRelayingNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:nil];
  147. }
  148. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  149. if ([UIApplicationShortcutItem class] != nil) {
  150. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  151. UIApplicationShortcutItem *localLibraryItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalLibrary
  152. localizedTitle:NSLocalizedString(@"SECTION_HEADER_LIBRARY",nil)
  153. localizedSubtitle:nil
  154. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"AllFiles"]
  155. userInfo:nil];
  156. UIApplicationShortcutItem *localServerItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalServers
  157. localizedTitle:NSLocalizedString(@"LOCAL_NETWORK",nil)
  158. localizedSubtitle:nil
  159. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Local"]
  160. userInfo:nil];
  161. UIApplicationShortcutItem *openNetworkStreamItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutOpenNetworkStream
  162. localizedTitle:NSLocalizedString(@"OPEN_NETWORK",nil)
  163. localizedSubtitle:nil
  164. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"OpenNetStream"]
  165. userInfo:nil];
  166. UIApplicationShortcutItem *cloudsItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutClouds
  167. localizedTitle:NSLocalizedString(@"CLOUD_SERVICES",nil)
  168. localizedSubtitle:nil
  169. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"iCloudIcon"]
  170. userInfo:nil];
  171. application.shortcutItems = @[localLibraryItem, localServerItem, openNetworkStreamItem, cloudsItem];
  172. }
  173. }
  174. return YES;
  175. }
  176. - (void)setupAppearence
  177. {
  178. UIColor *vlcOrange = [UIColor VLCOrangeTintColor];
  179. // Change the keyboard for UISearchBar
  180. [[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
  181. // For the cursor
  182. [[UITextField appearance] setTintColor:vlcOrange];
  183. // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
  184. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitleTextAttributes:@{[UIColor whiteColor] : NSForegroundColorAttributeName} forState:UIControlStateNormal];
  185. // For the edit selection indicators
  186. [[UITableView appearance] setTintColor:vlcOrange];
  187. [[UISwitch appearance] setOnTintColor:vlcOrange];
  188. [[UISearchBar appearance] setBarTintColor:vlcOrange];
  189. }
  190. - (void)dealloc
  191. {
  192. [[NSNotificationCenter defaultCenter] removeObserver:self];
  193. }
  194. #pragma mark - Handoff
  195. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  196. {
  197. if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  198. [userActivityType isEqualToString:kVLCUserActivityPlaying] ||
  199. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
  200. return YES;
  201. return NO;
  202. }
  203. - (BOOL)application:(UIApplication *)application
  204. continueUserActivity:(NSUserActivity *)userActivity
  205. restorationHandler:(void (^)(NSArray *))restorationHandler
  206. {
  207. NSString *userActivityType = userActivity.activityType;
  208. NSDictionary *dict = userActivity.userInfo;
  209. if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  210. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
  211. VLCLibraryMode libraryMode = (VLCLibraryMode)[(NSNumber *)dict[@"state"] integerValue];
  212. if (libraryMode <= VLCLibraryModeAllSeries) {
  213. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:libraryMode inSection:0]
  214. scrollPosition:UITableViewScrollPositionTop];
  215. [self.libraryViewController setLibraryMode:libraryMode];
  216. }
  217. [self.libraryViewController restoreUserActivityState:userActivity];
  218. _isComingFromHandoff = YES;
  219. return YES;
  220. } else {
  221. NSURL *uriRepresentation = nil;
  222. if ([userActivityType isEqualToString:CSSearchableItemActionType]) {
  223. uriRepresentation = [NSURL URLWithString:dict[CSSearchableItemActivityIdentifier]];
  224. } else {
  225. uriRepresentation = dict[@"playingmedia"];
  226. }
  227. if (!uriRepresentation) {
  228. return NO;
  229. }
  230. NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
  231. if (managedObject == nil) {
  232. APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
  233. return NO;
  234. }
  235. [[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
  236. return YES;
  237. }
  238. return NO;
  239. }
  240. - (void)application:(UIApplication *)application
  241. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  242. error:(NSError *)error
  243. {
  244. if (error.code != NSUserCancelledError){
  245. //TODO: present alert
  246. }
  247. }
  248. - (BOOL)application:(UIApplication *)application
  249. openURL:(NSURL *)url
  250. sourceApplication:(NSString *)sourceApplication
  251. annotation:(id)annotation
  252. {
  253. //Handles Dropbox Authorization flow.
  254. DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
  255. if (authResult != nil) {
  256. if ([authResult isSuccess]) {
  257. return YES;
  258. }
  259. }
  260. //Handles Google Authorization flow.
  261. if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
  262. _currentGoogleAuthorizationFlow = nil;
  263. return YES;
  264. }
  265. if (_libraryViewController && url != nil) {
  266. APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  267. if (url.isFileURL) {
  268. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  269. NSString *directoryPath = searchPaths[0];
  270. NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
  271. NSError *theError;
  272. [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
  273. if (theError.code != noErr)
  274. APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
  275. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  276. } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
  277. // URL confirmes to the x-callback-url specification
  278. // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
  279. APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
  280. NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
  281. NSURL *movieURL;
  282. NSURL *successCallback;
  283. NSURL *errorCallback;
  284. NSString *fileName;
  285. for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
  286. NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
  287. if (keyvalue.count < 2) continue;
  288. NSString *key = keyvalue[0];
  289. NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  290. if ([key isEqualToString:@"url"])
  291. movieURL = [NSURL URLWithString:value];
  292. else if ([key isEqualToString:@"filename"])
  293. fileName = value;
  294. else if ([key isEqualToString:@"x-success"])
  295. successCallback = [NSURL URLWithString:value];
  296. else if ([key isEqualToString:@"x-error"])
  297. errorCallback = [NSURL URLWithString:value];
  298. }
  299. if ([action isEqualToString:@"stream"] && movieURL) {
  300. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  301. vpc.fullscreenSessionRequested = YES;
  302. VLCMediaList *medialist = [[VLCMediaList alloc] init];
  303. [medialist addMedia:[VLCMedia mediaWithURL:movieURL]];
  304. vpc.successCallback = successCallback;
  305. vpc.errorCallback = errorCallback;
  306. [vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  307. }
  308. else if ([action isEqualToString:@"download"] && movieURL) {
  309. [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
  310. }
  311. } else {
  312. NSString *receivedUrl = [url absoluteString];
  313. if ([receivedUrl length] > 6) {
  314. NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
  315. if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
  316. NSString *parsedString = [receivedUrl substringFromIndex:6];
  317. NSUInteger location = [parsedString rangeOfString:@"//"].location;
  318. /* Safari & al mangle vlc://http:// so fix this */
  319. if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
  320. parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
  321. } else {
  322. parsedString = [receivedUrl substringFromIndex:6];
  323. if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
  324. parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
  325. }
  326. }
  327. url = [NSURL URLWithString:parsedString];
  328. }
  329. }
  330. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
  331. scrollPosition:UITableViewScrollPositionNone];
  332. NSString *scheme = url.scheme;
  333. if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
  334. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
  335. alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  336. if (cancelled)
  337. [self downloadMovieFromURL:url fileNameOfMedia:nil];
  338. else {
  339. VLCMedia *media = [VLCMedia mediaWithURL:url];
  340. VLCMediaList *medialist = [[VLCMediaList alloc] init];
  341. [medialist addMedia:media];
  342. [[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  343. }
  344. };
  345. [alert show];
  346. } else {
  347. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  348. vpc.fullscreenSessionRequested = YES;
  349. VLCMediaList *medialist = [[VLCMediaList alloc] init];
  350. [medialist addMedia:[VLCMedia mediaWithURL:url]];
  351. [vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
  352. }
  353. }
  354. return YES;
  355. }
  356. return NO;
  357. }
  358. - (void)applicationWillEnterForeground:(UIApplication *)application
  359. {
  360. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  361. }
  362. - (void)applicationWillResignActive:(UIApplication *)application
  363. {
  364. _passcodeValidated = NO;
  365. [self validatePasscode];
  366. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  367. }
  368. - (void)applicationDidBecomeActive:(UIApplication *)application
  369. {
  370. if (!_isRunningMigration && !_isComingFromHandoff) {
  371. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  372. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  373. } else if(_isComingFromHandoff) {
  374. _isComingFromHandoff = NO;
  375. }
  376. }
  377. - (void)applicationWillTerminate:(UIApplication *)application
  378. {
  379. _passcodeValidated = NO;
  380. [[NSUserDefaults standardUserDefaults] synchronize];
  381. }
  382. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  383. {
  384. [[VLCSidebarController sharedInstance] performActionForShortcutItem:shortcutItem];
  385. }
  386. #pragma mark - media discovering
  387. - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
  388. {
  389. if (!isLoading) {
  390. MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
  391. [sharedLibrary addFilePaths:@[fileName]];
  392. /* exclude media files from backup (QA1719) */
  393. NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
  394. [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  395. // TODO Should we update media db after adding new files?
  396. [sharedLibrary updateMediaDatabase];
  397. [_libraryViewController updateViewContents];
  398. }
  399. }
  400. - (void)mediaFileDeleted:(NSString *)name
  401. {
  402. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  403. [_libraryViewController updateViewContents];
  404. }
  405. - (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
  406. {
  407. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
  408. [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate libraryViewController] updateViewContents];
  409. }
  410. #pragma mark - pass code validation
  411. - (void)passcodeWasValidated:(NSNotification *)aNotifcation
  412. {
  413. _passcodeValidated = YES;
  414. [self.libraryViewController updateViewContents];
  415. if ([VLCPlaybackController sharedInstance].isPlaying)
  416. [[VLCPlayerDisplayController sharedInstance] pushPlaybackView];
  417. }
  418. - (BOOL)passcodeValidated
  419. {
  420. return _passcodeValidated;
  421. }
  422. - (void)validatePasscode
  423. {
  424. VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
  425. if (!_passcodeValidated && [keychainCoordinator passcodeLockEnabled]) {
  426. [[VLCPlayerDisplayController sharedInstance] dismissPlaybackView];
  427. [keychainCoordinator validatePasscode];
  428. } else {
  429. _passcodeValidated = YES;
  430. [self passcodeValidated];
  431. }
  432. }
  433. #pragma mark - download handling
  434. - (void)downloadMovieFromURL:(NSURL *)url
  435. fileNameOfMedia:(NSString *)fileName
  436. {
  437. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
  438. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1]
  439. scrollPosition:UITableViewScrollPositionNone];
  440. }
  441. #pragma mark - watch stuff
  442. - (void)application:(UIApplication *)application
  443. handleWatchKitExtensionRequest:(NSDictionary *)userInfo
  444. reply:(void (^)(NSDictionary *))reply
  445. {
  446. if ([VLCWatchCommunication isSupported]) {
  447. [self.watchCommunication session:[WCSession defaultSession] didReceiveMessage:userInfo replyHandler:reply];
  448. }
  449. }
  450. @end