Commit a2249ce1 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

move VLCPlaybackController configuration code for MediaLibrary object to...

move VLCPlaybackController configuration code for MediaLibrary object to category on VLCPlaybackController reduce duplicated code in VLCPlaylistViewController
parent 88914707
......@@ -36,7 +36,6 @@
- (void)presentMovieViewController;
- (void)openMediaFromManagedObject:(NSManagedObject *)file;
- (void)openMovieFromURL:(NSURL *)url;
- (void)openMediaList:(VLCMediaList*)list atIndex:(int)index;
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath;
@property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController;
......
......@@ -33,6 +33,7 @@
#import "VLCPlaybackController.h"
#import "VLCNavigationController.h"
#import "VLCWatchMessage.h"
#import "VLCPlaybackController+MediaLibrary.h"
#define HAVE_FABRIC 0
......@@ -573,15 +574,8 @@ continueUserActivity:(NSUserActivity *)userActivity
if (vpc.presentingMovieViewController)
retainFullscreenPlayback = YES;
if ([mediaObject isKindOfClass:[MLFile class]])
vpc.fileFromMediaLibrary = (MLFile *)mediaObject;
else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])
vpc.fileFromMediaLibrary = [(MLAlbumTrack*)mediaObject files].anyObject;
else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
vpc.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
[(MLFile *)vpc.fileFromMediaLibrary setUnread:@(NO)];
[vpc playMediaLibraryObject:mediaObject];
[vpc startPlayback];
if (retainFullscreenPlayback)
[self presentMovieViewController];
}
......@@ -590,7 +584,6 @@ continueUserActivity:(NSUserActivity *)userActivity
successCallback:(NSURL *)successCallback
errorCallback:(NSURL *)errorCallback
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.url = url;
......@@ -605,17 +598,6 @@ continueUserActivity:(NSUserActivity *)userActivity
[self openMovieFromURL:url successCallback:nil errorCallback:nil];
}
- (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.mediaList = list;
vpc.itemInMediaListToBePlayedFirst = index;
vpc.pathToExternalSubtitlesFile = nil;
[vpc startPlayback];
}
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
......
/*****************************************************************************
* VLCPlaybackController+MediaLibrary.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCPlaybackController.h"
@class NSManagedObject;
@interface VLCPlaybackController (MediaLibrary)
- (void)playMediaLibraryObject:(NSManagedObject *)mediaObject;
@end
/*****************************************************************************
* VLCPlaybackController+MediaLibrary.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCPlaybackController+MediaLibrary.h"
#import <MediaLibraryKit/MediaLibraryKit.h>
#import <CoreData/CoreData.h>
@implementation VLCPlaybackController (MediaLibrary)
- (void)playMediaLibraryObject:(NSManagedObject *)mediaObject
{
if ([mediaObject isKindOfClass:[MLFile class]]) {
[self configureWithFile:(MLFile *)mediaObject];
}
else if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
[self configureWithAlbumTrack:(MLAlbumTrack *)mediaObject];
}
else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
[self configureWithSingleFile:[(MLShowEpisode*)mediaObject files].anyObject];
[self startPlayback];
}
- (void)configureWithFile:(MLFile *)file
{
if (file.labels.count == 0) {
[self configureWithSingleFile:file];
} else {
MLLabel *folder = [file.labels anyObject];
NSArray *files = [folder sortedFolderItems];
int index = (int)[files indexOfObject:file];
[self configureMediaListWithFiles:files indexToPlay:index];
}
}
- (void)configureWithSingleFile:(MLFile *)file
{
[file setUnread:@(NO)];
self.fileFromMediaLibrary = file;
}
- (void)configureWithAlbumTrack:(MLAlbumTrack *)albumTrack
{
NSArray *tracks = [[albumTrack album] sortedTracks];
NSMutableArray *files = [NSMutableArray arrayWithCapacity:tracks.count];
for (MLAlbumTrack *track in tracks) {
MLFile *file = track.files.anyObject;
[files addObject:file];
}
int index = (int)[tracks indexOfObject:albumTrack];
[self configureMediaListWithFiles:files indexToPlay:index];
}
- (void)configureMediaListWithFiles:(NSArray *)files indexToPlay:(int)index
{
VLCMediaList *list = [[VLCMediaList alloc] init];
for (MLFile *file in files.reverseObjectEnumerator) {
[list addMedia:[VLCMedia mediaWithURL:file.url]];
}
[self configureMediaList:list atIndex:index];
}
- (void)configureMediaList:(VLCMediaList *)list atIndex:(int)index
{
self.mediaList = list;
self.itemInMediaListToBePlayedFirst = index;
self.pathToExternalSubtitlesFile = nil;
}
@end
......@@ -58,9 +58,6 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
LXReorderableCollectionViewFlowLayout *_reorderLayout;
BOOL inFolder;
UILongPressGestureRecognizer *_longPressGestureRecognizer;
NSInteger _mediaToPlayIndex;
VLCMediaList *_list;
NSArray *_tracks;
NSMutableArray *_searchData;
UISearchBar *_searchBar;
......@@ -712,46 +709,10 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
else
selectedObject = _foundMedia[indexPath.row];
if ([selectedObject isKindOfClass:[MLAlbumTrack class]]) {
_tracks = [[(MLAlbumTrack*)selectedObject album] sortedTracks];
NSUInteger count = _tracks.count;
_list = [[VLCMediaList alloc] init];
_list.delegate = self;
MLFile *file;
VLCMedia *media;
for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)_tracks[x] files].anyObject;
media = [VLCMedia mediaWithURL:file.url];
[media parse];
[_list addMedia:media];
}
_mediaToPlayIndex = indexPath.row;
} else if ([selectedObject isKindOfClass:[MLFile class]] && [((MLFile *)selectedObject).labels count] > 0) {
MLLabel *folder = [((MLFile *)selectedObject).labels anyObject];
_tracks = [folder sortedFolderItems];
NSUInteger count = _tracks.count;
_list = [[VLCMediaList alloc] init];
_list.delegate = self;
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = (MLFile *)_tracks[x];
[_list addMedia:[VLCMedia mediaWithURL:file.url]];
}
_mediaToPlayIndex = indexPath.row;
} else {
if (_searchDisplayController.active == YES)
[_searchDisplayController setActive:NO animated:NO];
[self openMediaObject:selectedObject];
}
}
if (_searchDisplayController.active == YES)
[_searchDisplayController setActive:NO animated:NO];
#pragma mark - VLCMedialistDelegate
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
{
if (index == _tracks.count - 1) {
NSManagedObject *selectedObject = _foundMedia[_mediaToPlayIndex];
[(VLCAppDelegate *)[UIApplication sharedApplication].delegate openMediaList:_list atIndex:(int)[_tracks indexOfObject:selectedObject]];
}
[self openMediaObject:selectedObject];
}
#pragma mark - Gesture Action
......@@ -869,33 +830,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
}
NSManagedObject *selectedObject = _foundMedia[indexPath.row];
if ([selectedObject isKindOfClass:[MLAlbumTrack class]]) {
VLCMediaList *list;
NSArray *tracks = [[(MLAlbumTrack*)selectedObject album] sortedTracks];
NSUInteger count = tracks.count;
list = [[VLCMediaList alloc] init];
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)tracks[x] files].anyObject;
[list addMedia:[VLCMedia mediaWithURL:file.url]];
}
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[tracks indexOfObject:selectedObject]];
} else if ([selectedObject isKindOfClass:[MLFile class]] && [((MLFile *)selectedObject).labels count] > 0) {
VLCMediaList *list;
MLLabel *folder = [((MLFile *)selectedObject).labels anyObject];
NSArray *folderTracks = [folder sortedFolderItems];
NSUInteger count = folderTracks.count;
list = [[VLCMediaList alloc] init];
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = (MLFile *)folderTracks[x];
[list addMedia:[VLCMedia mediaWithURL:file.url]];
}
[(VLCAppDelegate *)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[folderTracks indexOfObject:selectedObject]];
} else
[self openMediaObject:selectedObject];
[self openMediaObject:selectedObject];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
......
......@@ -562,6 +562,7 @@
DD7110F01AF38B2B00854776 /* MLMediaLibrary+playlist.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */; };
DD7110F11AF38B2B00854776 /* MLMediaLibrary+playlist.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */; };
DD7635D61AF262D100240CB8 /* NSManagedObjectContext+refreshAll.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7635D51AF262D100240CB8 /* NSManagedObjectContext+refreshAll.m */; };
DD8F84311B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8F84301B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m */; };
DDACEB561ADAD11300735484 /* WKInterfaceObject+VLCProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */; };
DDB959401AFBB2F600BB8CFF /* MediaLibrary.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DDB9593C1AFBB2F600BB8CFF /* MediaLibrary.xcdatamodeld */; };
DDB959421AFBB30500BB8CFF /* MappingModel_2_5_to_2_5_2.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = DDB959411AFBB30500BB8CFF /* MappingModel_2_5_to_2_5_2.xcmappingmodel */; };
......@@ -1637,6 +1638,8 @@
DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MLMediaLibrary+playlist.m"; sourceTree = "<group>"; };
DD7635D41AF262D100240CB8 /* NSManagedObjectContext+refreshAll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObjectContext+refreshAll.h"; sourceTree = "<group>"; };
DD7635D51AF262D100240CB8 /* NSManagedObjectContext+refreshAll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObjectContext+refreshAll.m"; sourceTree = "<group>"; };
DD8F842F1B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "VLCPlaybackController+MediaLibrary.h"; path = "Sources/VLCPlaybackController+MediaLibrary.h"; sourceTree = SOURCE_ROOT; };
DD8F84301B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "VLCPlaybackController+MediaLibrary.m"; path = "Sources/VLCPlaybackController+MediaLibrary.m"; sourceTree = SOURCE_ROOT; };
DDACEB541ADAD11300735484 /* WKInterfaceObject+VLCProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKInterfaceObject+VLCProgress.h"; sourceTree = "<group>"; };
DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WKInterfaceObject+VLCProgress.m"; sourceTree = "<group>"; };
DDB9593D1AFBB2F600BB8CFF /* MediaLibrary-2.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MediaLibrary-2.1.xcdatamodel"; sourceTree = "<group>"; };
......@@ -2309,6 +2312,8 @@
children = (
7DE56C181AD93F9100E8CA00 /* VLCPlaybackController.h */,
7DE56C191AD93F9100E8CA00 /* VLCPlaybackController.m */,
DD8F842F1B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.h */,
DD8F84301B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m */,
7D37848D183A98B6009EE944 /* VLCMovieViewController.h */,
7D37848E183A98B6009EE944 /* VLCMovieViewController.m */,
7D9561091AF3E9E800779745 /* VLCMiniPlaybackView.h */,
......@@ -3748,6 +3753,7 @@
7D37848F183A98B6009EE944 /* VLCMovieViewController.m in Sources */,
7D378492183A98BF009EE944 /* VLCExternalDisplayController.m in Sources */,
7D378499183A98D1009EE944 /* VLCPlaylistCollectionViewCell.m in Sources */,
DD8F84311B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m in Sources */,
7D37849A183A98D1009EE944 /* VLCPlaylistTableViewCell.m in Sources */,
7D37849B183A98D1009EE944 /* VLCPlaylistViewController.m in Sources */,
7D37849E183A98DD009EE944 /* VLCThumbnailsCache.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment