Browse Source

upnp: improve folder listing and scrolling a lot on slower networks by fetching thumbnails off the main thread...

Felix Paul Kühne 11 years ago
parent
commit
7a9ca4950d

+ 1 - 0
Sources/VLCLocalNetworkListCell.h

@@ -29,6 +29,7 @@
 @property (nonatomic, retain) NSString *title;
 @property (nonatomic, retain) NSString *subtitle;
 @property (nonatomic, retain) UIImage *icon;
+@property (nonatomic, retain) NSURL *iconURL;
 @property (nonatomic, readwrite) BOOL isDownloadable;
 @property (nonatomic, retain) NSURL *downloadURL;
 

+ 13 - 0
Sources/VLCLocalNetworkListCell.m

@@ -62,6 +62,19 @@
     self.thumbnailView.image = icon;
 }
 
+- (void)setIconURL:(NSURL *)iconURL
+{
+    _iconURL = iconURL;
+    [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
+}
+
+- (void)_updateIconFromURL
+{
+    NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
+    UIImage* image = [[UIImage alloc] initWithData:imageData];
+    [self setIcon:image];
+}
+
 - (void)setIsDownloadable:(BOOL)isDownloadable
 {
     self.downloadButton.hidden = !isDownloadable;

+ 3 - 7
Sources/VLCLocalServerFolderListViewController.m

@@ -217,13 +217,9 @@
             [cell setSubtitle: [NSString stringWithFormat:@"%@ (%@)", [NSByteCountFormatter stringFromByteCount:mediaSize countStyle:NSByteCountFormatterCountStyleFile], [VLCTime timeWithInt:durationInSeconds * 1000].stringValue]];
             [cell setIsDirectory:NO];
             cell.isDownloadable = YES;
-            if (![mediaItem.albumArt isEqualToString:NULL]) {
-                NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaItem.albumArt]];
-                UIImage* image = [[UIImage alloc] initWithData:imageData];
-                [cell setIcon:image];
-            }
-            else
-                [cell setIcon:[UIImage imageNamed:@"blank"]];
+            if (![mediaItem.albumArt isEqualToString:NULL])
+                [cell setIconURL:[NSURL URLWithString:mediaItem.albumArt]];
+            [cell setIcon:[UIImage imageNamed:@"blank"]];
             cell.delegate = self;
         } else {
             [cell setIsDirectory:YES];