Commit 7c94c41e authored by Carola Nitz's avatar Carola Nitz

first hit at seperating viewpresentation from the underlying media management....

first hit at seperating viewpresentation from the underlying media management. Moved the _foundmedia array into it's own class VLCMediaDataSource.m.
This way a lot of duplicated logic got removed when accessing this array.
That way it won't be accessed without the synchronized block and the UpdateViewContents method was cleaned up as well.
parent 49b540c5
Pipeline #100 failed with stage
in 0 seconds
...@@ -16,4 +16,5 @@ ...@@ -16,4 +16,5 @@
- (UINib *)nibclass; - (UINib *)nibclass;
- (NSManagedObject *)objectAtIndex:(NSUInteger)index; - (NSManagedObject *)objectAtIndex:(NSUInteger)index;
- (void)shouldReloadTableForSearchString:(NSString *)searchString searchableFiles:(NSArray *)files; - (void)shouldReloadTableForSearchString:(NSString *)searchString searchableFiles:(NSArray *)files;
@end @end
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
#import "VLCFirstStepsViewController.h" #import "VLCFirstStepsViewController.h"
#import "VLCFolderCollectionViewFlowLayout.h" #import "VLCFolderCollectionViewFlowLayout.h"
#import "VLCKeychainCoordinator.h" #import "VLCKeychainCoordinator.h"
#import "VLCMediaDataSource.h"
#import "VLCLibrarySearchDisplayDataSource.h" #import "VLCLibrarySearchDisplayDataSource.h"
#import "VLCMovieViewController.h" #import "VLCMovieViewController.h"
#import "VLCNavigationController.h" #import "VLCNavigationController.h"
#import "VLCPlaylistCollectionViewCell.h" #import "VLCPlaylistCollectionViewCell.h"
#import "VLCPlaylistTableViewCell.h" #import "VLCPlaylistTableViewCell.h"
#import "NSString+SupportedMedia.h"
#import "VLCPlaybackController+MediaLibrary.h" #import "VLCPlaybackController+MediaLibrary.h"
#import <CoreSpotlight/CoreSpotlight.h> #import <CoreSpotlight/CoreSpotlight.h>
...@@ -51,7 +51,6 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -51,7 +51,6 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
@end @end
@interface VLCLibraryViewController () <VLCFolderCollectionViewDelegateFlowLayout, LXReorderableCollectionViewDataSource, LXReorderableCollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary, VLCMediaListDelegate, UISearchBarDelegate, UISearchDisplayDelegate> { @interface VLCLibraryViewController () <VLCFolderCollectionViewDelegateFlowLayout, LXReorderableCollectionViewDataSource, LXReorderableCollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary, VLCMediaListDelegate, UISearchBarDelegate, UISearchDisplayDelegate> {
NSMutableArray *_foundMedia;
VLCLibraryMode _libraryMode; VLCLibraryMode _libraryMode;
VLCLibraryMode _previousLibraryMode; VLCLibraryMode _previousLibraryMode;
UIBarButtonItem *_menuButton; UIBarButtonItem *_menuButton;
...@@ -65,6 +64,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -65,6 +64,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
UILongPressGestureRecognizer *_longPressGestureRecognizer; UILongPressGestureRecognizer *_longPressGestureRecognizer;
VLCLibrarySearchDisplayDataSource *_searchDataSource; VLCLibrarySearchDisplayDataSource *_searchDataSource;
VLCMediaDataSource *_mediaDataSource;
UISearchBar *_searchBar; UISearchBar *_searchBar;
UISearchDisplayController *_searchDisplayController; UISearchDisplayController *_searchDisplayController;
...@@ -103,6 +104,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -103,6 +104,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[self updateViewsForCurrentDisplayMode]; [self updateViewsForCurrentDisplayMode];
_libraryMode = VLCLibraryModeAllFiles; _libraryMode = VLCLibraryModeAllFiles;
_searchDataSource = [VLCLibrarySearchDisplayDataSource new]; _searchDataSource = [VLCLibrarySearchDisplayDataSource new];
_mediaDataSource = [VLCMediaDataSource new];
self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject]; self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
_emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping; _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
...@@ -270,7 +272,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -270,7 +272,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[defaults synchronize]; [defaults synchronize];
} }
if (_foundMedia.count < 1) if ([_mediaDataSource numberOfFiles] < 1)
[self updateViewContents]; [self updateViewContents];
[[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.]; [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
} }
...@@ -295,12 +297,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -295,12 +297,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)openMediaObject:(NSManagedObject *)mediaObject - (void)openMediaObject:(NSManagedObject *)mediaObject
{ {
if ([mediaObject isKindOfClass:[MLAlbum class]] || [mediaObject isKindOfClass:[MLShow class]]) { if ([mediaObject isKindOfClass:[MLAlbum class]] || [mediaObject isKindOfClass:[MLShow class]]) {
[_mediaDataSource updateContentsForSelection:mediaObject];
BOOL isAlbum = [mediaObject isKindOfClass:[MLAlbum class]]; BOOL isAlbum = [mediaObject isKindOfClass:[MLAlbum class]];
NSArray* array = isAlbum ? [(MLAlbum *)mediaObject sortedTracks] : [(MLShow *)mediaObject sortedEpisodes];
@synchronized(_foundMedia) {
_foundMedia = [NSMutableArray arrayWithArray:array];
}
self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)]; self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
if (_libraryMode == VLCLibraryModeAllFiles) if (_libraryMode == VLCLibraryModeAllFiles)
self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", nil); self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", nil);
...@@ -309,7 +308,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -309,7 +308,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
self.title = [(MLAlbum*)mediaObject name]; self.title = [(MLAlbum*)mediaObject name];
[self reloadViews]; [self reloadViews];
} else if ([mediaObject isKindOfClass:[MLLabel class]]) { } else if ([mediaObject isKindOfClass:[MLLabel class]]) {
MLLabel *folder = (MLLabel*) mediaObject; [_mediaDataSource updateContentsForSelection:mediaObject];
_inFolder = YES; _inFolder = YES;
[self.navigationController.scrollNavigationBar resetToDefaultPositionWithAnimation:YES]; [self.navigationController.scrollNavigationBar resetToDefaultPositionWithAnimation:YES];
if (!self.usingTableViewToShowData) { if (!self.usingTableViewToShowData) {
...@@ -323,12 +322,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -323,12 +322,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
} }
} }
_libraryMode = VLCLibraryModeFolder; _libraryMode = VLCLibraryModeFolder;
@synchronized(_foundMedia) {
_foundMedia = [NSMutableArray arrayWithArray:[folder sortedFolderItems]];
}
self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)]; self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", nil); self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", nil);
self.title = [folder name]; self.title = [(MLLabel*)mediaObject name];
_removeFromFolderBarButtonItem.enabled = YES; _removeFromFolderBarButtonItem.enabled = YES;
_createFolderBarButtonItem.enabled = NO; _createFolderBarButtonItem.enabled = NO;
...@@ -369,55 +366,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -369,55 +366,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)removeMediaObject:(id)managedObject updateDatabase:(BOOL)updateDB - (void)removeMediaObject:(id)managedObject updateDatabase:(BOOL)updateDB
{ {
// delete all tracks from an album [_mediaDataSource removeMediaObject:managedObject];
if ([managedObject isKindOfClass:[MLAlbum class]]) {
MLAlbum *album = managedObject;
NSSet *iterAlbumTrack = [NSSet setWithSet:album.tracks];
for (MLAlbumTrack *track in iterAlbumTrack) {
NSSet *iterFiles = [NSSet setWithSet:track.files];
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
}
[[MLMediaLibrary sharedMediaLibrary] removeObject: album];
// delete all episodes from a show
} else if ([managedObject isKindOfClass:[MLShow class]]) {
MLShow *show = managedObject;
NSSet *iterShowEpisodes = [NSSet setWithSet:show.episodes];
for (MLShowEpisode *episode in iterShowEpisodes) {
NSSet *iterFiles = [NSSet setWithSet:episode.files];
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
}
[[MLMediaLibrary sharedMediaLibrary] removeObject: show];
// delete all files from an episode
} else if ([managedObject isKindOfClass:[MLShowEpisode class]]) {
MLShowEpisode *episode = managedObject;
NSSet *iterFiles = [NSSet setWithSet:episode.files];
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
// delete all files from a track
[[MLMediaLibrary sharedMediaLibrary] removeObject: episode];
} else if ([managedObject isKindOfClass:[MLAlbumTrack class]]) {
MLAlbumTrack *track = managedObject;
NSSet *iterFiles = [NSSet setWithSet:track.files];
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
} else if ([managedObject isKindOfClass:[MLLabel class]]) {
MLLabel *folder = managedObject;
NSSet *iterFiles = [NSSet setWithSet:folder.files];
[folder removeFiles:folder.files];
for (MLFile *file in iterFiles)
[self _deleteMediaObject:file];
[[MLMediaLibrary sharedMediaLibrary] removeObject:folder];
}
else
[self _deleteMediaObject:managedObject];
if (updateDB) { if (updateDB) {
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase]; [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
...@@ -425,48 +374,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -425,48 +374,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
} }
} }
- (void)_deleteMediaObject:(MLFile *)mediaObject
{
if (_inFolder)
[self rearrangeFolderTrackNumbersForRemovedItem:mediaObject];
/* stop playback if needed */
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
if (vpc.isPlaying) {
MLFile *currentlyPlayingFile = [[MLFile fileForURL:vpc.mediaPlayer.media.url] firstObject];
if (currentlyPlayingFile) {
if (currentlyPlayingFile == mediaObject)
[vpc stopPlayback];
}
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folderLocation = [[mediaObject.url path] stringByDeletingLastPathComponent];
NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
NSString *fileName = [mediaObject.path.lastPathComponent stringByDeletingPathExtension];
if (!fileName)
return;
NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return ([obj rangeOfString:fileName].location != NSNotFound);
}];
NSUInteger count = indexSet.count;
NSString *additionalFilePath;
NSUInteger currentIndex = [indexSet firstIndex];
for (unsigned int x = 0; x < count; x++) {
additionalFilePath = allfiles[currentIndex];
if ([additionalFilePath isSupportedSubtitleFormat])
[fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
}
[fileManager removeItemAtURL:mediaObject.url error:nil];
}
- (void)_displayEmptyLibraryViewIfNeeded - (void)_displayEmptyLibraryViewIfNeeded
{ {
if (self.emptyLibraryView.superview) if (self.emptyLibraryView.superview)
[self.emptyLibraryView removeFromSuperview]; [self.emptyLibraryView removeFromSuperview];
if (_foundMedia.count == 0) { if ([_mediaDataSource numberOfFiles] == 0) {
_inFolder = (_libraryMode == VLCLibraryModeFolder || _libraryMode == VLCLibraryModeCreateFolder); _inFolder = (_libraryMode == VLCLibraryModeFolder || _libraryMode == VLCLibraryModeCreateFolder);
self.emptyLibraryView.emptyLibraryLabel.text = _inFolder ? NSLocalizedString(@"FOLDER_EMPTY", nil) : NSLocalizedString(@"EMPTY_LIBRARY", nil); self.emptyLibraryView.emptyLibraryLabel.text = _inFolder ? NSLocalizedString(@"FOLDER_EMPTY", nil) : NSLocalizedString(@"EMPTY_LIBRARY", nil);
self.emptyLibraryView.emptyLibraryLongDescriptionLabel.text = _inFolder ? NSLocalizedString(@"FOLDER_EMPTY_LONG", nil) : NSLocalizedString(@"EMPTY_LIBRARY_LONG", nil); self.emptyLibraryView.emptyLibraryLongDescriptionLabel.text = _inFolder ? NSLocalizedString(@"FOLDER_EMPTY_LONG", nil) : NSLocalizedString(@"EMPTY_LIBRARY_LONG", nil);
...@@ -483,12 +396,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -483,12 +396,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
self.navigationItem.rightBarButtonItem = self.editButtonItem; self.navigationItem.rightBarButtonItem = self.editButtonItem;
} }
} }
if (self.usingTableViewToShowData) if (self.usingTableViewToShowData) {
_tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine: _tableView.separatorStyle = [_mediaDataSource numberOfFiles] > 0 ? UITableViewCellSeparatorStyleSingleLine:
UITableViewCellSeparatorStyleNone; UITableViewCellSeparatorStyleNone;
else } else {
[self.collectionView.collectionViewLayout invalidateLayout]; [self.collectionView.collectionViewLayout invalidateLayout];
}
[self updateViewsForCurrentDisplayMode]; [self updateViewsForCurrentDisplayMode];
} }
...@@ -554,112 +467,40 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -554,112 +467,40 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)updateViewContents - (void)updateViewContents
{ {
@synchronized(self) {
_foundMedia = [[NSMutableArray alloc] init];
}
if (![(VLCAppDelegate *)[UIApplication sharedApplication].delegate passcodeValidated]) { if (![(VLCAppDelegate *)[UIApplication sharedApplication].delegate passcodeValidated]) {
APLog(@"library is locked, won't show contents"); APLog(@"library is locked, won't show contents");
return; return;
} }
self.navigationItem.leftBarButtonItem = _menuButton; self.navigationItem.leftBarButtonItem = _menuButton;
[_mediaDataSource removeAllObjects];
if (_libraryMode == VLCLibraryModeAllAlbums)
self.title = NSLocalizedString(@"LIBRARY_MUSIC", nil);
else if( _libraryMode == VLCLibraryModeAllSeries)
self.title = NSLocalizedString(@"LIBRARY_SERIES", nil);
else
self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
_createFolderBarButtonItem.enabled = (_libraryMode == VLCLibraryModeAllAlbums || _libraryMode == VLCLibraryModeAllSeries) ? NO : YES;
_removeFromFolderBarButtonItem.enabled = NO; _removeFromFolderBarButtonItem.enabled = NO;
/* add all albums */ switch (_libraryMode) {
if (_libraryMode != VLCLibraryModeAllSeries) { case VLCLibraryModeAllAlbums: {
NSArray *rawAlbums = [MLAlbum allAlbums]; self.title = NSLocalizedString(@"LIBRARY_MUSIC", nil);
for (MLAlbum *album in rawAlbums) { _createFolderBarButtonItem.enabled = NO;
if (_libraryMode != VLCLibraryModeAllAlbums) { [_mediaDataSource addAlbumsInAllAlbumMode:YES];
if (album.name.length > 0 && album.tracks.count > 1) { } break;
@synchronized(_foundMedia) { case VLCLibraryModeAllSeries: {
[_foundMedia addObject:album]; self.title = NSLocalizedString(@"LIBRARY_SERIES", nil);
} _createFolderBarButtonItem.enabled = NO;
} [_mediaDataSource addAllShows];
} else { } break;
if (album.name.length > 0) { //Todo: I'm not sure if updateViewContents should be called in VLCLibraryModeFolder
@synchronized(_foundMedia) { //Here should maybe be an NSAssert to prevent this but for now due to refactoring these calls would've been made in that case
[_foundMedia addObject:album]; case VLCLibraryModeAllFiles:
} case VLCLibraryModeFolder:
} case VLCLibraryModeCreateFolder: {
} self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
} _createFolderBarButtonItem.enabled = YES;
}
if (_libraryMode == VLCLibraryModeAllAlbums) { [_mediaDataSource addAlbumsInAllAlbumMode:NO];
[self reloadViews]; [_mediaDataSource addAllShows];
return; [_mediaDataSource addAllFolders];
} [_mediaDataSource addRemainingFiles];
/* add all shows */
NSArray *rawShows = [MLShow allShows];
for (MLShow *show in rawShows) {
if (show.name.length > 0 && show.episodes.count > 1) {
@synchronized(_foundMedia) {
[_foundMedia addObject:show];
}
}
}
if (_libraryMode == VLCLibraryModeAllSeries) {
[self reloadViews];
return;
}
/* add all folders*/
NSArray *allFolders = [MLLabel allLabels];
for (MLLabel *folder in allFolders) {
@synchronized(_foundMedia) {
[_foundMedia addObject:folder];
}
}
/* add all remaining files */
NSArray *allFiles = [MLFile allFiles];
for (MLFile *file in allFiles) {
if (file.labels != nil) {
@synchronized(file.labels) {
if (file.labels.count > 0)
continue;
}
}
if (!file.isShowEpisode && !file.isAlbumTrack) {
@synchronized(_foundMedia) {
[_foundMedia addObject:file];
}
}
else if (file.isShowEpisode) {
if (file.showEpisode.show.episodes.count < 2) {
@synchronized(_foundMedia) {
[_foundMedia addObject:file];
}
}
/* older MediaLibraryKit versions don't send a show name in a popular
* corner case. hence, we need to work-around here and force a reload
* afterwards as this could lead to the 'all my shows are gone'
* syndrome (see #10435, #10464, #10432 et al) */
if (file.showEpisode.show.name.length == 0) {
file.showEpisode.show.name = NSLocalizedString(@"UNTITLED_SHOW", nil);
[self performSelector:@selector(updateViewContents) withObject:nil afterDelay:0.1];
}
} else if (file.isAlbumTrack) {
if (file.albumTrack.album.tracks.count < 2) {
@synchronized(_foundMedia) {
[_foundMedia addObject:file];
}
}
} }
} }
[self reloadViews]; [self reloadViews];
} }
...@@ -700,14 +541,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -700,14 +541,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
#pragma mark - Table View #pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ {
return _foundMedia.count; return [_mediaDataSource numberOfFiles];
} }
// Customize the appearance of table view cells. // Customize the appearance of table view cells.
...@@ -725,30 +561,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -725,30 +561,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)]; [swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:swipeRight]; [cell addGestureRecognizer:swipeRight];
NSInteger row = indexPath.row; cell.mediaObject = [_mediaDataSource objectAtIndex:indexPath.row];
@synchronized (_foundMedia) {
if (row < _foundMedia.count)
cell.mediaObject = _foundMedia[row];
}
return cell; return cell;
} }
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{ {
@synchronized(_foundMedia) { [_mediaDataSource moveObjectFromIndex:fromIndexPath.item toIndex:toIndexPath.item];
MLFile* object = _foundMedia[fromIndexPath.item];
[_foundMedia removeObjectAtIndex:fromIndexPath.item];
[_foundMedia insertObject:object atIndex:toIndexPath.item];
if (![object isKindOfClass:[MLFile class]])
return;
object.folderTrackNumber = @(toIndexPath.item - 1);
object = [_foundMedia objectAtIndex:fromIndexPath.item];
if (![object isKindOfClass:[MLFile class]])
return;
object.folderTrackNumber = @(fromIndexPath.item - 1);
}
} }
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
...@@ -762,17 +582,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -762,17 +582,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
cell.multipleSelectionBackgroundView.backgroundColor = cell.backgroundColor; cell.multipleSelectionBackgroundView.backgroundColor = cell.backgroundColor;
} }
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ {
if (editingStyle == UITableViewCellEditingStyleDelete) { if (editingStyle == UITableViewCellEditingStyleDelete) {
NSInteger row = indexPath.row; NSInteger row = indexPath.row;
_deleteFromTableView = YES; _deleteFromTableView = YES;
if (row < _foundMedia.count) if (row < [_mediaDataSource numberOfFiles])
[self deleteSelection:indexPath]; [self deleteSelection:indexPath];
} }
} }
...@@ -791,16 +606,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -791,16 +606,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
return; return;
} }
NSArray *visibleCells = [tableView visibleCells]; for (VLCPlaylistTableViewCell *cell in [tableView visibleCells]) {
NSUInteger cellCount = visibleCells.count; if ([cell isExpanded])
for (NSUInteger x = 0; x < cellCount; x++) { [cell collapsWithAnimation:NO];
if ([visibleCells[x] isExpanded])
[visibleCells[x] collapsWithAnimation:NO];
} }
if (tableView.isEditing) { if (tableView.isEditing) {
if (_libraryMode == VLCLibraryModeCreateFolder) { if (_libraryMode == VLCLibraryModeCreateFolder) {
_folderObject = _foundMedia[indexPath.row]; _folderObject = [_mediaDataSource objectAtIndex:indexPath.row];
_libraryMode = _previousLibraryMode; _libraryMode = _previousLibraryMode;
[self updateViewContents]; [self updateViewContents];
[self createFolderWithName:nil]; [self createFolderWithName:nil];
...@@ -817,10 +630,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -817,10 +630,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
if (tableView == self.searchDisplayController.searchResultsTableView) { if (tableView == self.searchDisplayController.searchResultsTableView) {
selectedObject = [_searchDataSource objectAtIndex:row]; selectedObject = [_searchDataSource objectAtIndex:row];
} else { } else {
@synchronized (_foundMedia) { selectedObject = [_mediaDataSource objectAtIndex:row];
if (row < _foundMedia.count)
selectedObject = _foundMedia[row];
}
} }
if (_searchDisplayController.active) if (_searchDisplayController.active)
...@@ -833,11 +643,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -833,11 +643,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
#pragma mark - Gesture Action #pragma mark - Gesture Action
- (void)swipeRightOnTableViewCellGestureAction:(UIGestureRecognizer *)recognizer - (void)swipeRightOnTableViewCellGestureAction:(UIGestureRecognizer *)recognizer
{ {
if (self.tableView.isEditing) { [self setEditing:!self.tableView.isEditing animated:YES];
[self setEditing:NO animated:YES]; if (!self.tableView.isEditing) {
} else {
[self setEditing:YES animated:YES];
NSIndexPath *path = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]]; NSIndexPath *path = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:path.row inSection:path.section] [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:path.row inSection:path.section]
animated:YES animated:YES
...@@ -856,17 +663,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -856,17 +663,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
#pragma mark - Collection View #pragma mark - Collection View
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{ {
return _foundMedia.count; return [_mediaDataSource numberOfFiles];
} }
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath]; VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
@synchronized (_foundMedia) {
NSUInteger row = indexPath.row; cell.mediaObject = [_mediaDataSource objectAtIndex:indexPath.row];
if (row < _foundMedia.count)
cell.mediaObject = _foundMedia[row];
}
cell.collectionView = _collectionView; cell.collectionView = _collectionView;
...@@ -913,7 +717,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -913,7 +717,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
{ {
if (self.editing) { if (self.editing) {
if (_libraryMode == VLCLibraryModeCreateFolder) { if (_libraryMode == VLCLibraryModeCreateFolder) {
_folderObject = _foundMedia[indexPath.item]; _folderObject = [_mediaDataSource objectAtIndex:indexPath.item];
[self updateViewContents]; [self updateViewContents];
[self createFolderWithName:nil]; [self createFolderWithName:nil<