瀏覽代碼

Code simplification: subclass VLCPlaylistGridView from AQGridViewCell, editing simplification

Gleb Pinigin 12 年之前
父節點
當前提交
44b7ec40c6

+ 3 - 3
AspenProject/VLCPlaylistGridView.h

@@ -7,8 +7,9 @@
 //
 
 #import "VLCLinearProgressIndicator.h"
+#import "AQGridViewCell.h"
 
-@interface VLCPlaylistGridView : UIView
+@interface VLCPlaylistGridView : AQGridViewCell
 
 @property (nonatomic, strong) IBOutlet UILabel *titleLabel;
 @property (nonatomic, strong) IBOutlet UILabel *subtitleLabel;
@@ -18,8 +19,7 @@
 
 @property (nonatomic, retain) MLFile *mediaObject;
 
-@property (nonatomic) BOOL editable;
-
 - (IBAction)removeMedia:(id)sender;
++ (CGSize)preferredSize;
 
 @end

+ 19 - 5
AspenProject/VLCPlaylistGridView.m

@@ -10,19 +10,33 @@
 #import "VLCAppDelegate.h"
 
 @interface VLCPlaylistGridView (Hack)
-@property (nonatomic, retain) NSString * reuseIdentifier;
+@property (nonatomic, retain) NSString *reuseIdentifier;
 @end
 
 @implementation VLCPlaylistGridView
 
-- (BOOL)editable
+- (void)awakeFromNib {
+    [super awakeFromNib];
+    _contentView = self;
+    self.backgroundColor = [UIColor blackColor];
+    self.reuseIdentifier = @"AQPlaylistCell";
+}
+
+- (void)setEditing:(BOOL)editing animated:(BOOL)animated
+{
+    [super setEditing:editing animated:animated];
+    self.removeMediaButton.hidden = !editing;
+}
+
+- (void)prepareForReuse
 {
-    return !self.removeMediaButton.hidden;
+    [super prepareForReuse];
+    self.removeMediaButton.hidden = YES;
 }
 
-- (void)setEditable:(BOOL)editable
++ (CGSize)preferredSize
 {
-    self.removeMediaButton.hidden = !editable;
+    return CGSizeMake(384, 240);
 }
 
 - (void)setMediaObject:(MLFile *)mediaObject

+ 1 - 68
AspenProject/VLCPlaylistGridView.xib

@@ -42,7 +42,6 @@
 						<int key="NSvFlags">292</int>
 						<string key="NSFrame">{{52, 8}, {281, 160}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
 						<reference key="NSNextKeyView" ref="978623485"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<object class="NSColor" key="IBUIBackgroundColor">
@@ -56,7 +55,6 @@
 						<int key="NSvFlags">274</int>
 						<string key="NSFrame">{{54, 10}, {277, 156}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
 						<reference key="NSNextKeyView" ref="296556150"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<bool key="IBUIUserInteractionEnabled">NO</bool>
@@ -67,7 +65,6 @@
 						<int key="NSvFlags">264</int>
 						<string key="NSFrame">{{20, 182}, {344, 21}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
 						<reference key="NSNextKeyView" ref="610797449"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<bool key="IBUIOpaque">NO</bool>
@@ -107,8 +104,6 @@
 						<int key="NSvFlags">264</int>
 						<string key="NSFrame">{{20, 203}, {344, 28}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
-						<reference key="NSNextKeyView"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<bool key="IBUIOpaque">NO</bool>
 						<bool key="IBUIClipsSubviews">YES</bool>
@@ -141,7 +136,6 @@
 						<int key="NSvFlags">292</int>
 						<string key="NSFrame">{{54, 154}, {277, 12}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
 						<reference key="NSNextKeyView" ref="276503826"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<object class="NSColor" key="IBUIBackgroundColor">
@@ -155,7 +149,6 @@
 						<int key="NSvFlags">-2147483356</int>
 						<string key="NSFrame">{{314, 0}, {33, 29}}</string>
 						<reference key="NSSuperview" ref="93090196"/>
-						<reference key="NSWindow"/>
 						<reference key="NSNextKeyView" ref="863064291"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<bool key="IBUIOpaque">NO</bool>
@@ -191,7 +184,6 @@
 				</array>
 				<string key="NSFrameSize">{384, 243}</string>
 				<reference key="NSSuperview"/>
-				<reference key="NSWindow"/>
 				<reference key="NSNextKeyView" ref="470328177"/>
 				<string key="NSReuseIdentifierKey">_NS:9</string>
 				<object class="NSColor" key="IBUIBackgroundColor">
@@ -342,66 +334,7 @@
 			<nil key="sourceID"/>
 			<int key="maxID">22</int>
 		</object>
-		<object class="IBClassDescriber" key="IBDocument.Classes">
-			<array class="NSMutableArray" key="referencedPartialClassDescriptions">
-				<object class="IBPartialClassDescription">
-					<string key="className">VLCLinearProgressIndicator</string>
-					<string key="superclassName">UIProgressView</string>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/VLCLinearProgressIndicator.h</string>
-					</object>
-				</object>
-				<object class="IBPartialClassDescription">
-					<string key="className">VLCPlaylistGridView</string>
-					<string key="superclassName">UIView</string>
-					<object class="NSMutableDictionary" key="actions">
-						<string key="NS.key.0">removeMedia:</string>
-						<string key="NS.object.0">id</string>
-					</object>
-					<object class="NSMutableDictionary" key="actionInfosByName">
-						<string key="NS.key.0">removeMedia:</string>
-						<object class="IBActionInfo" key="NS.object.0">
-							<string key="name">removeMedia:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</object>
-					<dictionary class="NSMutableDictionary" key="outlets">
-						<string key="progressView">VLCLinearProgressIndicator</string>
-						<string key="removeMediaButton">UIButton</string>
-						<string key="subtitleLabel">UILabel</string>
-						<string key="thumbnailView">UIImageView</string>
-						<string key="titleLabel">UILabel</string>
-					</dictionary>
-					<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-						<object class="IBToOneOutletInfo" key="progressView">
-							<string key="name">progressView</string>
-							<string key="candidateClassName">VLCLinearProgressIndicator</string>
-						</object>
-						<object class="IBToOneOutletInfo" key="removeMediaButton">
-							<string key="name">removeMediaButton</string>
-							<string key="candidateClassName">UIButton</string>
-						</object>
-						<object class="IBToOneOutletInfo" key="subtitleLabel">
-							<string key="name">subtitleLabel</string>
-							<string key="candidateClassName">UILabel</string>
-						</object>
-						<object class="IBToOneOutletInfo" key="thumbnailView">
-							<string key="name">thumbnailView</string>
-							<string key="candidateClassName">UIImageView</string>
-						</object>
-						<object class="IBToOneOutletInfo" key="titleLabel">
-							<string key="name">titleLabel</string>
-							<string key="candidateClassName">UILabel</string>
-						</object>
-					</dictionary>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/VLCPlaylistGridView.h</string>
-					</object>
-				</object>
-			</array>
-		</object>
+		<object class="IBClassDescriber" key="IBDocument.Classes"/>
 		<int key="IBDocument.localizationMode">0</int>
 		<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
 		<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">

+ 9 - 22
AspenProject/VLCPlaylistViewController.m

@@ -150,33 +150,22 @@
 
 - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
 {
-    static NSString *AQCellIdentifier = @"AQCell";
+    static NSString *AQCellIdentifier = @"AQPlaylistCell";
 
-    AQGridViewCell *cell = (AQGridViewCell *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
+    VLCPlaylistGridView *cell = (VLCPlaylistGridView *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
     if (cell == nil) {
-        VLCPlaylistGridView *cellViewClass = [[VLCPlaylistGridView alloc] init];
-
-        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistGridView" owner:cellViewClass options:nil];
-        cellViewClass = [array objectAtIndex:0];
-        cell = [[AQGridViewCell alloc] initWithFrame:cellViewClass.frame reuseIdentifier:AQCellIdentifier];
-        [cell.contentView addSubview:cellViewClass];
+        cell = [[[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistGridView" owner:self options:nil] lastObject];
         cell.selectionStyle = AQGridViewCellSelectionStyleGlow;
     }
 
-    VLCPlaylistGridView *cellView = (VLCPlaylistGridView *)[[cell contentView] viewWithTag:1];
-    cellView.mediaObject = _foundMedia[index];
+    cell.mediaObject = _foundMedia[index];
 
     return cell;
 }
 
 - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
 {
-    VLCPlaylistGridView *cellViewClass = [[VLCPlaylistGridView alloc] init];
-    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistGridView" owner:cellViewClass options:nil];
-    cellViewClass = [array objectAtIndex:0];
-
-    CGSize cellSize = CGSizeMake(cellViewClass.frame.size.width, cellViewClass.frame.size.height);
-    return cellSize;
+    return [VLCPlaylistGridView preferredSize];
 }
 
 - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
@@ -197,13 +186,11 @@
     else
         _editMode = !editing;
 
-    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
-        NSUInteger count = _foundMedia.count;
-        for (NSUInteger x = 0; x < count; x++) {
-            [(VLCPlaylistGridView *)[[[self.gridView cellForItemAtIndex:x] contentView] viewWithTag:1] setEditable:_editMode];
-        }
-    } else
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        [self.gridView setEditing:_editMode];
+    } else {
         [self.tableView setEditing:_editMode animated:YES];
+    }
 
     if (_editMode) {
         self.editButtonItem.style = UIBarButtonItemStyleDone;