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

library: implement deletion of multiple items in a single editing session (phone UI only so far)

parent 43b8f8ab
......@@ -130,7 +130,7 @@
{
if (buttonIndex == 1) {
VLCPlaylistViewController *delegate = (VLCPlaylistViewController*)self.collectionView.delegate;
[delegate removeMediaObject:self.mediaObject];
[delegate removeMediaObject:self.mediaObject updateDatabase:YES];
}
}
......
......@@ -28,6 +28,7 @@
NSAssert([nibContentArray count] == 1, @"meh");
NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
cell.multipleSelectionBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
return cell;
}
......
......@@ -30,7 +30,7 @@ typedef enum {
- (IBAction)leftButtonAction:(id)sender;
- (void)updateViewContents;
- (void)removeMediaObject:(id)mediaObject;
- (void)removeMediaObject:(id)mediaObject updateDatabase:(BOOL)updateDB;
- (void)setLibraryMode:(VLCLibraryMode)mode;
......
......@@ -126,6 +126,8 @@
_emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
[_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteMultipleFiles)]]];
if (SYSTEM_RUNS_IOS7_OR_LATER)
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
......@@ -202,7 +204,7 @@
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaFromManagedObject:mediaObject];
}
- (void)removeMediaObject:(id)managedObject
- (void)removeMediaObject:(id)managedObject updateDatabase:(BOOL)updateDB
{
// delete all tracks from an album
if ([managedObject isKindOfClass:[MLAlbum class]]) {
......@@ -240,10 +242,13 @@
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
}
} else
[self _deleteMediaObject:managedObject];
if (updateDB) {
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
[self updateViewContents];
}
}
- (void)_deleteMediaObject:(MLFile *)mediaObject
......@@ -388,6 +393,7 @@
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
cell.multipleSelectionBackgroundView.backgroundColor = cell.backgroundColor;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
......@@ -398,11 +404,14 @@
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
[self removeMediaObject: _foundMedia[indexPath.row]];
[self removeMediaObject: _foundMedia[indexPath.row] updateDatabase:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.isEditing)
return;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSManagedObject *selectedObject = _foundMedia[indexPath.row];
[self openMediaObject:selectedObject];
......@@ -515,8 +524,12 @@
[aCell setEditing:editing animated:animated];
}];
} else
} else {
self.navigationController.toolbarHidden = !editing;
self.tableView.allowsMultipleSelectionDuringEditing = editing;
[self.tableView setEditing:editing animated:YES];
[self.editButtonItem setTitle:editing ? NSLocalizedString(@"BUTTON_CANCEL",@"") : NSLocalizedString(@"BUTTON_EDIT", @"")];
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
......@@ -538,6 +551,28 @@
[self setLibraryMode:_libraryMode];
}
- (void)deleteMultipleFiles
{
[self.tableView beginUpdates];
NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
NSUInteger count = indexPaths.count;
NSMutableArray *objects = [[NSMutableArray alloc] initWithCapacity:count];
for (NSUInteger x = 0; x < count; x++)
[objects addObject:_foundMedia[[indexPaths[x] row]]];
for (NSUInteger x = 0; x < count; x++)
[self removeMediaObject:objects[x] updateDatabase:NO];
[self.tableView endUpdates];
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
[self updateViewContents];
[self setEditing:NO animated:YES];
}
#pragma mark - coin coin
- (void)setLibraryMode:(VLCLibraryMode)mode
......
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