Commit 1d9a5ed6 authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

Prevent runtime exceptions

(cherry picked from commit e8f106f1)
parent 03d18b16
......@@ -822,7 +822,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[cell showMetadata:NO];
}
NSManagedObject *selectedObject = _foundMedia[indexPath.row];
NSManagedObject *selectedObject;
@synchronized(self) {
selectedObject = _foundMedia[indexPath.row];
}
[self openMediaObject:selectedObject];
}
......@@ -837,7 +840,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)collectionView:(UICollectionView *)collectionView removeItemFromFolderAtIndexPathIfNeeded:(NSIndexPath *)indexPath
{
id mediaObject = _foundMedia[indexPath.item];
id mediaObject;
@synchronized(self) {
mediaObject = _foundMedia[indexPath.item];
}
if (![mediaObject isKindOfClass:[MLFile class]])
return;
......@@ -867,8 +873,12 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)collectionView:(UICollectionView *)collectionView requestToMoveItemAtIndexPath:(NSIndexPath *)itemPath intoFolderAtIndexPath:(NSIndexPath *)folderPath
{
id folderPathItem = _foundMedia[folderPath.item];
id itemPathItem = _foundMedia[itemPath.item];
id folderPathItem;
id itemPathItem;
@synchronized(self) {
folderPathItem = _foundMedia[folderPath.item];
itemPathItem = _foundMedia[itemPath.item];
}
BOOL validFileTypeAtFolderPath = ([folderPathItem isKindOfClass:[MLFile class]] || [folderPathItem isKindOfClass:[MLLabel class]]) && [itemPathItem isKindOfClass:[MLFile class]];
......@@ -948,10 +958,15 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
for (NSInteger i = _indexPaths.count - 1; i >=0; i--) {
NSIndexPath *path = _indexPaths[i];
id mediaObject;
if (!_usingTableViewToShowData)
mediaObject = _foundMedia[path.item];
else
mediaObject = _foundMedia[path.row];
if (!_usingTableViewToShowData) {
@synchronized(self) {
mediaObject = _foundMedia[path.item];
}
} else {
@synchronized(self) {
mediaObject = _foundMedia[path.row];
}
}
if ([mediaObject isKindOfClass:[MLLabel class]])
[_indexPaths removeObject:path];
}
......@@ -960,7 +975,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
NSArray *folder = [MLLabel allLabels];
//if we already have folders display them
if ([folder count] > 0) {
_foundMedia = [NSMutableArray arrayWithArray:folder];
@synchronized(self) {
_foundMedia = [NSMutableArray arrayWithArray:folder];
}
self.title = NSLocalizedString(@"SELECT_FOLDER", nil);
_previousLibraryMode = _libraryMode;
_libraryMode = VLCLibraryModeCreateFolder;
......@@ -983,7 +1000,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
for (NSInteger i = [_indexPaths count] - 1; i >= 0; i--) {
NSIndexPath *path = _indexPaths[i];
id item = _foundMedia[_usingTableViewToShowData ? path.row : path.item];
id item;
@synchronized(self) {
item = _foundMedia[_usingTableViewToShowData ? path.row : path.item];
}
if ([item isKindOfClass:[MLFile class]]) {
MLFile *file = (MLFile *)item;
......@@ -1023,10 +1043,16 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
}
if (_folderObject != nil) {
NSUInteger folderIndex = [_foundMedia indexOfObject:_folderObject];
id mediaObject;
NSUInteger folderIndex;
@synchronized(self) {
folderIndex = [_foundMedia indexOfObject:_folderObject];
mediaObject = _foundMedia[folderIndex];
}
//item got dragged onto item
if ([_foundMedia[folderIndex] isKindOfClass:[MLFile class]]) {
MLFile *file = _foundMedia[folderIndex];
if ([mediaObject isKindOfClass:[MLFile class]]) {
MLFile *file = (MLFile *)mediaObject;
MLLabel *label = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Label"];
label.name = folderName;
......@@ -1052,7 +1078,10 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
itemFile.folderTrackNumber = @([label files].count - 1);
} else {
//item got dragged onto folder or items should be added to folder
MLLabel *label = _foundMedia[folderIndex];
MLLabel *label;
@synchronized(self) {
label = _foundMedia[folderIndex];
}
[_indexPaths sortUsingSelector:@selector(compare:)];
@synchronized(self) {
......
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