Prechádzať zdrojové kódy

add VLCWatchTableController (untested I hope it works)

Tobias Conradi 10 rokov pred
rodič
commit
1b46795495

+ 2 - 3
Podfile.lock

@@ -11,8 +11,7 @@ PODS:
   - upnpx (1.3.2)
 
 DEPENDENCIES:
-  - box-ios-sdk-v2 (from `git://github.com/carolanitz/box-ios-sdk-v2.git`, commit
-    `d2df30aa5f76d30910e06f3ef5aff49025de3cf1`)
+  - box-ios-sdk-v2 (from `git://github.com/carolanitz/box-ios-sdk-v2.git`, commit `d2df30aa5f76d30910e06f3ef5aff49025de3cf1`)
   - GHSidebarNav (= 1.0.0)
   - InAppSettingsKit (= 2.2.2)
   - OBSlider (= 1.1.0)
@@ -46,4 +45,4 @@ SPEC CHECKSUMS:
   SSKeychain: 88767e903ee8d274ed380e364d96b7a101235286
   upnpx: e56e4f26d21c439b2383e03b5ca9082a3d5046a1
 
-COCOAPODS: 0.36.1
+COCOAPODS: 0.36.0

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

@@ -10,6 +10,11 @@
             <objects>
                 <controller id="AgC-eL-Hgc" customClass="InterfaceController">
                     <items>
+                        <button width="1" alignment="left" title="previous page" id="fUJ-qB-19l">
+                            <connections>
+                                <action selector="previousPagePressed" destination="AgC-eL-Hgc" id="d5P-dB-jji"/>
+                            </connections>
+                        </button>
                         <table alignment="left" id="lC4-Vd-sgP">
                             <items>
                                 <tableRow identifier="mediaRow" id="QhF-se-FCS" customClass="VLCRowController">
@@ -27,8 +32,15 @@
                                 </tableRow>
                             </items>
                         </table>
+                        <button width="1" alignment="left" title="next page" id="3AK-kX-V9D">
+                            <connections>
+                                <action selector="nextPagePressed" destination="AgC-eL-Hgc" id="iNm-4n-TvE"/>
+                            </connections>
+                        </button>
                     </items>
                     <connections>
+                        <outlet property="nextButton" destination="3AK-kX-V9D" id="Iju-cx-571"/>
+                        <outlet property="previousButton" destination="fUJ-qB-19l" id="r36-II-aik"/>
                         <outlet property="table" destination="lC4-Vd-sgP" id="mxe-b7-XMx"/>
                     </connections>
                 </controller>

+ 5 - 0
VLC for iOS WatchKit Extension/InterfaceController.h

@@ -17,5 +17,10 @@
 #import "VLCBaseInterfaceController.h"
 
 @interface InterfaceController : VLCBaseInterfaceController
+@property (weak, nonatomic) IBOutlet WKInterfaceButton *previousButton;
 @property (nonatomic, weak) IBOutlet WKInterfaceTable *table;
+@property (weak, nonatomic) IBOutlet WKInterfaceButton *nextButton;
+- (IBAction)previousPagePressed;
+- (IBAction)nextPagePressed;
+
 @end

+ 26 - 27
VLC for iOS WatchKit Extension/InterfaceController.m

@@ -17,13 +17,14 @@
 #import <MobileVLCKit/VLCTime.h>
 
 #import "VLCNotificationRelay.h"
+#import "VLCWatchTableController.h"
 
 static NSString *const rowType = @"mediaRow";
 static NSString *const VLCDBUpdateNotification = @"VLCUpdateDataBase";
 static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.dbupdate";
 
 @interface InterfaceController()
-@property (nonatomic, strong) NSMutableArray *mediaObjects;
+@property (nonatomic, strong) VLCWatchTableController *tableController;
 @end
 
 
@@ -42,6 +43,18 @@ static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.db
     self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
     [[VLCNotificationRelay sharedRelay] addRelayRemoteName:VLCDBUpdateNotificationRemote toLocalName:VLCDBUpdateNotification];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateData) name:VLCDBUpdateNotification object:nil];
+    VLCWatchTableController *tableController = [VLCWatchTableController new];
+    tableController.table = self.table;
+    tableController.previousPageButton = self.previousButton;
+    tableController.nextPageButton = self.nextButton;
+    tableController.pageSize = 5;
+    tableController.rowTypeForObjectBlock = ^(id object) {
+        return rowType;
+    };
+    tableController.configureRowControllerWithObjectBlock = ^(id controller, id object) {
+        [self configureTableRowController:context withObject:object];
+    };
+
 
     [self updateData];
 }
@@ -62,43 +75,29 @@ static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.db
     [[NSNotificationCenter defaultCenter] removeObserver:self name:VLCDBUpdateNotification object:nil];
 }
 
-
-
-
 - (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
-    id object = self.mediaObjects[rowIndex];
+    id object = self.tableController.displayedObjects[rowIndex];
     if ([object isKindOfClass:[MLFile class]]) {
         [self pushControllerWithName:@"detailInfo" context:object];
     }
 }
 
-#pragma mark - data handling
-
-- (void)updateData {
-    NSArray *oldObjects = self.mediaObjects;
-    NSSet *oldSet = [[NSSet alloc] initWithArray:oldObjects];
-    NSMutableArray *newObjects = [self mediaArray];
-    NSMutableSet *newSet = [[NSMutableSet alloc] initWithArray:newObjects];
+- (IBAction)nextPagePressed {
+    [self.tableController nextPageButtonPressed];
+}
 
-    WKInterfaceTable *table = self.table;
+- (IBAction)previousPagePressed {
+    [self.tableController previousPageButtonPressed];
+}
 
-    [oldObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
-        if (![newSet containsObject:obj]) {
-            [table removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:idx]];
-        }
-    }];
-    [newObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
-        if (![oldSet containsObject:obj]) {
-            [table insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:idx] withRowType:rowType];
-        }
-        [self configureTableCellAtIndex:idx withObject:obj];
-    }];
+#pragma mark - data handling
 
-    self.mediaObjects = newObjects;
+- (void)updateData {
+    self.tableController.objects = [self mediaArray];
 }
 
-- (void)configureTableCellAtIndex:(NSUInteger)index withObject:(MLFile *)object {
-    VLCRowController *row = [self.table rowControllerAtIndex:index];
+- (void)configureTableRowController:(id)rowController withObject:(MLFile *)object {
+    VLCRowController *row = rowController;
     row.titleLabel.text = object.title;
     row.durationLabel.text = [VLCTime timeWithNumber:object.duration].stringValue;
     [row.group setBackgroundImage:object.computedThumbnail];

+ 57 - 0
VLC for iOS WatchKit Extension/VLCWatchTableController.h

@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * VLCWatchTableController.h
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Tobias Conradi <videolan # tobias-conradi.de>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import <WatchKit/WatchKit.h>
+
+typedef NSString *(^VLCWatchTableControllerRowTypeForObjectBlock)(id object);
+typedef void(^VLCWatchTableControllerConfigureRowControllerWithObjectBlock)(id rowController, id object);
+
+@interface VLCWatchTableController : NSObject
+@property (nonatomic, weak) IBOutlet WKInterfaceTable *table;
+
+/* 
+ * previous and next buttons are automatically hidden/shown depening on number
+ * of objects, page size and the current page
+ */
+@property (nonatomic, weak) IBOutlet WKInterfaceButton *previousPageButton;
+@property (nonatomic, weak) IBOutlet WKInterfaceButton *nextPageButton;
+
+
+/* 
+ * set eigher rowType if every row should have the same rowType or the
+ * rowTypeForObjectBlock which returns the matching row type for an object
+ */
+@property (nonatomic, copy) NSString *rowType;
+@property (nonatomic, copy) VLCWatchTableControllerRowTypeForObjectBlock rowTypeForObjectBlock;
+
+@property (nonatomic, copy) VLCWatchTableControllerConfigureRowControllerWithObjectBlock configureRowControllerWithObjectBlock;
+
+@property (nonatomic, copy, readonly) NSArray *displayedObjects;
+@property (nonatomic, copy, readonly) NSIndexSet *displayedIndexes;
+
+/* does setting these does not trigger table update call updateTable manually to update table */
+@property (nonatomic, assign) NSUInteger pageSize;
+@property (nonatomic, assign) NSUInteger currentPage;
+/*
+ * When the objects array changes it will figure out inserted and removed objects
+ * and updates the table accoringly.
+ */
+@property (nonatomic, copy) NSArray *objects;
+
+/* updates the table with the current configuration (pagesize, page, objects) */
+- (void)updateTable;
+
+- (IBAction)previousPageButtonPressed;
+- (IBAction)nextPageButtonPressed;
+
+
+@end

+ 124 - 0
VLC for iOS WatchKit Extension/VLCWatchTableController.m

@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * VLCWatchTableController.m
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2015 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Tobias Conradi <videolan # tobias-conradi.de>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+#import "VLCWatchTableController.h"
+
+
+@interface VLCWatchTableController()
+
+@property (nonatomic, copy, readwrite) NSArray *displayedObjects;
+@property (nonatomic, copy, readwrite) NSIndexSet *displayedIndexes;
+
+@end
+
+@implementation VLCWatchTableController
+
+
+- (void)setObjects:(NSArray *)objects {
+    _objects = [objects copy];
+    [self updateTable];
+}
+
+
+- (void)updateTable {
+
+    NSUInteger pageSize = self.pageSize;
+    NSUInteger currentPage = self.currentPage;
+    NSUInteger startIndex = self.currentPage*pageSize;
+    NSUInteger objectsCount = self.objects.count;
+
+    /* calculate a valid start index and reset current page if needed */
+    while (startIndex > objectsCount) {
+        if (startIndex < pageSize) {
+            startIndex = 0;
+            currentPage = 0;
+        } else {
+            startIndex -= pageSize;
+            currentPage--;
+        }
+    }
+
+    /* calculate valid end index */
+    NSUInteger endIndex = startIndex+pageSize;
+    if (endIndex > objectsCount) {
+        endIndex = objectsCount;
+    }
+
+    /* set starte for previous and next buttons */
+    self.previousPageButton.hidden = currentPage > 0;
+    self.nextPageButton.hidden = endIndex < objectsCount;
+
+    /* get new dispayed objects */
+    NSRange range = NSMakeRange(startIndex, endIndex-startIndex);
+    NSArray *newObjects = [self.objects subarrayWithRange:range];
+    NSMutableSet *newSet = [[NSMutableSet alloc] initWithArray:newObjects];
+
+    NSArray *oldObjects = self.displayedObjects;
+    NSSet *oldSet = [[NSSet alloc] initWithArray:oldObjects];
+
+    WKInterfaceTable *table = self.table;
+
+    [oldObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+        if (![newSet containsObject:obj]) {
+            [table removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:idx]];
+        }
+    }];
+
+    [newObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+        if (![oldSet containsObject:obj]) {
+            NSString *rowType = [self rowTypeForObject:obj];
+            [table insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:idx] withRowType:rowType];
+        }
+        [self configureTableCellAtIndex:idx withObject:obj];
+    }];
+
+    self.displayedObjects = newObjects;
+    self.displayedIndexes = [NSIndexSet indexSetWithIndexesInRange:range];
+}
+
+
+- (void)nextPageButtonPressed {
+    NSUInteger nextPageStartIndex = self.pageSize * (self.currentPage+1);
+    if (nextPageStartIndex > self.objects.count) {
+        return;
+    }
+    self.currentPage = self.currentPage+1;
+    [self updateTable];
+}
+
+- (void)previousPageButtonPressed {
+    if (self.pageSize>0) {
+        self.pageSize = self.pageSize-1;
+        [self updateTable];
+    }
+}
+
+#pragma mark - internal helper
+
+- (NSString *)rowTypeForObject:(id)object {
+    if (self.rowTypeForObjectBlock) {
+        return self.rowTypeForObjectBlock(object);
+    }
+    NSAssert(self.rowType, @"Either rowTypeForObjectBlock or rowType must be set");
+    return self.rowType;
+}
+
+- (void)configureTableCellAtIndex:(NSUInteger)index withObject:(id)object {
+    VLCWatchTableControllerConfigureRowControllerWithObjectBlock configureBlock = self.configureRowControllerWithObjectBlock;
+    NSAssert(configureBlock, @"configureRowControllerWithObjectBlock must be set");
+    if (configureBlock) {
+        id rowController = [self.table rowControllerAtIndex:index];
+        configureBlock(rowController, object);
+    }
+}
+
+@end

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

@@ -541,6 +541,7 @@
 		DD02C3071ACAEC690026EFEE /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CC1BBC4D170493A300A20CBF /* libbz2.dylib */; };
 		DD02C30B1ACAF0370026EFEE /* libstdc++.6.0.9.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DD02C30A1ACAF0370026EFEE /* libstdc++.6.0.9.dylib */; };
 		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 */; };
 		DDE4906C1ACDB63F00B1B5E3 /* VLCNotificationRelay.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */; };
 		DDE4906D1ACDBEA000B1B5E3 /* VLCNotificationRelay.m in Sources */ = {isa = PBXBuildFile; fileRef = DDE4906B1ACDB63F00B1B5E3 /* VLCNotificationRelay.m */; };
@@ -1580,6 +1581,8 @@
 		DD02C30A1ACAF0370026EFEE /* libstdc++.6.0.9.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.6.0.9.dylib"; path = "usr/lib/libstdc++.6.0.9.dylib"; sourceTree = SDKROOT; };
 		DD02C30C1ACAF4A50026EFEE /* VLCRowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCRowController.h; sourceTree = "<group>"; };
 		DD02C30D1ACAF4A50026EFEE /* VLCRowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCRowController.m; sourceTree = "<group>"; };
+		DD1542101ACFF76400AFD4EC /* VLCWatchTableController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCWatchTableController.h; sourceTree = "<group>"; };
+		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>"; };
 		DDE4906A1ACDB63F00B1B5E3 /* VLCNotificationRelay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCNotificationRelay.h; sourceTree = "<group>"; };
@@ -1805,6 +1808,8 @@
 				DDE490721ACE964200B1B5E3 /* VLCBaseInterfaceController.m */,
 				4173AEA41ABF1B850004101D /* InterfaceController.h */,
 				4173AEA51ABF1B850004101D /* InterfaceController.m */,
+				DD1542101ACFF76400AFD4EC /* VLCWatchTableController.h */,
+				DD1542111ACFF76400AFD4EC /* VLCWatchTableController.m */,
 				DD6FA7AE1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.h */,
 				DD6FA7AF1ACD641C006DEB2E /* VLCNowPlayingInterfaceController.m */,
 				DDE4906E1ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.h */,
@@ -3572,6 +3577,7 @@
 				DDF157B11ACB162700AAFBC6 /* MediaLibrary.xcdatamodeld in Sources */,
 				DDE490731ACE964200B1B5E3 /* VLCBaseInterfaceController.m in Sources */,
 				DDE4906C1ACDB63F00B1B5E3 /* VLCNotificationRelay.m in Sources */,
+				DD1542121ACFF76400AFD4EC /* VLCWatchTableController.m in Sources */,
 				DD02C30E1ACAF4A50026EFEE /* VLCRowController.m in Sources */,
 				DDE490701ACE8BBC00B1B5E3 /* VLCDetailInterfaceController.m in Sources */,
 				4173AEA61ABF1B850004101D /* InterfaceController.m in Sources */,