Commit f982baa4 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Clean-up property management within the grid view cell and add edit mode to grid view (close #8590)

parent 798ba7cf
......@@ -10,9 +10,8 @@
#import "VLCPlaylistViewController.h"
@interface VLCAppDelegate : UIResponder <UIApplicationDelegate>
{
VLCPlaylistViewController *_playlistViewController;
}
@property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController;
@property (nonatomic, strong) UIWindow *window;
......
......@@ -14,9 +14,12 @@
@property (nonatomic, strong) IBOutlet UILabel *subtitleLabel;
@property (nonatomic, strong) IBOutlet UIImageView *thumbnailView;
@property (nonatomic, strong) IBOutlet VLCLinearProgressIndicator *progressView;
@property (nonatomic, strong) IBOutlet UIButton *removeMediaButton;
@property (nonatomic, copy) UIImage *thumbnail;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, retain) MLFile *mediaObject;
@property (nonatomic) BOOL editable;
- (IBAction)removeMedia:(id)sender;
@end
......@@ -7,6 +7,7 @@
//
#import "VLCPlaylistGridView.h"
#import "VLCAppDelegate.h"
@interface VLCPlaylistGridView (Hack)
@property (nonatomic, retain) NSString * reuseIdentifier;
......@@ -14,37 +15,34 @@
@implementation VLCPlaylistGridView
- (UIImage *)thumbnail
- (BOOL)editable
{
return _thumbnailView.image;
return !self.removeMediaButton.hidden;
}
- (void)setThumbnail:(UIImage *)newThumb
- (void)setEditable:(BOOL)editable
{
self.thumbnailView.image = newThumb;
[self setNeedsDisplay];
self.removeMediaButton.hidden = !editable;
}
- (NSString *)title
- (void)setMediaObject:(MLFile *)mediaObject
{
return _titleLabel.text;
}
[mediaObject willDisplay];
- (void)setTitle:(NSString *)newTitle
{
self.titleLabel.text = newTitle;
[self setNeedsDisplay];
}
self.titleLabel.text = mediaObject.title;
self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[mediaObject duration]], [mediaObject fileSizeInBytes] / 2e6];
self.thumbnailView.image = mediaObject.computedThumbnail;
self.progressView.progress = mediaObject.lastPosition.floatValue;
- (NSString *)subtitle
{
return @"";
_mediaObject = mediaObject;
[self setNeedsDisplay];
}
- (void)setSubtitle:(NSString *)newSubtitle
- (IBAction)removeMedia:(id)sender
{
self.subtitleLabel.text = newSubtitle;
[self setNeedsDisplay];
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.playlistViewController removeMediaObject:self.mediaObject];
}
@end
......@@ -12,6 +12,7 @@
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
<string>IBUIButton</string>
<string>IBUIImageView</string>
<string>IBUILabel</string>
<string>IBUIView</string>
......@@ -107,7 +108,6 @@
<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>
......@@ -149,6 +149,41 @@
</object>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUIButton" id="296556150">
<reference key="NSNextResponder" ref="93090196"/>
<int key="NSvFlags">-2147483356</int>
<string key="NSFrame">{{11, 10}, {33, 29}}</string>
<reference key="NSSuperview" ref="93090196"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">x</string>
<object class="NSColor" key="IBUIHighlightedTitleColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleShadowColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC41AA</bytes>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">2</int>
<int key="size">2</int>
</object>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">18</double>
<int key="NSfFlags">16</int>
</object>
</object>
</array>
<string key="NSFrameSize">{384, 243}</string>
<reference key="NSSuperview"/>
......@@ -200,6 +235,23 @@
</object>
<int key="connectionID">18</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">removeMediaButton</string>
<reference key="source" ref="93090196"/>
<reference key="destination" ref="296556150"/>
</object>
<int key="connectionID">21</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">removeMedia:</string>
<reference key="source" ref="296556150"/>
<reference key="destination" ref="93090196"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">22</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
......@@ -229,6 +281,7 @@
<reference ref="610797449"/>
<reference ref="863064291"/>
<reference ref="470328177"/>
<reference ref="296556150"/>
</array>
<reference key="parent" ref="0"/>
</object>
......@@ -257,6 +310,11 @@
<reference key="object" ref="470328177"/>
<reference key="parent" ref="93090196"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">20</int>
<reference key="object" ref="296556150"/>
<reference key="parent" ref="93090196"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
......@@ -268,6 +326,7 @@
<string key="17.CustomClassName">VLCLinearProgressIndicator</string>
<string key="17.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="3.CustomClassName">VLCPlaylistGridView</string>
<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
......@@ -276,7 +335,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">19</int>
<int key="maxID">22</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
......@@ -291,8 +350,20 @@
<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>
......@@ -302,6 +373,10 @@
<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>
......
......@@ -15,6 +15,7 @@
@interface VLCPlaylistViewController : UIViewController <AQGridViewDataSource, AQGridViewDelegate, UITableViewDataSource, UITableViewDelegate, UITabBarDelegate>
{
NSURL *_pasteURL;
BOOL _editMode;
}
@property (nonatomic, strong) VLCMovieViewController *movieViewController;
......@@ -29,5 +30,6 @@
- (void)updateViewContents;
- (void)openMovieFromURL:(NSURL *)url;
- (void)removeMediaObject:(MLFile *)mediaObject;
@end
......@@ -69,6 +69,15 @@
[[MLMediaLibrary sharedMediaLibrary] libraryDidDisappear];
}
- (void)removeMediaObject:(MLFile *)mediaObject
{
[[NSFileManager defaultManager] removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
NSUInteger index = [_foundMedia indexOfObject:mediaObject];
[_foundMedia removeObjectAtIndex:index];
[self.tableView deleteRowsAtIndexPaths:[NSIndexPath indexPathWithIndex:index] withRowAnimation:UITableViewRowAnimationFade];
[self.gridView deleteItemsAtIndices:[NSIndexSet indexSetWithIndex:index] withAnimation:AQGridViewItemAnimationFade];
}
#pragma mark - Table View
- (void)updateViewContents
......@@ -119,16 +128,8 @@
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSUInteger row = indexPath.row;
MLFile *mediaObject = _foundMedia[row];
[[NSFileManager defaultManager] removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
[_foundMedia removeObjectAtIndex:row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.gridView deleteItemsAtIndices:[NSIndexSet indexSetWithIndex:row] withAnimation:AQGridViewItemAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
if (editingStyle == UITableViewCellEditingStyleDelete)
[self removeMediaObject: _foundMedia[indexPath.row]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
......@@ -162,12 +163,8 @@
cell.selectionStyle = AQGridViewCellSelectionStyleGlow;
}
MLFile *object = _foundMedia[index];
VLCPlaylistGridView *cellView = (VLCPlaylistGridView *)[[cell contentView] viewWithTag:1];
cellView.title = object.title;
cellView.subtitle = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
cellView.thumbnail = object.computedThumbnail;
cellView.progressView.progress = object.lastPosition.floatValue;
cellView.mediaObject = _foundMedia[index];
return cell;
}
......@@ -195,14 +192,25 @@
#pragma mark - UI implementation
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (self.tableView.editing) {
self.editButtonItem.style = UIBarButtonItemStylePlain;
self.editButtonItem.title = NSLocalizedString(@"Edit",@"");
[self.tableView setEditing:NO animated:YES];
} else {
if (_editMode != editing)
_editMode = editing;
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
[self.tableView setEditing:_editMode animated:YES];
if (_editMode) {
self.editButtonItem.style = UIBarButtonItemStyleDone;
self.editButtonItem.title = NSLocalizedString(@"Done",@"");
[self.tableView setEditing:YES animated:YES];
} else {
self.editButtonItem.style = UIBarButtonItemStylePlain;
self.editButtonItem.title = NSLocalizedString(@"Edit",@"");
}
}
......
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