Browse Source

move playlist array logic from VLCPlaylistInterfaceController to MLMediaLibrary category which eventually can be uses by both the iOS and Watch App

Tobias Conradi 10 years ago
parent
commit
ce80f39030

+ 29 - 0
SharedSources/MLMediaLibrary+playlist.h

@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * MLMediaLibrary+playlist.h
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Authors: Tobias Conradi <videolan # tobias-conradi.de>
+ *          Carola Nitz <caro # videolan.org>
+ *          Felix Paul Kühne <fkuehne # videolan.org>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import <MediaLibraryKit/MLMediaLibrary.h>
+
+typedef NS_ENUM(NSUInteger, VLCLibraryMode) {
+    VLCLibraryModeNone = 0,
+    VLCLibraryModeAllFiles,
+    VLCLibraryModeAllAlbums,
+    VLCLibraryModeAllSeries,
+};
+
+@interface MLMediaLibrary (playlist)
+
+- (NSArray *)playlistArrayForGroupObject:(id)groupObject;
+- (NSArray *)playlistArrayForLibraryMode:(VLCLibraryMode)libraryMode;
+
+@end

+ 96 - 0
SharedSources/MLMediaLibrary+playlist.m

@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * MLMediaLibrary+playlist.m
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Authors: Tobias Conradi <videolan # tobias-conradi.de>
+ *          Carola Nitz <caro # videolan.org>
+ *          Felix Paul Kühne <fkuehne # videolan.org>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import "MLMediaLibrary+playlist.h"
+#import <UIKit/UIKit.h>
+#import <MediaLibraryKit/MediaLibraryKit.h>
+
+@implementation MLMediaLibrary (playlist)
+
+
+- (NSArray *)playlistArrayForGroupObject:(id)groupObject
+{
+    if([groupObject isKindOfClass:[MLLabel class]]) {
+        return [(MLLabel *)groupObject sortedFolderItems];
+    } else if ([groupObject isKindOfClass:[MLAlbum class]]) {
+        return [(MLAlbum *)groupObject sortedTracks];
+    } else if ([groupObject isKindOfClass:[MLShow class]]){
+        return [(MLShow *)groupObject sortedEpisodes];
+    } else {
+        NSAssert(NO, @"this shouldn't have happened check the grouObjects type");
+        return nil;
+    }
+}
+
+//TODO: this code could use refactoring to be more readable
+- (NSArray *)playlistArrayForLibraryMode:(VLCLibraryMode)libraryMode
+{
+
+    NSMutableArray *objects = [NSMutableArray array];
+
+    /* add all albums */
+    if (libraryMode != VLCLibraryModeAllSeries) {
+        NSArray *rawAlbums = [MLAlbum allAlbums];
+        for (MLAlbum *album in rawAlbums) {
+            if (album.name.length > 0 && album.tracks.count > 1)
+                [objects addObject:album];
+        }
+    }
+    if (libraryMode == VLCLibraryModeAllAlbums) {
+        return objects;
+    }
+
+    /* add all shows */
+    NSArray *rawShows = [MLShow allShows];
+    for (MLShow *show in rawShows) {
+        if (show.name.length > 0 && show.episodes.count > 1)
+            [objects addObject:show];
+    }
+    if (libraryMode == VLCLibraryModeAllSeries) {
+        return objects;
+    }
+
+    /* add all folders*/
+    NSArray *allFolders = [MLLabel allLabels];
+    for (MLLabel *folder in allFolders)
+        [objects addObject:folder];
+
+    /* add all remaining files */
+    NSArray *allFiles = [MLFile allFiles];
+    for (MLFile *file in allFiles) {
+        if (file.labels.count > 0) continue;
+
+        if (!file.isShowEpisode && !file.isAlbumTrack)
+            [objects addObject:file];
+        else if (file.isShowEpisode) {
+            if (file.showEpisode.show.episodes.count < 2)
+                [objects addObject:file];
+
+            /* older MediaLibraryKit versions don't send a show name in a popular
+             * corner case. hence, we need to work-around here and force a reload
+             * afterwards as this could lead to the 'all my shows are gone'
+             * syndrome (see #10435, #10464, #10432 et al) */
+            if (file.showEpisode.show.name.length == 0) {
+                file.showEpisode.show.name = NSLocalizedString(@"UNTITLED_SHOW", nil);
+            }
+        } else if (file.isAlbumTrack) {
+            if (file.albumTrack.album.tracks.count < 2)
+                [objects addObject:file];
+        }
+    }
+
+    return objects;
+}
+
+@end

+ 12 - 79
VLC for iOS WatchKit Extension/VLCPlaylistInterfaceController.m

@@ -20,18 +20,12 @@
 #import "VLCNotificationRelay.h"
 #import "VLCWatchTableController.h"
 #import "NSManagedObjectContext+refreshAll.h"
+#import "MLMediaLibrary+playlist.h"
 
 static NSString *const rowType = @"mediaRow";
 static NSString *const VLCDBUpdateNotification = @"VLCUpdateDataBase";
 static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.dbupdate";
 
-typedef enum {
-    VLCLibraryModeAllFiles  = 0,
-    VLCLibraryModeAllAlbums = 1,
-    VLCLibraryModeAllSeries = 2,
-    VLCLibraryModeInGroup = 3
-} VLCLibraryMode;
-
 @interface VLCPlaylistInterfaceController()
 {
     CGRect _thumbnailSize;
@@ -62,7 +56,7 @@ typedef enum {
     } else {
         self.groupObject = context;
         self.title = [self.groupObject name];
-        self.libraryMode = VLCLibraryModeInGroup;
+        self.libraryMode = VLCLibraryModeNone;
     }
     [self addNowPlayingMenu];
 
@@ -140,77 +134,6 @@ typedef enum {
     self.tableController.objects = [self mediaArray];
 }
 
-//TODO: this code could use refactoring to be more readable
-- (NSMutableArray *)mediaArray {
-
-    if (_libraryMode == VLCLibraryModeInGroup) {
-        id groupObject = self.groupObject;
-
-        if([groupObject isKindOfClass:[MLLabel class]]) {
-            return [NSMutableArray arrayWithArray:[(MLLabel *)groupObject sortedFolderItems]];
-        } else if ([groupObject isKindOfClass:[MLAlbum class]]) {
-            return [NSMutableArray arrayWithArray:[(MLAlbum *)groupObject sortedTracks]];
-        } else if ([groupObject isKindOfClass:[MLShow class]]){
-            return [NSMutableArray arrayWithArray:[(MLShow *)groupObject sortedEpisodes]];
-        } else {
-            NSAssert(NO, @"this shouldn't have happened check the grouObjects type");
-        }
-    }
-
-    NSMutableArray *objects = [NSMutableArray array];
-
-    /* add all albums */
-    if (_libraryMode != VLCLibraryModeAllSeries) {
-        NSArray *rawAlbums = [MLAlbum allAlbums];
-        for (MLAlbum *album in rawAlbums) {
-            if (album.name.length > 0 && album.tracks.count > 1)
-                [objects addObject:album];
-        }
-    }
-    if (_libraryMode == VLCLibraryModeAllAlbums) {
-        return objects;
-    }
-
-    /* add all shows */
-    NSArray *rawShows = [MLShow allShows];
-    for (MLShow *show in rawShows) {
-        if (show.name.length > 0 && show.episodes.count > 1)
-            [objects addObject:show];
-    }
-    if (_libraryMode == VLCLibraryModeAllSeries) {
-        return objects;
-    }
-
-    /* add all folders*/
-    NSArray *allFolders = [MLLabel allLabels];
-    for (MLLabel *folder in allFolders)
-        [objects addObject:folder];
-
-    /* add all remaining files */
-    NSArray *allFiles = [MLFile allFiles];
-    for (MLFile *file in allFiles) {
-        if (file.labels.count > 0) continue;
-
-        if (!file.isShowEpisode && !file.isAlbumTrack)
-            [objects addObject:file];
-        else if (file.isShowEpisode) {
-            if (file.showEpisode.show.episodes.count < 2)
-                [objects addObject:file];
-
-            /* older MediaLibraryKit versions don't send a show name in a popular
-             * corner case. hence, we need to work-around here and force a reload
-             * afterwards as this could lead to the 'all my shows are gone'
-             * syndrome (see #10435, #10464, #10432 et al) */
-            if (file.showEpisode.show.name.length == 0) {
-                file.showEpisode.show.name = NSLocalizedString(@"UNTITLED_SHOW", nil);
-            }
-        } else if (file.isAlbumTrack) {
-            if (file.albumTrack.album.tracks.count < 2)
-                [objects addObject:file];
-        }
-    }
-    return objects;
-}
 
 - (void)setLibraryMode:(VLCLibraryMode)libraryMode
 {
@@ -219,4 +142,14 @@ typedef enum {
     _libraryMode = libraryMode;
 }
 
+- (NSArray *)mediaArray
+{
+    id groupObject = self.groupObject;
+    if (groupObject) {
+        return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForGroupObject:groupObject];
+    } else {
+        return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForLibraryMode:self.libraryMode];
+    }
+}
+
 @end

+ 16 - 0
VLC for iOS.xcodeproj/project.pbxproj

@@ -552,6 +552,8 @@
 		DD02C30E1ACAF4A50026EFEE /* VLCRowController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD02C30D1ACAF4A50026EFEE /* VLCRowController.m */; };
 		DD1542121ACFF76400AFD4EC /* VLCWatchTableController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1542111ACFF76400AFD4EC /* VLCWatchTableController.m */; };
 		DD6FA7B01ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD6FA7AF1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m */; };
+		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 */; };
 		DDACEB561ADAD11300735484 /* WKInterfaceObject+VLCProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = DDACEB551ADAD11300735484 /* WKInterfaceObject+VLCProgress.m */; };
 		DDC10BE41AEE8EA700890DC3 /* VLCTimeNavigationTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDC10BE31AEE8EA700890DC3 /* VLCTimeNavigationTitleView.m */; };
@@ -1618,6 +1620,8 @@
 		DD1542111ACFF76400AFD4EC /* VLCWatchTableController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCWatchTableController.m; sourceTree = "<group>"; };
 		DD6FA7AE1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCNowPlayingInterfaceController.h; sourceTree = "<group>"; };
 		DD6FA7AF1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCNowPlayingInterfaceController.m; sourceTree = "<group>"; };
+		DD7110EE1AF38B2B00854776 /* MLMediaLibrary+playlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MLMediaLibrary+playlist.h"; sourceTree = "<group>"; };
+		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>"; };
 		DDACEB541ADAD11300735484 /* WKInterfaceObject+VLCProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKInterfaceObject+VLCProgress.h"; sourceTree = "<group>"; };
@@ -2468,6 +2472,7 @@
 				A7924697170F0ED20036AAF2 /* Resources */,
 				7D94FCE516DE7D1000F2623B /* Supporting Files */,
 				CC1BBC441704936500A20CBF /* External VLC Libraries */,
+				DD7110ED1AF38AFD00854776 /* SharedSources */,
 				4173AEA11ABF1B850004101D /* VLC for iOS WatchKit Extension */,
 				4173AEAF1ABF1B850004101D /* VLC for iOS WatchKit App */,
 				7D94FCDD16DE7D1000F2623B /* Frameworks */,
@@ -3010,6 +3015,15 @@
 			name = "External VLC Libraries";
 			sourceTree = "<group>";
 		};
+		DD7110ED1AF38AFD00854776 /* SharedSources */ = {
+			isa = PBXGroup;
+			children = (
+				DD7110EE1AF38B2B00854776 /* MLMediaLibrary+playlist.h */,
+				DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */,
+			);
+			path = SharedSources;
+			sourceTree = "<group>";
+		};
 		E0C04F921A25B41C0080331A /* Document Picker */ = {
 			isa = PBXGroup;
 			children = (
@@ -3638,6 +3652,7 @@
 				DDF157B11ACB162700AAFBC6 /* MediaLibrary.xcdatamodeld in Sources */,
 				DDE490731ACE964200B1B5E3 /* VLCBaseInterfaceController.m in Sources */,
 				DDE4906C1ACDB63F00B1B5E3 /* VLCNotificationRelay.m in Sources */,
+				DD7110F11AF38B2B00854776 /* MLMediaLibrary+playlist.m in Sources */,
 				DD1542121ACFF76400AFD4EC /* VLCWatchTableController.m in Sources */,
 				DD02C30E1ACAF4A50026EFEE /* VLCRowController.m in Sources */,
 				DD7635D61AF262D100240CB8 /* NSManagedObjectContext+refreshAll.m in Sources */,
@@ -3696,6 +3711,7 @@
 				7DC19ADF1868C7BB00810BF7 /* VLCFirstStepsViewController.m in Sources */,
 				7DE56C1A1AD93F9100E8CA00 /* VLCPlaybackController.m in Sources */,
 				7DC72D6317B7ED24008A26D0 /* WhiteRaccoon.m in Sources */,
+				DD7110F01AF38B2B00854776 /* MLMediaLibrary+playlist.m in Sources */,
 				7D5CAA891A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m in Sources */,
 				7D63C19018774B1700BD5256 /* VLCFirstStepsSecondPageViewController.m in Sources */,
 				8F91EC79195CEC7900F5BCBA /* VLCOpenInActivity.m in Sources */,