Переглянути джерело

push a tableviewcontroller for groupitems and a detailviewcontroller otherwise

Carola Nitz 10 роки тому
батько
коміт
06c877d059

+ 3 - 3
VLC for iOS WatchKit App/Base.lproj/Interface.storyboard

@@ -5,10 +5,10 @@
         <plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="3737"/>
     </dependencies>
     <scenes>
-        <!--Interface Controller-->
+        <!--tableViewController-->
         <scene sceneID="aou-V4-d1y">
             <objects>
-                <controller id="AgC-eL-Hgc" customClass="InterfaceController">
+                <controller identifier="tableViewController" id="AgC-eL-Hgc" customClass="InterfaceController">
                     <items>
                         <button width="1" alignment="left" title="︿" id="fUJ-qB-19l">
                             <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@@ -19,7 +19,7 @@
                         <table alignment="left" id="lC4-Vd-sgP">
                             <items>
                                 <tableRow identifier="mediaRow" id="QhF-se-FCS" customClass="VLCRowController">
-                                    <group key="rootItem" width="1" height="60" alignment="left" contentMode="scaleAspectFill" layout="vertical" radius="10" id="IQK-uE-8Jr">
+                                    <group key="rootItem" width="1" height="60" alignment="left" contentMode="scaleAspectFill" layout="vertical" radius="5" id="IQK-uE-8Jr">
                                         <items>
                                             <label alignment="left" verticalAlignment="bottom" text="title" numberOfLines="0" minimumScaleFactor="0.90000000000000002" id="bUB-PE-2P0"/>
                                         </items>

+ 44 - 12
VLC for iOS WatchKit Extension/InterfaceController.m

@@ -28,13 +28,16 @@ static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.db
 typedef enum {
     VLCLibraryModeAllFiles  = 0,
     VLCLibraryModeAllAlbums = 1,
-    VLCLibraryModeAllSeries = 2
+    VLCLibraryModeAllSeries = 2,
+    VLCLibraryModeInGroup = 3
 } VLCLibraryMode;
 
 @interface InterfaceController()
 @property (nonatomic, strong) VLCWatchTableController *tableController;
 @property (nonatomic) VLCLibraryMode libraryMode;
 @property (nonatomic) BOOL needsUpdate;
+@property (nonatomic) id groupObject;
+
 @end
 
 @implementation InterfaceController
@@ -44,20 +47,32 @@ typedef enum {
     NSLog(@"%s",__PRETTY_FUNCTION__);
 
     NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.org.videolan.vlc-ios"];
-    [self setupMenuButtons];
-    self.libraryMode = VLCLibraryModeAllFiles;
     MLMediaLibrary *mediaLibrary = [MLMediaLibrary sharedMediaLibrary];
     mediaLibrary.libraryBasePath = groupURL.path;
     mediaLibrary.additionalPersitentStoreOptions = @{NSReadOnlyPersistentStoreOption : @YES};
 
-    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
-
-    self.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", nil);
-    self.emptyLibraryLabelLong.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", nil);
+    if (context == nil) {
+        self.libraryMode = VLCLibraryModeAllFiles;
+        [self setupMenuButtons];
+        self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
+        self.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", nil);
+        self.emptyLibraryLabelLong.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", nil);
+    } else {
+        self.groupObject = context;
+        self.title = [self.groupObject name];
+        self.libraryMode = VLCLibraryModeInGroup;
+    }
 
     [[VLCNotificationRelay sharedRelay] addRelayRemoteName:VLCDBUpdateNotificationRemote toLocalName:VLCDBUpdateNotification];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateData) name:VLCDBUpdateNotification object:nil];
 
+    [self setupTableController];
+    [self updateData];
+
+}
+
+- (void)setupTableController {
+
     VLCWatchTableController *tableController = [[VLCWatchTableController alloc] init];
     tableController.table = self.table;
     tableController.previousPageButton = self.previousButton;
@@ -71,8 +86,6 @@ typedef enum {
         [weakSelf configureTableRowController:controller withObject:object];
     };
     self.tableController = tableController;
-    [self updateData];
-
 }
 
 - (void) dealloc {
@@ -90,7 +103,9 @@ typedef enum {
 
 - (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
     id object = self.tableController.displayedObjects[rowIndex];
-    if ([object isKindOfClass:[MLFile class]]) {
+    if ([object isKindOfClass:[MLAlbum class]] || [object isKindOfClass:[MLLabel class]] || [object isKindOfClass:[MLShow class]]) {
+        [self pushControllerWithName:@"tableViewController" context:object];
+    } else {
         [self pushControllerWithName:@"detailInfo" context:object];
     }
 }
@@ -142,6 +157,7 @@ typedef enum {
 }
 
 - (void)configureTableRowController:(id)rowController withObject:(id)storageObject {
+
     VLCRowController *row = rowController;
     UIImage *backgroundImage;
 
@@ -173,9 +189,10 @@ typedef enum {
         backgroundImage = nil;
      */
 
-    [row.group setBackgroundImage:[self generateBackgroundiImageWithGradient:backgroundImage]];
+    [row.group setBackgroundImage:[self generateBackgroundImageWithGradient:backgroundImage]];
 }
-- (UIImage *)generateBackgroundiImageWithGradient:(UIImage *)backgroundImage {
+
+- (UIImage *)generateBackgroundImageWithGradient:(UIImage *)backgroundImage {
 
     UIImage *gradient = [UIImage imageNamed:@"gradient-cell-ios7"];
 
@@ -195,6 +212,21 @@ typedef enum {
 
 //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 */