VLCAppDelegate.m 22.3 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCAppDelegate.m
 * VLC for iOS
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
 *          Jean-Romain Prévost <jr # 3on.fr>
 *          Luis Fernandes <zipleen # gmail.com>
 *          Carola Nitz <nitz.carola # googlemail.com>
13
 *          Tamas Timar <ttimar.vlc # gmail.com>
Tobias's avatar
Tobias committed
14
 *          Tobias Conradi <videolan # tobias-conradi.de>
15
 *          Soomin Lee <TheHungryBu # gmail.com>
16 17 18
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
Felix Paul Kühne's avatar
Felix Paul Kühne committed
19 20

#import "VLCAppDelegate.h"
Gleb Pinigin's avatar
Gleb Pinigin committed
21
#import "VLCMediaFileDiscoverer.h"
22
#import "NSString+SupportedMedia.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
23
#import "UIDevice+VLC.h"
24
#import "VLCHTTPUploaderController.h"
25
#import "VLCMigrationViewController.h"
Carola Nitz's avatar
Carola Nitz committed
26
#import <BoxSDK/BoxSDK.h>
27
#import "VLCPlaybackController.h"
28
#import "VLCPlaybackController+MediaLibrary.h"
Tobias's avatar
Tobias committed
29
#import <MediaPlayer/MediaPlayer.h>
Felix Paul Kühne's avatar
Felix Paul Kühne committed
30
#import <HockeySDK/HockeySDK.h>
Felix Paul Kühne's avatar
Felix Paul Kühne committed
31
#import "VLCActivityManager.h"
32
#import "VLCDropboxConstants.h"
33
#import "VLCDownloadViewController.h"
34
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
35
#import "VLCPlaybackNavigationController.h"
36
#import "PAPasscodeViewController.h"
37
#import "VLC_iOS-Swift.h"
38 39

NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
40

Felix Paul Kühne's avatar
Felix Paul Kühne committed
41 42
#define BETA_DISTRIBUTION 1

43 44
@interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
{
45
    BOOL _isRunningMigration;
Carola Nitz's avatar
Carola Nitz committed
46
    BOOL _isComingFromHandoff;
47
    VLCKeychainCoordinator *_keychainCoordinator;
48 49
    AppCoordinator *appCoordinator;
    UITabBarController *rootViewController;
Gleb Pinigin's avatar
Gleb Pinigin committed
50
}
51 52

@end
Felix Paul Kühne's avatar
Felix Paul Kühne committed
53 54 55

@implementation VLCAppDelegate

56 57 58 59
+ (void)initialize
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

60 61
    NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowFaceID : @(1),
                                  kVLCSettingPasscodeAllowTouchID : @(1),
Felix Paul Kühne's avatar
Felix Paul Kühne committed
62 63 64
                                  kVLCSettingContinueAudioInBackgroundKey : @(YES),
                                  kVLCSettingStretchAudio : @(NO),
                                  kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
65
                                  kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
Felix Paul Kühne's avatar
Felix Paul Kühne committed
66 67 68 69 70
                                  kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
                                  kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
                                  kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
                                  kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
                                  kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
71
                                  kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
Felix Paul Kühne's avatar
Felix Paul Kühne committed
72
                                  kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
73 74 75 76 77 78
                                  kVLCSettingVolumeGesture : @(YES),
                                  kVLCSettingPlayPauseGesture : @(YES),
                                  kVLCSettingBrightnessGesture : @(YES),
                                  kVLCSettingSeekGesture : @(YES),
                                  kVLCSettingCloseGesture : @(YES),
                                  kVLCSettingVariableJumpDuration : @(NO),
79
                                  kVLCSettingVideoFullscreenPlayback : @(YES),
80
                                  kVLCSettingContinuePlayback : @(1),
81
                                  kVLCSettingContinueAudioPlayback : @(1),
Felix Paul Kühne's avatar
Felix Paul Kühne committed
82 83 84 85 86
                                  kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
                                  kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
                                  kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
                                  kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
                                  kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
87 88
                                  kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
                                  kVLCAutomaticallyPlayNextItem : @(YES)};
89 90 91
    [defaults registerDefaults:appDefaults];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
92 93
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
94
    BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
95 96 97
    [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
                                liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
                                      delegate:nil];
98
    [hockeyManager startManager];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
99

100 101 102
    // Configure Dropbox
    [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];

103
    [VLCApperanceManager setupAppearanceWithTheme:PresentationTheme.current];
104

Felix Paul Kühne's avatar
Felix Paul Kühne committed
105 106
    // Init the HTTP Server and clean its cache
    [[VLCHTTPUploaderController sharedInstance] cleanCache];
107

Felix Paul Kühne's avatar
Felix Paul Kühne committed
108
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
109 110 111
    rootViewController = [UITabBarController new];
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
112
    // enable crash preventer
113 114 115 116
    void (^setupBlock)(void) = ^{
        void (^setupLibraryBlock)(void) = ^{
            self->appCoordinator = [[AppCoordinator alloc] initWithTabBarController:self->rootViewController];
            [self->appCoordinator start];
117 118
        };
        [self validatePasscodeIfNeededWithCompletion:setupLibraryBlock];
119

120
        BOOL spotlightEnabled = ![VLCKeychainCoordinator passcodeLockEnabled];
121
        [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
122 123
        [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];

124
        VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
125 126
        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        discoverer.directoryPath = [searchPaths firstObject];
127
        [discoverer addObserver:self];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
128
        [discoverer startDiscovering];
129 130 131
    };

    NSError *error = nil;
132 133

    if ([[MLMediaLibrary sharedMediaLibrary] libraryMigrationNeeded]){
134 135 136 137
        _isRunningMigration = YES;

        VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
        migrationController.completionHandler = ^{
138

139 140
            //migrate
            setupBlock();
141
            self->_isRunningMigration = NO;
142
            [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
143
            [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
144
        };
Felix Paul Kühne's avatar
Felix Paul Kühne committed
145

146 147
        self.window.rootViewController = migrationController;
        [self.window makeKeyAndVisible];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
148

149 150
    } else {
        if (error != nil) {
151
            APLog(@"removed persistentStore since it was corrupt");
152 153 154 155 156
            NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
            [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
        }
        setupBlock();
    }
157

158
    /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
159
    if (@available(iOS 9, *)) {
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
        if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
            UIApplicationShortcutItem *localLibraryItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalLibrary
                                                                                           localizedTitle:NSLocalizedString(@"SECTION_HEADER_LIBRARY",nil)
                                                                                        localizedSubtitle:nil
                                                                                                     icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"AllFiles"]
                                                                                                 userInfo:nil];
            UIApplicationShortcutItem *localServerItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalServers
                                                                                           localizedTitle:NSLocalizedString(@"LOCAL_NETWORK",nil)
                                                                                        localizedSubtitle:nil
                                                                                                     icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Local"]
                                                                                                 userInfo:nil];
            UIApplicationShortcutItem *openNetworkStreamItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutOpenNetworkStream
                                                                                           localizedTitle:NSLocalizedString(@"OPEN_NETWORK",nil)
                                                                                        localizedSubtitle:nil
                                                                                                     icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"OpenNetStream"]
                                                                                                 userInfo:nil];
            UIApplicationShortcutItem *cloudsItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutClouds
                                                                                           localizedTitle:NSLocalizedString(@"CLOUD_SERVICES",nil)
                                                                                        localizedSubtitle:nil
                                                                                                     icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"iCloudIcon"]
                                                                                                 userInfo:nil];
            application.shortcutItems = @[localLibraryItem, localServerItem, openNetworkStreamItem, cloudsItem];
        }
    }

185 186
    return YES;
}
187

Carola Nitz's avatar
Carola Nitz committed
188 189
#pragma mark - Handoff

190 191
- (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
{
192 193 194
    if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
        [userActivityType isEqualToString:kVLCUserActivityPlaying] ||
        [userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
Carola Nitz's avatar
Carola Nitz committed
195
        return YES;
196

Carola Nitz's avatar
Carola Nitz committed
197 198 199
    return NO;
}

200 201 202 203 204
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray *))restorationHandler
{
    NSString *userActivityType = userActivity.activityType;
205 206 207
    NSDictionary *dict = userActivity.userInfo;
    if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
       [userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
208
        //TODO: Add restoreUserActivityState to the mediaviewcontroller
Carola Nitz's avatar
Carola Nitz committed
209
        _isComingFromHandoff = YES;
Carola Nitz's avatar
Carola Nitz committed
210
        return YES;
211
    } else {
Tobias's avatar
Tobias committed
212 213 214 215 216 217 218 219 220 221 222
        NSURL *uriRepresentation = nil;
        if ([userActivityType isEqualToString:CSSearchableItemActionType]) {
            uriRepresentation = [NSURL URLWithString:dict[CSSearchableItemActivityIdentifier]];
        } else {
            uriRepresentation = dict[@"playingmedia"];
        }

        if (!uriRepresentation) {
            return NO;
        }

223 224 225 226 227 228 229
        NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
        if (managedObject == nil) {
            APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
            return NO;
        }
        [[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
        return YES;
Carola Nitz's avatar
Carola Nitz committed
230 231 232 233
    }
    return NO;
}

234 235 236
- (void)application:(UIApplication *)application
didFailToContinueUserActivityWithType:(NSString *)userActivityType
              error:(NSError *)error
Carola Nitz's avatar
Carola Nitz committed
237 238 239 240 241 242
{
    if (error.code != NSUserCancelledError){
        //TODO: present alert
    }
}

Carola Nitz's avatar
Carola Nitz committed
243
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
244
{
245 246 247 248 249 250
    //Handles Dropbox Authorization flow.
    DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
    if (authResult != nil) {
        if ([authResult isSuccess]) {
            return YES;
        }
251
    }
252

253 254 255 256 257 258
    //Handles Google Authorization flow.
    if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
        _currentGoogleAuthorizationFlow = nil;
        return YES;
    }

259 260 261 262 263 264 265 266
    //TODO: we need a model of URLHandlers that registers with the VLCAppdelegate
    // then we can go through the list of handlers ask if they can handle the url and the first to say yes handles the call.
    // that way internal if elses get encapsulated
    /*
    protocol VLCURLHandler {
        func canHandleOpen(url: URL, options:[UIApplicationOpenURLOptionsKey:AnyObject]=[:]()) -> bool
        func performOpen(url: URL, options:[UIApplicationOpenURLOptionsKey:AnyObject]=[:]()) -> bool
    } */
267

268
//    if (_libraryViewController && url != nil) {
269
//        APLog(@"requested %@ to be opened", url);
270 271
//
//        if (url.isFileURL) {
272 273 274 275 276 277
//            VLCDocumentClass *subclass = [[VLCDocumentClass alloc] initWithFileURL:url];
//            [subclass openWithCompletionHandler:^(BOOL success) {
//                [self playWithURL:url completion:^(BOOL success) {
//                    [subclass closeWithCompletionHandler:nil];
//                }];
//            }];
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
//        } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
//            // URL confirmes to the x-callback-url specification
//            // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
//            APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
//            NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
//            NSURL *movieURL;
//            NSURL *successCallback;
//            NSURL *errorCallback;
//            NSString *fileName;
//            for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
//                NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
//                if (keyvalue.count < 2) continue;
//                NSString *key = keyvalue[0];
//                NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//
//                if ([key isEqualToString:@"url"])
//                    movieURL = [NSURL URLWithString:value];
//                else if ([key isEqualToString:@"filename"])
//                    fileName = value;
//                else if ([key isEqualToString:@"x-success"])
//                    successCallback = [NSURL URLWithString:value];
//                else if ([key isEqualToString:@"x-error"])
//                    errorCallback = [NSURL URLWithString:value];
//            }
//            if ([action isEqualToString:@"stream"] && movieURL) {
303 304 305 306 307 308 309 310 311 312 313 314
//                [self playWithURL:movieURL completion:^(BOOL success) {
//                    NSURL *callback = success ? successCallback : errorCallback;
//                    if (@available(iOS 10, *)) {
//                         [[UIApplication sharedApplication] openURL:callback options:@{} completionHandler:nil];
//                    } else {
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wdeprecated-declarations"
//                        /* UIApplication's replacement calls require iOS 10 or later, which we can't enforce as of yet */
//                       [[UIApplication sharedApplication] openURL:callback];
//#pragma clang diagnostic pop
//                    }
//                }];
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
//            }
//            else if ([action isEqualToString:@"download"] && movieURL) {
//                [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
//            }
//        } else {
//            NSString *receivedUrl = [url absoluteString];
//            if ([receivedUrl length] > 6) {
//                NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
//                if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
//                    NSString *parsedString = [receivedUrl substringFromIndex:6];
//                    NSUInteger location = [parsedString rangeOfString:@"//"].location;
//
//                    /* Safari & al mangle vlc://http:// so fix this */
//                    if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
//                            parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
//                    } else {
//                        parsedString = [receivedUrl substringFromIndex:6];
//                        if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
//                            parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
//                        }
//                    }
//                    url = [NSURL URLWithString:parsedString];
//                }
//            }
//            [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
//                                                         scrollPosition:UITableViewScrollPositionNone];
//
//            NSString *scheme = url.scheme;
//            if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
//                VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
//                alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
//                    if (cancelled)
//                        [self downloadMovieFromURL:url fileNameOfMedia:nil];
//                    else {
349
//                        [self playWithURL:url completion:nil];
350 351 352 353
//                    }
//                };
//                [alert show];
//            } else {
354
//                [self playWithURL:url completion:nil];
355 356 357 358
//            }
//        }
//        return YES;
//    }
359 360 361
    return NO;
}

362 363 364 365 366
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
367 368
- (void)applicationWillResignActive:(UIApplication *)application
{
369 370 371 372 373 374 375 376
    //Touch ID is shown 
    if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
        UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
        if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
            return;
        }
    }
    [self validatePasscodeIfNeededWithCompletion:^{
377
        //TODO: handle updating the videoview and
378
        if ([VLCPlaybackController sharedInstance].isPlaying){
379
            //TODO: push playback
380 381
        }
    }];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
382 383 384 385 386
    [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
Carola Nitz's avatar
Carola Nitz committed
387
    if (!_isRunningMigration && !_isComingFromHandoff) {
388
        [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
389 390
      //  [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
        [[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
Carola Nitz's avatar
Carola Nitz committed
391 392
    } else if(_isComingFromHandoff) {
        _isComingFromHandoff = NO;
393
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
394 395
}

396 397
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
398
    //TODO: shortcutItem should be implemented
399 400
}

Gleb Pinigin's avatar
Gleb Pinigin committed
401
#pragma mark - media discovering
402

403 404
- (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
{
Gleb Pinigin's avatar
Gleb Pinigin committed
405 406 407
    if (!isLoading) {
        MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
        [sharedLibrary addFilePaths:@[fileName]];
408

Gleb Pinigin's avatar
Gleb Pinigin committed
409 410 411
        /* exclude media files from backup (QA1719) */
        NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
        [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
412

Gleb Pinigin's avatar
Gleb Pinigin committed
413 414
        // TODO Should we update media db after adding new files?
        [sharedLibrary updateMediaDatabase];
415
        // TODO: update the VideoViewController
416 417 418
    }
}

419 420
- (void)mediaFileDeleted:(NSString *)name
{
Gleb Pinigin's avatar
Gleb Pinigin committed
421
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
422
   // TODO: update the VideoViewController
Gleb Pinigin's avatar
Gleb Pinigin committed
423 424
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
425
- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
426 427
{
    [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
428
  // TODO: update the VideoViewController
429 430
}

431
#pragma mark - pass code validation
432 433 434 435 436 437 438
- (VLCKeychainCoordinator *)keychainCoordinator
{
    if (!_keychainCoordinator) {
        _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
    }
    return _keychainCoordinator;
}
439

440
- (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
441
{
442
    if ([VLCKeychainCoordinator passcodeLockEnabled]) {
443
        //TODO: Dimiss playback
444
        [self.keychainCoordinator validatePasscodeWithCompletion:completion];
445
    } else {
446
        completion();
447
    }
448 449
}

450 451 452 453 454
#pragma mark - download handling

- (void)downloadMovieFromURL:(NSURL *)url
             fileNameOfMedia:(NSString *)fileName
{
455
    [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
456
    //TODO: open DownloadViewController
457 458
}

Carola Nitz's avatar
Carola Nitz committed
459
#pragma mark - playback
460
- (void)playWithURL:(NSURL *)url completion:(void (^ __nullable)(BOOL success))completion
Carola Nitz's avatar
Carola Nitz committed
461 462 463 464
{
    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
    vpc.fullscreenSessionRequested = YES;
    VLCMediaList *mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
465
    [vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil completion:completion];
Carola Nitz's avatar
Carola Nitz committed
466 467
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
468
@end